diff --git a/app/app.py b/app/app.py index a83f238..9b10d78 100644 --- a/app/app.py +++ b/app/app.py @@ -235,7 +235,7 @@ def _schedule_batch_notification(): asyncio.create_task(send_batch_notification()) 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: return @@ -244,7 +244,7 @@ async def reset_telegram_debounce(): if _batch_complete_timer: _batch_complete_timer.cancel() 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): """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") 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 ---------- diff --git a/frontend/app.js b/frontend/app.js index 79db1dc..86f0023 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -164,6 +164,10 @@ function render(){ if (isComplete && hasSuccess) { showBanner("All uploads complete.", "ok"); 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 {} } } }