Fix TypeScript errors: Update User type system across all storage implementations
This commit is contained in:
+11
-5
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable no-console, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import { AdminConfig } from './admin.types';
|
||||
import { EpisodeSkipConfig, Favorite, IStorage, PlayRecord, UserSettings } from './types';
|
||||
import { EpisodeSkipConfig, Favorite, IStorage, PlayRecord, User, UserSettings } from './types';
|
||||
|
||||
// 搜索历史最大条数
|
||||
const SEARCH_HISTORY_LIMIT = 20;
|
||||
@@ -428,14 +428,20 @@ export class D1Storage implements IStorage {
|
||||
}
|
||||
|
||||
// 用户列表
|
||||
async getAllUsers(): Promise<string[]> {
|
||||
async getAllUsers(): Promise<User[]> {
|
||||
try {
|
||||
const db = await this.getDatabase();
|
||||
const result = await db
|
||||
.prepare('SELECT username FROM users ORDER BY created_at ASC')
|
||||
.all<{ username: string }>();
|
||||
.prepare('SELECT username, created_at FROM users ORDER BY created_at ASC')
|
||||
.all<{ username: string; created_at: string }>();
|
||||
|
||||
return result.results.map((row) => row.username);
|
||||
const ownerUsername = process.env.USERNAME || 'admin';
|
||||
|
||||
return result.results.map((row) => ({
|
||||
username: row.username,
|
||||
role: row.username === ownerUsername ? 'owner' : 'user',
|
||||
created_at: row.created_at
|
||||
}));
|
||||
} catch (err) {
|
||||
console.error('Failed to get all users:', err);
|
||||
throw err;
|
||||
|
||||
Reference in New Issue
Block a user