feat: Add upload completion hint and increase notification debounce timer
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
15
app/app.py
15
app/app.py
@@ -235,7 +235,7 @@ def _schedule_batch_notification():
|
|||||||
asyncio.create_task(send_batch_notification())
|
asyncio.create_task(send_batch_notification())
|
||||||
|
|
||||||
async def reset_telegram_debounce():
|
async def reset_telegram_debounce():
|
||||||
"""Resets the 30s timer for batch completion notification."""
|
"""Resets the 120s timer for batch completion notification."""
|
||||||
if not SETTINGS.telegram_bot_api_key or not TELEGRAM_OWNER_ID:
|
if not SETTINGS.telegram_bot_api_key or not TELEGRAM_OWNER_ID:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ async def reset_telegram_debounce():
|
|||||||
if _batch_complete_timer:
|
if _batch_complete_timer:
|
||||||
_batch_complete_timer.cancel()
|
_batch_complete_timer.cancel()
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
_batch_complete_timer = loop.call_later(10, _schedule_batch_notification)
|
_batch_complete_timer = loop.call_later(120, _schedule_batch_notification)
|
||||||
|
|
||||||
async def add_file_to_batch(filename: str, size: int, album_name: str, is_invite: bool):
|
async def add_file_to_batch(filename: str, size: int, album_name: str, is_invite: bool):
|
||||||
"""Adds a completed file to the batch list."""
|
"""Adds a completed file to the batch list."""
|
||||||
@@ -1127,6 +1127,17 @@ async def api_upload_chunk_complete(request: Request) -> JSONResponse:
|
|||||||
await send_progress(session_id_local, item_id_local, "error", 100, "Failed to save file locally")
|
await send_progress(session_id_local, item_id_local, "error", 100, "Failed to save file locally")
|
||||||
return JSONResponse({"error": "local_save_failed"}, status_code=500)
|
return JSONResponse({"error": "local_save_failed"}, status_code=500)
|
||||||
|
|
||||||
|
@app.post("/api/uploads/batch_complete_hint")
|
||||||
|
async def api_batch_complete_hint(request: Request) -> JSONResponse:
|
||||||
|
"""
|
||||||
|
Client-side hint that a batch of uploads has completed.
|
||||||
|
This triggers the batch notification immediately instead of waiting for the debounce timer.
|
||||||
|
"""
|
||||||
|
# session_id from body is optional, for future use, but not currently used
|
||||||
|
# because the batch is global.
|
||||||
|
await send_batch_notification()
|
||||||
|
return JSONResponse({"ok": True})
|
||||||
|
|
||||||
|
|
||||||
# ---------- Auth & Albums & Invites APIs ----------
|
# ---------- Auth & Albums & Invites APIs ----------
|
||||||
|
|
||||||
|
|||||||
@@ -164,6 +164,10 @@ function render(){
|
|||||||
if (isComplete && hasSuccess) {
|
if (isComplete && hasSuccess) {
|
||||||
showBanner("All uploads complete.", "ok");
|
showBanner("All uploads complete.", "ok");
|
||||||
allCompleteBannerShown = true;
|
allCompleteBannerShown = true;
|
||||||
|
// Hint to backend that this batch is done, to trigger notification sooner
|
||||||
|
try {
|
||||||
|
fetch('/api/uploads/batch_complete_hint', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ session_id: sessionId }) }).catch(()=>{});
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user