diff --git a/main.py b/main.py index fc4b482..a14050e 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ from fastapi.staticfiles import StaticFiles from auth import authenticate, verify_token from db import get_audit_log, get_history, get_history_any_user, init_db, list_sessions, log_action, save_message +from tus_upload import register_tus # Backend: "claude" (Docker sandbox), "glm" (GLM-5 + CAG), "auto" (route by task) AI_BACKEND = os.environ.get("AI_BACKEND", "claude") @@ -187,7 +188,7 @@ _AUDIT_MAP = [ ("POST", "/api/admin/", "admin"), ] -_SKIP_PREFIXES = ("/static/", "/favicon") +_SKIP_PREFIXES = ("/static/", "/favicon", "/api/tus") # tus chunks are logged on completion, not per-PATCH def _resolve_action(method: str, path: str) -> str | None: @@ -286,6 +287,22 @@ async def index(): return Path("static/chat.html").read_text(encoding="utf-8") +# Resumable uploads (tus 1.0.0). Same-process, reuses auth + per-user work dir; +# the finished file lands in the work dir exactly like legacy /api/upload. +TUS_MAX_SIZE = 3 * 1024 * 1024 * 1024 # 3 GB +register_tus( + app, + get_user=_get_user, + get_work_dir=get_work_dir, + is_allowed_file=is_allowed_file, + log_action=log_action, + save_message=save_message, + max_size=TUS_MAX_SIZE, + staging_root=Path(os.environ.get("DATA_DIR", "./smeta-web-data")) / "_tus", + allowed_hint="xlsx, xls, docx, pdf, csv, txt, xml, json, yaml, gge, esw, zip", +) + + @app.post("/api/login") async def login(request: Request): body = await request.json() diff --git a/static/chat.html b/static/chat.html index 8a08dc6..b037fc0 100644 --- a/static/chat.html +++ b/static/chat.html @@ -154,6 +154,7 @@ body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Robo +