feat: add /art proxy endpoint and fix /current to expose rgb+art_url
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e8128cad80
commit
38acb8bccb
1 changed files with 34 additions and 0 deletions
|
|
@ -86,6 +86,18 @@ class ControlState:
|
|||
"running": True,
|
||||
}
|
||||
|
||||
def set_current(self, art_url: str, rgb: tuple[int, int, int]) -> None:
|
||||
with self._lock:
|
||||
self._art_url = art_url
|
||||
self._rgb = rgb
|
||||
|
||||
def current(self) -> dict[str, object]:
|
||||
with self._lock:
|
||||
return {
|
||||
"art_url": getattr(self, "_art_url", None),
|
||||
"rgb": list(getattr(self, "_rgb", [0, 200, 255])),
|
||||
}
|
||||
|
||||
|
||||
CONTROL_STATE = ControlState()
|
||||
|
||||
|
|
@ -98,6 +110,27 @@ class ControlHandler(BaseHTTPRequestHandler):
|
|||
if self.path == "/status":
|
||||
self.write_json(200, CONTROL_STATE.snapshot())
|
||||
return
|
||||
if self.path == "/current":
|
||||
self.write_json(200, CONTROL_STATE.current())
|
||||
return
|
||||
if self.path.startswith("/art"):
|
||||
art_url = CONTROL_STATE.current().get("art_url")
|
||||
if not art_url:
|
||||
self.write_json(404, {"error": "no art"})
|
||||
return
|
||||
try:
|
||||
resp = requests.get(art_url, timeout=5)
|
||||
body = resp.content
|
||||
ctype = resp.headers.get("Content-Type", "image/jpeg")
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", ctype)
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.send_header("Access-Control-Allow-Origin", "*")
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
except Exception:
|
||||
self.write_json(502, {"error": "fetch failed"})
|
||||
return
|
||||
self.write_json(404, {"error": "not found"})
|
||||
|
||||
def do_POST(self) -> None:
|
||||
|
|
@ -537,6 +570,7 @@ def main() -> None:
|
|||
print(f"Cor base: {raw_rgb} -> paleta: {palette_rgb}")
|
||||
print(f"Aplicando cor: {rgb}")
|
||||
set_light_color(rgb)
|
||||
CONTROL_STATE.set_current(art_url, rgb)
|
||||
last_track = track_id
|
||||
last_rgb = rgb
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue