Add SSE endpoint and dream notify — /api/events and /api/events/notify
This commit is contained in:
@@ -289,6 +289,18 @@ def deliver(dream_text, mode, task=None):
|
||||
|
||||
print(f"Dream written to Nextcloud: Journal/Dreams/{filename}")
|
||||
|
||||
# Notify any open browser connections via SSE
|
||||
try:
|
||||
import requests as _req
|
||||
_req.post("http://localhost:8000/api/events/notify", json={
|
||||
"type": "dream",
|
||||
"mode": mode,
|
||||
"filename": filename,
|
||||
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M"),
|
||||
}, timeout=3)
|
||||
except Exception as _e:
|
||||
print(f"SSE notify failed (non-critical): {_e}")
|
||||
|
||||
state = load_dreamer_state()
|
||||
state["last_dream_timestamp"] = datetime.now().timestamp()
|
||||
state["last_dream_mode"] = mode
|
||||
|
||||
Reference in New Issue
Block a user