feat: Add Telegram commands to control public uploads and show help
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
27
app/app.py
27
app/app.py
@@ -51,6 +51,8 @@ app.add_middleware(
|
||||
|
||||
# Global settings (read-only at runtime)
|
||||
SETTINGS: Settings = load_settings()
|
||||
_public_uploads_enabled_runtime = SETTINGS.public_upload_page_enabled
|
||||
|
||||
|
||||
# Basic logging setup using settings
|
||||
logging.basicConfig(level=SETTINGS.log_level, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
|
||||
@@ -276,8 +278,25 @@ async def handle_telegram_update(update: dict):
|
||||
logger.warning("Ignoring Telegram message from non-owner: %s", from_id)
|
||||
return
|
||||
|
||||
global _public_uploads_enabled_runtime
|
||||
if text == "/start":
|
||||
await send_telegram_message(str(chat_id), "File Drop Bot active.")
|
||||
elif text == "/help":
|
||||
help_text = (
|
||||
"/help - Show this help message\n"
|
||||
"/start - Check if bot is active\n"
|
||||
"/disable_public - Temporarily disable public uploads\n"
|
||||
"/enable_public - Temporarily enable public uploads"
|
||||
)
|
||||
await send_telegram_message(str(chat_id), help_text)
|
||||
elif text == "/disable_public":
|
||||
_public_uploads_enabled_runtime = False
|
||||
logger.info("Public uploads disabled by Telegram owner.")
|
||||
await send_telegram_message(str(chat_id), "Public uploads have been disabled.")
|
||||
elif text == "/enable_public":
|
||||
_public_uploads_enabled_runtime = True
|
||||
logger.info("Public uploads enabled by Telegram owner.")
|
||||
await send_telegram_message(str(chat_id), "Public uploads have been enabled.")
|
||||
|
||||
async def poll_telegram_updates():
|
||||
"""Poll for Telegram updates and process them."""
|
||||
@@ -489,7 +508,7 @@ async def send_progress(session_id: str, item_id: str, status: str, progress: in
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request) -> HTMLResponse:
|
||||
"""Serve the SPA (frontend/index.html) or redirect to login if disabled."""
|
||||
if not SETTINGS.public_upload_page_enabled:
|
||||
if not _public_uploads_enabled_runtime:
|
||||
return RedirectResponse(url="/login")
|
||||
return FileResponse(os.path.join(FRONTEND_DIR, "index.html"))
|
||||
|
||||
@@ -523,7 +542,7 @@ async def api_ping() -> dict:
|
||||
async def api_config() -> dict:
|
||||
"""Expose minimal public configuration flags for the frontend."""
|
||||
return {
|
||||
"public_upload_page_enabled": SETTINGS.public_upload_page_enabled,
|
||||
"public_upload_page_enabled": _public_uploads_enabled_runtime,
|
||||
"chunked_uploads_enabled": SETTINGS.chunked_uploads_enabled,
|
||||
"chunk_size_mb": SETTINGS.chunk_size_mb,
|
||||
}
|
||||
@@ -679,7 +698,7 @@ async def api_upload(
|
||||
target_album_name = album_name
|
||||
|
||||
album_for_saving = target_album_name if invite_token else "public"
|
||||
if not invite_token and not SETTINGS.public_upload_page_enabled:
|
||||
if not invite_token and not _public_uploads_enabled_runtime:
|
||||
await send_progress(session_id, item_id, "error", 100, "Public uploads disabled")
|
||||
return JSONResponse({"error": "public_upload_disabled"}, status_code=403)
|
||||
try:
|
||||
@@ -1015,7 +1034,7 @@ async def api_upload_chunk_complete(request: Request) -> JSONResponse:
|
||||
target_album_name = album_name
|
||||
|
||||
album_for_saving = target_album_name if invite_token else "public"
|
||||
if not invite_token and not SETTINGS.public_upload_page_enabled:
|
||||
if not invite_token and not _public_uploads_enabled_runtime:
|
||||
await send_progress(session_id_local, item_id_local, "error", 100, "Public uploads disabled")
|
||||
return JSONResponse({"error": "public_upload_disabled"}, status_code=403)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user