Fix TypeScript errors: Update User type system across all storage implementations
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-console */
|
||||
import { AdminConfig } from './admin.types';
|
||||
import { EpisodeSkipConfig, Favorite, IStorage, PlayRecord, UserSettings } from './types';
|
||||
import { EpisodeSkipConfig, Favorite, IStorage, PlayRecord, User, UserSettings } from './types';
|
||||
|
||||
/**
|
||||
* LocalStorage 存储实现
|
||||
@@ -341,18 +341,38 @@ export class LocalStorage implements IStorage {
|
||||
}
|
||||
|
||||
// ---------- 管理员功能 ----------
|
||||
async getAllUsers(): Promise<string[]> {
|
||||
async getAllUsers(): Promise<User[]> {
|
||||
if (typeof window === 'undefined') return [];
|
||||
|
||||
try {
|
||||
const users: string[] = [];
|
||||
const users: User[] = [];
|
||||
const prefix = 'katelyatv_user_';
|
||||
const ownerUsername = process.env.USERNAME || 'admin';
|
||||
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const storageKey = localStorage.key(i);
|
||||
if (storageKey && storageKey.startsWith(prefix)) {
|
||||
const userName = storageKey.replace(prefix, '');
|
||||
users.push(userName);
|
||||
const username = storageKey.replace(prefix, '');
|
||||
|
||||
// 尝试获取用户创建时间
|
||||
let created_at = '';
|
||||
try {
|
||||
const userDataStr = localStorage.getItem(storageKey);
|
||||
if (userDataStr) {
|
||||
const userData = JSON.parse(userDataStr);
|
||||
if (userData.created_at) {
|
||||
created_at = new Date(userData.created_at).toISOString();
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// 忽略解析错误
|
||||
}
|
||||
|
||||
users.push({
|
||||
username,
|
||||
role: username === ownerUsername ? 'owner' : 'user',
|
||||
created_at
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user