fix: change admin USERNAME config

This commit is contained in:
shinya
2025-07-26 14:54:20 +08:00
parent 27ae84b7d4
commit 3da1be7432

View File

@@ -261,6 +261,27 @@ export async function getConfig(): Promise<AdminConfig> {
source.from = 'custom';
}
});
const ownerUser = process.env.USERNAME || '';
// 检查配置中的站长用户是否和 USERNAME 匹配,如果不匹配则降级为普通用户
let containOwner = false;
adminConfig.UserConfig.Users.forEach((user) => {
if (user.username !== ownerUser && user.role === 'owner') {
user.role = 'user';
}
if (user.username === ownerUser) {
containOwner = true;
user.role = 'owner';
}
});
// 如果不在则添加
if (!containOwner) {
adminConfig.UserConfig.Users.unshift({
username: ownerUser,
role: 'owner',
});
}
cachedConfig = adminConfig;
} else {
// DB 无配置,执行一次初始化