From dc444376c8b83db40ef773c2aeeeff4e646e646a Mon Sep 17 00:00:00 2001 From: anor Date: Thu, 26 Mar 2026 17:45:39 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20admin-=D0=BF=D0=B0=D0=BD=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D1=81=D0=BC?= =?UTF-8?q?=D0=BE=D1=82=D1=80=D0=B0=20=D1=81=D0=B5=D1=81=D1=81=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /admin — таблица всех сессий (время, юзер, кол-во сообщений, последний вопрос) - Кнопка «Открыть» → /?tab=UUID — переход в чат пользователя - /?tab=UUID — поддержка прямых ссылок на сессии Co-Authored-By: Claude Opus 4.6 (1M context) --- main.py | 24 ++++++++++++++++++++++++ static/admin.html | 47 +++++++++++++++++++++++++++++++++++++++++++++++ static/chat.html | 4 +++- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 static/admin.html diff --git a/main.py b/main.py index 1f0cd42..efa0ef4 100644 --- a/main.py +++ b/main.py @@ -541,6 +541,30 @@ async def batch_v2_download(job_id: str, request: Request): return FileResponse(job["output_file"], filename=Path(job["output_file"]).name) +# === Admin: view user sessions === + + +@app.get("/api/admin/sessions") +async def admin_sessions(request: Request): + """List all sessions with last activity — for admin use.""" + _get_user(request) + from db import _conn + with _conn() as conn: + rows = conn.execute( + "SELECT username, tab_id, MAX(timestamp) as last_ts, COUNT(*) as msg_count, " + "(SELECT content FROM messages m2 WHERE m2.tab_id = messages.tab_id " + " AND m2.role = 'user' ORDER BY m2.id DESC LIMIT 1) as last_question " + "FROM messages GROUP BY tab_id ORDER BY last_ts DESC LIMIT 50", + ).fetchall() + return [dict(r) for r in rows] + + +@app.get("/admin", response_class=HTMLResponse) +async def admin_page(request: Request): + _get_user(request) + return Path("static/admin.html").read_text(encoding="utf-8") + + # === Batch V3: Generate + Verify + Auto-Retry === import batch_v3 diff --git a/static/admin.html b/static/admin.html new file mode 100644 index 0000000..970f03a --- /dev/null +++ b/static/admin.html @@ -0,0 +1,47 @@ + + + + +Admin — Сессии + + + +
+

Сессии пользователей

+ + +
ВремяПользовательСообщенийПоследний вопрос
+
+ + + diff --git a/static/chat.html b/static/chat.html index c3afeee..0a2b24c 100644 --- a/static/chat.html +++ b/static/chat.html @@ -160,7 +160,9 @@ let token = localStorage.getItem('token'); let pendingFiles = []; let streaming = false; // Each tab gets its own session — allows multiple windows -let tabId = sessionStorage.getItem('tabId') || crypto.randomUUID(); +// Support ?tab=UUID to open specific session +const urlTab = new URLSearchParams(window.location.search).get('tab'); +let tabId = urlTab || sessionStorage.getItem('tabId') || crypto.randomUUID(); sessionStorage.setItem('tabId', tabId); // --- Init ---