diff --git a/frontend/src/lib/format.ts b/frontend/src/lib/format.ts index de5b6f5..2af92fa 100644 --- a/frontend/src/lib/format.ts +++ b/frontend/src/lib/format.ts @@ -305,6 +305,37 @@ export function eventLevelKey(level?: string | null) { return level === 'warning' ? 'warn' : level } +/** + * 登录设备:会话表里存的是原始 User-Agent,四五十个字符的英文串会把整行撑成三行, + * 谁都看不出「这到底是哪台机器」。这里只留人能读懂的两件事——什么浏览器、什么系统; + * 原文由调用方塞进 title,真要逐字排查时还在。 + */ +const UA_BROWSERS: [string, string][] = [ + ['HeadlessChrome', 'Headless Chrome'], ['Edg', 'Edge'], ['OPR', 'Opera'], + ['Firefox', 'Firefox'], ['Chrome', 'Chrome'], ['Safari', 'Safari'] +] +const UA_SYSTEMS: [RegExp, string][] = [ + [/Windows NT/, 'Windows'], [/Mac OS X|Macintosh/, 'macOS'], [/Android/, 'Android'], + [/iPhone|iPad|CPU OS/, 'iOS'], [/Linux/, 'Linux'] +] + +export function describeUserAgent(ua?: string | null): string { + const s = String(ua || '').trim() + if (!s) return '未知客户端' + for (const [token, name] of UA_BROWSERS) { + // 只取主版本号:156.0.0.0.8078.4 这种长尾在小标签里没有任何信息量 + const hit = s.match(new RegExp(token + '\\/(\\d+)')) + if (hit) { + const sys = UA_SYSTEMS.find(([re]) => re.test(s))?.[1] + return [name + ' ' + hit[1], sys].filter(Boolean).join(' · ') + } + } + // 命令行客户端(curl / python-requests / 脚本):名字和版本就是全部信息 + const cli = s.match(/^([A-Za-z][\w!.-]*)\/([\d.]+)/) + if (cli) return cli[1] + ' ' + cli[2] + return s.length > 28 ? s.slice(0, 28) + '…' : s +} + /** * 镜头审核标签:AI 调度器放行不等于人工审核。 * 质检没过、只是「按现有画面继续出片」的软放行,更要显式提醒人工复核, diff --git a/frontend/src/pages/Account.tsx b/frontend/src/pages/Account.tsx index 8399959..d7ed514 100644 --- a/frontend/src/pages/Account.tsx +++ b/frontend/src/pages/Account.tsx @@ -8,7 +8,7 @@ import { useEffect, useState } from 'react' import { useSearchParams } from 'react-router-dom' import * as api from '../api/client' -import { fmtAgo, fmtTime } from '../lib/format' +import { describeUserAgent, fmtAgo, fmtTime } from '../lib/format' import { useAutoRefresh } from '../hooks/use-auto-refresh' import { SecretInput } from '../components/forms' import { @@ -16,7 +16,7 @@ import { } from '../components/ui' import { login, roleLabel, setUser, useAuthStore } from '../stores/auth' -const RULES_HINT = '至少 8 位,且不能只有一类字符(字母 / 数字 / 符号至少两种)' +const RULES_HINT = '至少 8 位,字母 / 数字 / 符号至少两种' export default function Account() { const [params] = useSearchParams() @@ -109,7 +109,7 @@ export default function Account() { - + - + - setPwd((p) => ({ ...p, current_password: v }))} /> - - + setPwd((p) => ({ ...p, new_password: v }))} /> - - + setPwd((p) => ({ ...p, confirm: v }))} onKeyUp={(e) => { if (e.key === 'Enter') void changePassword() }} /> @@ -159,15 +158,18 @@ export default function Account() { - + {sessions.length}} /> {!sessions.length ? 只有一个当前会话,没有其它设备在线。 : ( -
+ /* 会话是一条条堆起来的(脚本、探针、旧浏览器都算一条), + 限高滚动才不会让这一栏把整页撑到看不完 */ +
{sessions.map((row) => ( - {row.current ? '当前会话' : describeUserAgent(row.label)}} right={row.current - ? 使用中 + ? 使用中 : }>

{row.ip || '未知 IP'} · 活跃于 {fmtAgo(row.last_seen_at)} · {fmtTime(row.expires_at)} 过期

diff --git a/frontend/src/pages/UserAdmin.tsx b/frontend/src/pages/UserAdmin.tsx index 4b9225f..fde51f8 100644 --- a/frontend/src/pages/UserAdmin.tsx +++ b/frontend/src/pages/UserAdmin.tsx @@ -11,7 +11,7 @@ import { fmtAgo, fmtTime } from '../lib/format' import { useAutoRefresh } from '../hooks' import { SecretInput, Select } from '../components/forms' import { - Actions, Button, Check, Ctlbar, Empty, ErrorText, Field, FieldBlock, FormRow, Layout, MUTED, + Actions, Badge, Button, Check, Ctlbar, Empty, ErrorText, Field, FieldBlock, FormRow, Layout, MUTED, MUTED_MONO, PageHead, Panel, PanelHead, Stack, Stat, StatGrid, Sub, Table, TableBox, Tag, cellRight } from '../components/ui' import { notify, notifyBad } from '../stores/notice' @@ -173,18 +173,16 @@ export default function UserAdmin() { - - - setKeyword(e.target.value)} /> - - - setKeyword(e.target.value)} /> + + + + + setCreate((f) => ({ ...f, username: e.target.value }))} /> setCreate((f) => ({ ...f, display_name: e.target.value }))} /> - setCreate((f) => ({ ...f, email: e.target.value }))} /> + setCreate((f) => ({ ...f, email: e.target.value }))} /> setEdit((f) => ({ ...f, display_name: e.target.value }))} /> - setEdit((f) => ({ ...f, email: e.target.value }))} /> + setEdit((f) => ({ ...f, email: e.target.value }))} />