自动创建站长账号

This commit is contained in:
mtvpls
2026-02-08 02:10:55 +08:00
parent a2e07011ec
commit c6865b4607
3 changed files with 86 additions and 11 deletions

View File

@@ -439,14 +439,39 @@ export class PostgresStorage implements IStorage {
// 如果数据库中没有,检查是否是环境变量中的站长
if (userName === process.env.USERNAME) {
return {
role: 'owner',
const ownerInfo = {
role: 'owner' as const,
banned: false,
created_at: 0,
created_at: Date.now(),
playrecord_migrated: true,
favorite_migrated: true,
skip_migrated: true,
};
// 为站长创建数据库记录
try {
await this.db
.prepare(`
INSERT INTO users (
username, password_hash, role, banned, created_at,
playrecord_migrated, favorite_migrated, skip_migrated
)
VALUES ($1, $2, $3, 0, $4, 1, 1, 1)
`)
.bind(
userName,
'', // 站长不需要密码哈希
'owner',
ownerInfo.created_at
)
.run();
console.log(`Created database record for site owner: ${userName}`);
} catch (insertErr) {
console.error('Failed to create owner record:', insertErr);
// 即使插入失败,仍然返回默认信息
}
return ownerInfo;
}
return null;