feat: /api/repeaters and /api/tune-repeater endpoints
This commit is contained in:
@@ -15,10 +15,12 @@ import os
|
||||
import threading
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
import repeaters
|
||||
from radio import Radio, CIVError
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
PANEL = os.path.join(HERE, "panel.html")
|
||||
REPEATERS_JSON = os.path.join(HERE, "repeaters.json")
|
||||
|
||||
radio = None
|
||||
lock = threading.Lock()
|
||||
@@ -50,6 +52,9 @@ def apply_control(path, body):
|
||||
radio.set_volume(int(body["value"]))
|
||||
elif path == "/api/sql":
|
||||
radio.set_squelch_level(int(body["value"]))
|
||||
elif path == "/api/tune-repeater":
|
||||
steps, errors = radio.tune_repeater(body)
|
||||
return {"ok": bool(steps.get("freq")), "steps": steps, "errors": errors}
|
||||
else:
|
||||
raise CIVError("unknown control")
|
||||
return {"ok": True}
|
||||
@@ -81,6 +86,13 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self._json(read_status())
|
||||
except (CIVError, OSError) as e:
|
||||
self._json({"ok": False, "error": str(e)}, 200)
|
||||
elif self.path.startswith("/api/repeaters"):
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
qs = parse_qs(urlparse(self.path).query)
|
||||
q = qs.get("q", [""])[0]
|
||||
limit = int(qs.get("limit", ["25"])[0])
|
||||
recs = repeaters.search(repeaters.load(REPEATERS_JSON), q, limit)
|
||||
self._json({"ok": True, "repeaters": recs})
|
||||
else:
|
||||
self._json({"ok": False, "error": "not found"}, 404)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user