feat: Include destination and source in upload notifications
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
21
app/app.py
21
app/app.py
@@ -177,7 +177,7 @@ hub = SessionHub()
|
||||
# ---------- Telegram Bot ----------
|
||||
|
||||
# Batch upload notifications
|
||||
_upload_batch: List[Tuple[str, int]] = []
|
||||
_upload_batch: List[Tuple[str, int, str, bool]] = [] # filename, size, album_name, is_invite
|
||||
_batch_complete_timer: Optional[asyncio.TimerHandle] = None
|
||||
_batch_lock = asyncio.Lock()
|
||||
|
||||
@@ -210,18 +210,23 @@ async def send_batch_notification():
|
||||
_batch_complete_timer = None
|
||||
|
||||
num_files = len(batch_copy)
|
||||
total_size = sum(size for _, size in batch_copy)
|
||||
total_size = sum(size for _, size, _, _ in batch_copy)
|
||||
|
||||
# All items in a batch should have the same destination album and source type
|
||||
album_name = batch_copy[0][2] if batch_copy else "Unknown"
|
||||
is_invite = batch_copy[0][3] if batch_copy else False
|
||||
source = "Invite" if is_invite else "Public"
|
||||
|
||||
file_list_str = ""
|
||||
if num_files > 0:
|
||||
filenames = [name or "file" for name, _ in batch_copy]
|
||||
filenames = [name or "file" for name, _, _, _ in batch_copy]
|
||||
if num_files > 15:
|
||||
file_list_str = "\n".join(f"{name}" for name in filenames[:15])
|
||||
file_list_str += f"\n... and {num_files - 15} more."
|
||||
else:
|
||||
file_list_str = "\n".join(f"{name}" for name in filenames)
|
||||
|
||||
msg = f"New files uploaded:\n\n- Files: {num_files}\n- Total size: {human_size(total_size)}\n\n```\n{file_list_str}\n```List commands: /help".strip()
|
||||
msg = f"New files uploaded:\n\n- Destination: `{album_name}`\n- Source: {source}\n- Files: {num_files}\n- Total size: {human_size(total_size)}\n\n```\n{file_list_str}\n```List commands: /help".strip()
|
||||
await send_telegram_message(TELEGRAM_OWNER_ID, msg, markdown=True)
|
||||
|
||||
def _schedule_batch_notification():
|
||||
@@ -240,12 +245,12 @@ async def reset_telegram_debounce():
|
||||
loop = asyncio.get_event_loop()
|
||||
_batch_complete_timer = loop.call_later(10, _schedule_batch_notification)
|
||||
|
||||
async def add_file_to_batch(filename: str, size: int):
|
||||
async def add_file_to_batch(filename: str, size: int, album_name: str, is_invite: bool):
|
||||
"""Adds a completed file to the batch list."""
|
||||
if not SETTINGS.telegram_bot_api_key or not TELEGRAM_OWNER_ID:
|
||||
return
|
||||
async with _batch_lock:
|
||||
_upload_batch.append((filename, size))
|
||||
_upload_batch.append((filename, size, album_name, is_invite))
|
||||
|
||||
|
||||
TELEGRAM_API_URL = f"https://api.telegram.org/bot{SETTINGS.telegram_bot_api_key}"
|
||||
@@ -715,7 +720,7 @@ async def api_upload(
|
||||
with open(save_path, "wb") as f:
|
||||
f.write(raw)
|
||||
db_insert_upload(checksum, file.filename, size, device_asset_id, None, created_iso)
|
||||
await add_file_to_batch(file.filename, size)
|
||||
await add_file_to_batch(file.filename, size, album_for_saving, bool(invite_token))
|
||||
await reset_telegram_debounce()
|
||||
|
||||
msg = f"Saved to {album_for_saving}/{os.path.basename(save_path)}"
|
||||
@@ -1051,7 +1056,7 @@ async def api_upload_chunk_complete(request: Request) -> JSONResponse:
|
||||
with open(save_path, "wb") as f:
|
||||
f.write(raw)
|
||||
db_insert_upload(checksum, file_like_name, file_size, device_asset_id, None, created_iso)
|
||||
await add_file_to_batch(file_like_name, file_size)
|
||||
await add_file_to_batch(file_like_name, file_size, album_for_saving, bool(invite_token))
|
||||
|
||||
msg = f"Saved to {album_for_saving}/{os.path.basename(save_path)}"
|
||||
await send_progress(session_id_local, item_id_local, "done", 100, msg)
|
||||
|
||||
Reference in New Issue
Block a user