WIP: AI desktop sections, bridge slot, desktop page check

This commit is contained in:
Vasanth committed 2026-10-16 15:25:27 +05:30
1 parent 8951ac05a5
commit 472e18de0d
8 files changed
+465 -16

No files matched your search

+16 -9
View File
@@ -58,6 +58,9 @@ def reset():
put_run("job-1001", "invoice-1001.pdf", SAMPLE_FIELDS, pages_total=2, pages_done=2)
reset() # sample data from import on: the desktop bridge imports this module without a server
def run_view(job_id):
run, rows = RUNS[job_id], ROWS[job_id]
done = run["status"] == "done"
@@ -126,6 +129,18 @@ ROUTES = [
]
def dispatch(method, path, body):
"""One API request -> (status, payload). The web handler and the desktop bridge both call this."""
for m, pattern, fn in ROUTES:
match = re.fullmatch(pattern, path)
if m == method and match:
try:
return fn(*match.groups(), body)
except (KeyError, StopIteration):
return 404, {"detail": "Not found"}
return 404, {"detail": f"No route for {method} {path}"}
class Handler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=str(HERE / "dist"), **kwargs)
@@ -146,15 +161,7 @@ class Handler(SimpleHTTPRequestHandler):
path = urlparse(self.path).path[len(API):]
size = int(self.headers.get("Content-Length") or 0)
body = json.loads(self.rfile.read(size) or b"{}") if size else {}
status, payload = 404, {"detail": f"No route for {method} {path}"}
for m, pattern, fn in ROUTES:
match = re.fullmatch(pattern, path)
if m == method and match:
try:
status, payload = fn(*match.groups(), body)
except (KeyError, StopIteration):
status, payload = 404, {"detail": "Not found"}
break
status, payload = dispatch(method, path, body)
svg = isinstance(payload, str)
data = payload.encode() if svg else json.dumps(payload).encode()
self.send_response(status)