From 70b2cacc20f04c4c0159b416990c96a3151fcf9b Mon Sep 17 00:00:00 2001 From: 3970260761 <3970260761@qq.com> Date: Sun, 8 Nov 2026 01:38:08 +0800 Subject: [PATCH] =?UTF-8?q?fixed76:=20=E7=AE=A1=E7=90=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=A1=A8=E5=8A=A0=E6=B3=A8=E5=86=8C=E6=97=B6=E9=97=B4+?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E7=99=BB=E5=BD=95=E4=B8=A4=E5=88=97+TVBox?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B5=E5=8A=A0=E7=9B=B4=E6=92=AD=E6=BA=90?= =?UTF-8?q?=E5=9C=B0=E5=9D=80+=E6=B3=A8=E5=86=8C/=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=A1=A5=E6=97=B6=E9=97=B4=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/admin/page.tsx | 22 +++++++++ src/app/api/admin/user/route.ts | 6 ++- src/app/api/register/route.ts | 6 ++- src/app/config/page.tsx | 42 +++++++++++++++++ src/lib/admin.types.ts | 4 ++ src/lib/config.ts | 84 +++++++++++++++++++++++++++++---- 6 files changed, 152 insertions(+), 12 deletions(-) diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index c89bf2a..2f9c041 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -470,6 +470,18 @@ const UserConfig = ({ config, role, refreshConfig }: UserConfigProps) => { > 状态 + + 注册时间 + + + 最后登录 + { {!user.banned ? '正常' : '已封禁'} + + {user.created_at + ? `${new Date(user.created_at).toLocaleString('zh-CN', { hour12: false })}${user.created_at_estimated ? '*' : ''}` + : '-'} + + + {user.last_login_at + ? `${new Date(user.last_login_at).toLocaleString('zh-CN', { hour12: false })}${user.last_login_estimated ? '*' : ''}` + : '-'} + {/* 修改密码按钮 */} {canChangePassword && ( diff --git a/src/app/api/admin/user/route.ts b/src/app/api/admin/user/route.ts index 9c1cd92..84a2ae1 100644 --- a/src/app/api/admin/user/route.ts +++ b/src/app/api/admin/user/route.ts @@ -132,11 +132,13 @@ export async function POST(request: NextRequest) { ); } await storage.registerUser(targetUsername!, targetPassword); - // 更新配置 + // 更新配置(带注册时间,避免列表显示空白) adminConfig.UserConfig.Users.push({ username: targetUsername!, role: 'user', - }); + created_at: new Date().toISOString(), + created_at_estimated: false, + } as any); targetEntry = adminConfig.UserConfig.Users[ adminConfig.UserConfig.Users.length - 1 diff --git a/src/app/api/register/route.ts b/src/app/api/register/route.ts index 6fd6190..b66be4f 100644 --- a/src/app/api/register/route.ts +++ b/src/app/api/register/route.ts @@ -97,11 +97,13 @@ export async function POST(req: NextRequest) { await db.registerUser(username, password); - // 添加到配置中并保存 + // 添加到配置中并保存(带注册时间,避免列表显示空白) config.UserConfig.Users.push({ username, role: 'user', - }); + created_at: new Date().toISOString(), + created_at_estimated: false, + } as any); await db.saveAdminConfig(config); // 注册成功,设置认证cookie diff --git a/src/app/config/page.tsx b/src/app/config/page.tsx index 8b70b1d..ca72229 100644 --- a/src/app/config/page.tsx +++ b/src/app/config/page.tsx @@ -8,6 +8,7 @@ export const dynamic = 'force-dynamic'; export default function ConfigPage() { const [copied, setCopied] = useState(false); + const [copiedLive, setCopiedLive] = useState(false); const [format, setFormat] = useState<'json' | 'base64'>('json'); const getConfigUrl = useCallback(() => { @@ -16,6 +17,12 @@ export default function ConfigPage() { return `${baseUrl}/api/tvbox?format=${format}`; }, [format]); + const getLiveUrl = useCallback(() => { + if (typeof window === 'undefined') return ''; + const baseUrl = window.location.origin; + return `${baseUrl}/api/tvbox?live=txt`; + }, []); + const handleCopy = async () => { try { await navigator.clipboard.writeText(getConfigUrl()); @@ -26,6 +33,16 @@ export default function ConfigPage() { } }; + const handleCopyLive = async () => { + try { + await navigator.clipboard.writeText(getLiveUrl()); + setCopiedLive(true); + setTimeout(() => setCopiedLive(false), 2000); + } catch { + // Copy failed silently + } + }; + return ( <> @@ -72,6 +89,31 @@ export default function ConfigPage() { {copied ? '已复制' : '复制'} + +

+ 直播源地址 +

+

+ 仅含电视直播,可单独填入 TVBox 直播源(TXT 格式)。 +

+
+ + +
diff --git a/src/lib/admin.types.ts b/src/lib/admin.types.ts index 783dd81..1e0eefd 100644 --- a/src/lib/admin.types.ts +++ b/src/lib/admin.types.ts @@ -13,6 +13,10 @@ export interface AdminConfig { username: string; role: 'user' | 'admin' | 'owner'; banned?: boolean; + created_at?: string; + created_at_estimated?: boolean; + last_login_at?: string; + last_login_estimated?: boolean; }[]; }; SourceConfig: { diff --git a/src/lib/config.ts b/src/lib/config.ts index fa10ddf..254b064 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -73,16 +73,41 @@ async function initConfig() { adminConfig = await (storage as any).getAdminConfig(); } - // 获取所有用户名,用于补全 Users + // 获取所有用户(含注册/最后登录时间),用于补全 Users let userNames: string[] = []; + const userTimeMap = new Map< + string, + { + created_at?: string; + created_at_estimated?: boolean; + last_login_at?: string; + last_login_estimated?: boolean; + } + >(); if (storage && typeof (storage as any).getAllUsers === 'function') { try { const rawUsers = await (storage as any).getAllUsers(); // getAllUsers 返回的是 User 对象数组,这里统一取用户名字符串, // 否则会把整个对象写入 Users[].username(导致管理页渲染对象报 React #31) - userNames = (Array.isArray(rawUsers) ? rawUsers : []) - .map((u: any) => (typeof u === 'string' ? u : u && typeof u.username === 'string' ? u.username : '')) - .filter((n: string) => !!n); + // 同时保留时间字段,供用户列表展示注册/最后登录时间 + (Array.isArray(rawUsers) ? rawUsers : []).forEach((u: any) => { + const n = + typeof u === 'string' + ? u + : u && typeof u.username === 'string' + ? u.username + : ''; + if (!n) return; + userNames.push(n); + if (typeof u === 'object' && u) { + userTimeMap.set(n, { + created_at: u.created_at || undefined, + created_at_estimated: !!u.created_at_estimated, + last_login_at: u.last_login_at || undefined, + last_login_estimated: !!u.last_login_estimated, + }); + } + }); } catch (e) { console.error('获取用户列表失败:', e); } @@ -132,7 +157,24 @@ async function initConfig() { adminConfig!.UserConfig.Users.push({ username: uname, role: 'user', + ...(userTimeMap.get(uname) || {}), }); + } else { + // 已存在用户也回填时间字段(老配置升级时补上) + const exist = adminConfig!.UserConfig.Users.find( + (u) => u.username === uname + ); + const t = userTimeMap.get(uname); + if (exist && t) { + if (!exist.created_at && t.created_at) { + exist.created_at = t.created_at; + exist.created_at_estimated = t.created_at_estimated; + } + if (!exist.last_login_at && t.last_login_at) { + exist.last_login_at = t.last_login_at; + exist.last_login_estimated = t.last_login_estimated; + } + } } }); // 站长 @@ -151,6 +193,7 @@ async function initConfig() { let allUsers = userNames.map((uname) => ({ username: uname, role: 'user', + ...(userTimeMap.get(uname) || {}), })); const ownerUser = process.env.USERNAME; if (ownerUser) { @@ -325,14 +368,38 @@ export async function getConfig(): Promise { export async function resetConfig() { const storage = getStorage(); - // 获取所有用户名,用于补全 Users + // 获取所有用户(含注册/最后登录时间),用于补全 Users let userNames: string[] = []; + const userTimeMap = new Map< + string, + { + created_at?: string; + created_at_estimated?: boolean; + last_login_at?: string; + last_login_estimated?: boolean; + } + >(); if (storage && typeof (storage as any).getAllUsers === 'function') { try { const rawUsers = await (storage as any).getAllUsers(); - userNames = (Array.isArray(rawUsers) ? rawUsers : []) - .map((u: any) => (typeof u === 'string' ? u : u && typeof u.username === 'string' ? u.username : '')) - .filter((n: string) => !!n); + (Array.isArray(rawUsers) ? rawUsers : []).forEach((u: any) => { + const n = + typeof u === 'string' + ? u + : u && typeof u.username === 'string' + ? u.username + : ''; + if (!n) return; + userNames.push(n); + if (typeof u === 'object' && u) { + userTimeMap.set(n, { + created_at: u.created_at || undefined, + created_at_estimated: !!u.created_at_estimated, + last_login_at: u.last_login_at || undefined, + last_login_estimated: !!u.last_login_estimated, + }); + } + }); } catch (e) { console.error('获取用户列表失败:', e); } @@ -358,6 +425,7 @@ export async function resetConfig() { let allUsers = userNames.map((uname) => ({ username: uname, role: 'user', + ...(userTimeMap.get(uname) || {}), })); const ownerUser = process.env.USERNAME; if (ownerUser) {