Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70b2cacc20 |
No files matched your search
@@ -470,6 +470,18 @@ const UserConfig = ({ config, role, refreshConfig }: UserConfigProps) => {
|
|||||||
>
|
>
|
||||||
状态
|
状态
|
||||||
</th>
|
</th>
|
||||||
|
<th
|
||||||
|
scope='col'
|
||||||
|
className='px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider'
|
||||||
|
>
|
||||||
|
注册时间
|
||||||
|
</th>
|
||||||
|
<th
|
||||||
|
scope='col'
|
||||||
|
className='px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider'
|
||||||
|
>
|
||||||
|
最后登录
|
||||||
|
</th>
|
||||||
<th
|
<th
|
||||||
scope='col'
|
scope='col'
|
||||||
className='px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider'
|
className='px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider'
|
||||||
@@ -548,6 +560,16 @@ const UserConfig = ({ config, role, refreshConfig }: UserConfigProps) => {
|
|||||||
{!user.banned ? '正常' : '已封禁'}
|
{!user.banned ? '正常' : '已封禁'}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
<td className='px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400'>
|
||||||
|
{user.created_at
|
||||||
|
? `${new Date(user.created_at).toLocaleString('zh-CN', { hour12: false })}${user.created_at_estimated ? '*' : ''}`
|
||||||
|
: '-'}
|
||||||
|
</td>
|
||||||
|
<td className='px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400'>
|
||||||
|
{user.last_login_at
|
||||||
|
? `${new Date(user.last_login_at).toLocaleString('zh-CN', { hour12: false })}${user.last_login_estimated ? '*' : ''}`
|
||||||
|
: '-'}
|
||||||
|
</td>
|
||||||
<td className='px-6 py-4 whitespace-nowrap text-right text-sm font-medium space-x-2'>
|
<td className='px-6 py-4 whitespace-nowrap text-right text-sm font-medium space-x-2'>
|
||||||
{/* 修改密码按钮 */}
|
{/* 修改密码按钮 */}
|
||||||
{canChangePassword && (
|
{canChangePassword && (
|
||||||
|
|||||||
@@ -132,11 +132,13 @@ export async function POST(request: NextRequest) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
await storage.registerUser(targetUsername!, targetPassword);
|
await storage.registerUser(targetUsername!, targetPassword);
|
||||||
// 更新配置
|
// 更新配置(带注册时间,避免列表显示空白)
|
||||||
adminConfig.UserConfig.Users.push({
|
adminConfig.UserConfig.Users.push({
|
||||||
username: targetUsername!,
|
username: targetUsername!,
|
||||||
role: 'user',
|
role: 'user',
|
||||||
});
|
created_at: new Date().toISOString(),
|
||||||
|
created_at_estimated: false,
|
||||||
|
} as any);
|
||||||
targetEntry =
|
targetEntry =
|
||||||
adminConfig.UserConfig.Users[
|
adminConfig.UserConfig.Users[
|
||||||
adminConfig.UserConfig.Users.length - 1
|
adminConfig.UserConfig.Users.length - 1
|
||||||
|
|||||||
@@ -97,11 +97,13 @@ export async function POST(req: NextRequest) {
|
|||||||
|
|
||||||
await db.registerUser(username, password);
|
await db.registerUser(username, password);
|
||||||
|
|
||||||
// 添加到配置中并保存
|
// 添加到配置中并保存(带注册时间,避免列表显示空白)
|
||||||
config.UserConfig.Users.push({
|
config.UserConfig.Users.push({
|
||||||
username,
|
username,
|
||||||
role: 'user',
|
role: 'user',
|
||||||
});
|
created_at: new Date().toISOString(),
|
||||||
|
created_at_estimated: false,
|
||||||
|
} as any);
|
||||||
await db.saveAdminConfig(config);
|
await db.saveAdminConfig(config);
|
||||||
|
|
||||||
// 注册成功,设置认证cookie
|
// 注册成功,设置认证cookie
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const dynamic = 'force-dynamic';
|
|||||||
|
|
||||||
export default function ConfigPage() {
|
export default function ConfigPage() {
|
||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
|
const [copiedLive, setCopiedLive] = useState(false);
|
||||||
const [format, setFormat] = useState<'json' | 'base64'>('json');
|
const [format, setFormat] = useState<'json' | 'base64'>('json');
|
||||||
|
|
||||||
const getConfigUrl = useCallback(() => {
|
const getConfigUrl = useCallback(() => {
|
||||||
@@ -16,6 +17,12 @@ export default function ConfigPage() {
|
|||||||
return `${baseUrl}/api/tvbox?format=${format}`;
|
return `${baseUrl}/api/tvbox?format=${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 () => {
|
const handleCopy = async () => {
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(getConfigUrl());
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<TopRightButtons variant='float' />
|
<TopRightButtons variant='float' />
|
||||||
@@ -72,6 +89,31 @@ export default function ConfigPage() {
|
|||||||
{copied ? '已复制' : '复制'}
|
{copied ? '已复制' : '复制'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h2 className="text-xl font-semibold mt-6 mb-2 text-gray-900 dark:text-white">
|
||||||
|
直播源地址
|
||||||
|
</h2>
|
||||||
|
<p className="text-sm text-gray-500 dark:text-gray-400 mb-4">
|
||||||
|
仅含电视直播,可单独填入 TVBox 直播源(TXT 格式)。
|
||||||
|
</p>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
readOnly
|
||||||
|
value={getLiveUrl()}
|
||||||
|
className="flex-1 p-3 border border-gray-300 dark:border-gray-600 rounded-md bg-gray-50 dark:bg-gray-700 text-gray-900 dark:text-white font-mono text-sm"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={handleCopyLive}
|
||||||
|
className={`px-4 py-3 rounded-md font-medium transition-colors ${
|
||||||
|
copiedLive
|
||||||
|
? 'bg-green-500 text-white'
|
||||||
|
: 'bg-blue-500 hover:bg-blue-600 text-white'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{copiedLive ? '已复制' : '复制'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 mb-6">
|
<div className="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 mb-6">
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ export interface AdminConfig {
|
|||||||
username: string;
|
username: string;
|
||||||
role: 'user' | 'admin' | 'owner';
|
role: 'user' | 'admin' | 'owner';
|
||||||
banned?: boolean;
|
banned?: boolean;
|
||||||
|
created_at?: string;
|
||||||
|
created_at_estimated?: boolean;
|
||||||
|
last_login_at?: string;
|
||||||
|
last_login_estimated?: boolean;
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
SourceConfig: {
|
SourceConfig: {
|
||||||
|
|||||||
+76
-8
@@ -73,16 +73,41 @@ async function initConfig() {
|
|||||||
adminConfig = await (storage as any).getAdminConfig();
|
adminConfig = await (storage as any).getAdminConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有用户名,用于补全 Users
|
// 获取所有用户(含注册/最后登录时间),用于补全 Users
|
||||||
let userNames: string[] = [];
|
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') {
|
if (storage && typeof (storage as any).getAllUsers === 'function') {
|
||||||
try {
|
try {
|
||||||
const rawUsers = await (storage as any).getAllUsers();
|
const rawUsers = await (storage as any).getAllUsers();
|
||||||
// getAllUsers 返回的是 User 对象数组,这里统一取用户名字符串,
|
// getAllUsers 返回的是 User 对象数组,这里统一取用户名字符串,
|
||||||
// 否则会把整个对象写入 Users[].username(导致管理页渲染对象报 React #31)
|
// 否则会把整个对象写入 Users[].username(导致管理页渲染对象报 React #31)
|
||||||
userNames = (Array.isArray(rawUsers) ? rawUsers : [])
|
// 同时保留时间字段,供用户列表展示注册/最后登录时间
|
||||||
.map((u: any) => (typeof u === 'string' ? u : u && typeof u.username === 'string' ? u.username : ''))
|
(Array.isArray(rawUsers) ? rawUsers : []).forEach((u: any) => {
|
||||||
.filter((n: string) => !!n);
|
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) {
|
} catch (e) {
|
||||||
console.error('获取用户列表失败:', e);
|
console.error('获取用户列表失败:', e);
|
||||||
}
|
}
|
||||||
@@ -132,7 +157,24 @@ async function initConfig() {
|
|||||||
adminConfig!.UserConfig.Users.push({
|
adminConfig!.UserConfig.Users.push({
|
||||||
username: uname,
|
username: uname,
|
||||||
role: 'user',
|
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) => ({
|
let allUsers = userNames.map((uname) => ({
|
||||||
username: uname,
|
username: uname,
|
||||||
role: 'user',
|
role: 'user',
|
||||||
|
...(userTimeMap.get(uname) || {}),
|
||||||
}));
|
}));
|
||||||
const ownerUser = process.env.USERNAME;
|
const ownerUser = process.env.USERNAME;
|
||||||
if (ownerUser) {
|
if (ownerUser) {
|
||||||
@@ -325,14 +368,38 @@ export async function getConfig(): Promise<AdminConfig> {
|
|||||||
|
|
||||||
export async function resetConfig() {
|
export async function resetConfig() {
|
||||||
const storage = getStorage();
|
const storage = getStorage();
|
||||||
// 获取所有用户名,用于补全 Users
|
// 获取所有用户(含注册/最后登录时间),用于补全 Users
|
||||||
let userNames: string[] = [];
|
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') {
|
if (storage && typeof (storage as any).getAllUsers === 'function') {
|
||||||
try {
|
try {
|
||||||
const rawUsers = await (storage as any).getAllUsers();
|
const rawUsers = await (storage as any).getAllUsers();
|
||||||
userNames = (Array.isArray(rawUsers) ? rawUsers : [])
|
(Array.isArray(rawUsers) ? rawUsers : []).forEach((u: any) => {
|
||||||
.map((u: any) => (typeof u === 'string' ? u : u && typeof u.username === 'string' ? u.username : ''))
|
const n =
|
||||||
.filter((n: string) => !!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) {
|
} catch (e) {
|
||||||
console.error('获取用户列表失败:', e);
|
console.error('获取用户列表失败:', e);
|
||||||
}
|
}
|
||||||
@@ -358,6 +425,7 @@ export async function resetConfig() {
|
|||||||
let allUsers = userNames.map((uname) => ({
|
let allUsers = userNames.map((uname) => ({
|
||||||
username: uname,
|
username: uname,
|
||||||
role: 'user',
|
role: 'user',
|
||||||
|
...(userTimeMap.get(uname) || {}),
|
||||||
}));
|
}));
|
||||||
const ownerUser = process.env.USERNAME;
|
const ownerUser = process.env.USERNAME;
|
||||||
if (ownerUser) {
|
if (ownerUser) {
|
||||||
|
|||||||
Reference in new issue
Block a user