feat: admin-панель для просмотра сессий пользователей

- /admin — таблица всех сессий (время, юзер, кол-во сообщений, последний вопрос)
- Кнопка «Открыть» → /?tab=UUID — переход в чат пользователя
- /?tab=UUID — поддержка прямых ссылок на сессии

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-26 17:45:39 +10:00
co-authored by Claude Opus 4.6
parent a976588356
commit dc444376c8
3 changed files with 74 additions and 1 deletions
+47
View File
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Admin — Сессии</title>
<style>
:root { --bg: #f5f0eb; --card: #fff; --text: #3a3a3a; --muted: #6b6b6b; --accent: #c4463a; --border: #d4c5b2; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); padding: 2rem; }
.container { max-width: 900px; margin: 0 auto; }
h1 { font-size: 1.2rem; margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
th { background: #ede5db; text-align: left; padding: 8px 12px; font-size: .8rem; font-weight: 600; }
td { padding: 6px 12px; border-top: 1px solid #eee; font-size: .85rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.time { color: var(--muted); font-size: .75rem; }
.q { color: var(--muted); font-size: .8rem; max-width: 350px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
</style>
</head>
<body>
<div class="container">
<h1>Сессии пользователей</h1>
<table id="sessions">
<tr><th>Время</th><th>Пользователь</th><th>Сообщений</th><th>Последний вопрос</th><th></th></tr>
</table>
</div>
<script>
const token = localStorage.getItem('token');
if (!token) window.location.href = '/';
fetch('/api/admin/sessions', {headers: {'Authorization': 'Bearer ' + token}})
.then(r => r.json())
.then(sessions => {
const table = document.getElementById('sessions');
for (const s of sessions) {
const d = new Date(s.last_ts < 1e12 ? s.last_ts * 1000 : s.last_ts);
const ts = d.toLocaleString('ru-RU', {day:'2-digit',month:'2-digit',year:'2-digit',hour:'2-digit',minute:'2-digit'});
const tr = document.createElement('tr');
const q = (s.last_question || '').slice(0, 80);
tr.innerHTML = `<td class="time">${ts}</td><td>${s.username}</td><td>${s.msg_count}</td><td class="q" title="${q}">${q}</td><td><a href="/?tab=${s.tab_id}" target="_blank">Открыть</a></td>`;
table.appendChild(tr);
}
});
</script>
</body>
</html>