mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-05 18:11:41 +00:00
Merge branch 'main' into 95-send-spots-to-xota
# Conflicts: # README.md # config-example.yml # core/config.py # server/handlers/api/addspot.py # server/handlers/api/options.py # static/js/add-spot.js # static/js/bands.js # static/js/map.js
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
@@ -10,7 +10,7 @@ from tornado.web import Application
|
||||
from core.config import MAX_SPOT_AGE, ALLOW_SPOTTING
|
||||
from core.constants import BANDS, ALL_MODES, MODE_TYPES, SIGS, CONTINENTS, PROPAGATION_MODES
|
||||
from core.prometheus_metrics_handler import api_requests_counter
|
||||
from core.utils import serialize_everything
|
||||
from core.utils import safe_json_dumps
|
||||
|
||||
|
||||
class APIOptionsHandler(tornado.web.RequestHandler):
|
||||
@@ -28,19 +28,20 @@ class APIOptionsHandler(tornado.web.RequestHandler):
|
||||
self._spot_providers = spot_providers or []
|
||||
|
||||
def get(self):
|
||||
# Metrics
|
||||
self._web_server_metrics["last_api_access_time"] = datetime.now(pytz.UTC)
|
||||
self._web_server_metrics["api_access_counter"] += 1
|
||||
self._web_server_metrics["status"] = "OK"
|
||||
api_requests_counter.inc()
|
||||
try:
|
||||
# Metrics
|
||||
self._web_server_metrics["last_api_access_time"] = datetime.now(pytz.UTC)
|
||||
self._web_server_metrics["api_access_counter"] += 1
|
||||
self._web_server_metrics["status"] = "OK"
|
||||
api_requests_counter.inc()
|
||||
|
||||
# Build a map of SIG name -> list of provider names that can submit spots for that SIG
|
||||
# Build a map of SIG name -> list of provider names that can submit spots for that SIG
|
||||
spot_submit_providers = {}
|
||||
for provider in self._spot_providers:
|
||||
if not provider.enabled:
|
||||
continue
|
||||
for sig in SIGS:
|
||||
if provider.can_submit_spot(sig.name):
|
||||
if provider.can_submit_spot(sig.name):
|
||||
spot_submit_providers.setdefault(sig.name, []).append(provider.name)
|
||||
|
||||
# Spot/alert sources are filtered for only ones that are enabled in config, no point letting the user toggle
|
||||
@@ -51,8 +52,8 @@ class APIOptionsHandler(tornado.web.RequestHandler):
|
||||
map(lambda p: p["name"], filter(lambda p: p["enabled"], self._status_data["alert_providers"])))
|
||||
# If spotting to this server is enabled, "API" is another valid spot source even though it does not come from
|
||||
# one of our providers.
|
||||
if ALLOW_SPOTTING:
|
||||
spot_sources.append("API")
|
||||
if ALLOW_SPOTTING:
|
||||
spot_sources.append("API")
|
||||
|
||||
options = {"bands": BANDS,
|
||||
"modes": ALL_MODES,
|
||||
@@ -66,7 +67,12 @@ class APIOptionsHandler(tornado.web.RequestHandler):
|
||||
"spot_allowed": ALLOW_SPOTTING,
|
||||
"spot_submit_providers": spot_submit_providers}
|
||||
|
||||
self.write(json.dumps(options, default=serialize_everything))
|
||||
self.set_status(200)
|
||||
self.set_header("Cache-Control", "no-store")
|
||||
self.set_header("Content-Type", "application/json")
|
||||
self.write(safe_json_dumps(options))
|
||||
self.set_status(200)
|
||||
self.set_header("Cache-Control", "no-store")
|
||||
self.set_header("Content-Type", "application/json")
|
||||
|
||||
except Exception as e:
|
||||
logging.error("Exception when handling client request to options API: %s", e, exc_info=True)
|
||||
self.write(safe_json_dumps("Error - an internal server error occurred."))
|
||||
self.set_status(500)
|
||||
|
||||
Reference in New Issue
Block a user