fix: redirect browser visits from API state to dashboard

This commit is contained in:
pnannery committed 2026-09-11 08:37:25 -04:00
1 parent 26a30f534b
commit 9fd3077cae
1 file changed
+8 -1
+8 -1
View File
@@ -52,7 +52,14 @@ class H(BaseHTTPRequestHandler):
p=urlparse(self.path).path
if p=='/':return self.send(200,INDEX,'text/html; charset=utf-8')
if p=='/api/watchlist':return self.send(200,json.dumps(watchlist.read()))
if p=='/api/state':return self.send(200,STATE.read_text() if STATE.exists() else '{}')
if p=='/api/state':
# If someone opens the JSON endpoint directly from a phone/browser,
# send them to the dashboard instead of a raw JSON wall. Programmatic
# callers and dashboard fetch() still receive JSON.
accept=self.headers.get('Accept','')
if 'text/html' in accept and 'application/json' not in accept:
self.send_response(303);self.send_header('Location','/');self.send_header('Cache-Control','no-store');self.end_headers();return
return self.send(200,STATE.read_text() if STATE.exists() else '{}')
if p=='/api/report':return self.send(200,report_text(json.loads(STATE.read_text()) if STATE.exists() else {}),'text/plain; charset=utf-8')
if p=='/api/log':
from collections import deque