新版用户迁移将站长转换为普通账号
This commit is contained in:
@@ -98,8 +98,9 @@ export async function POST(req: NextRequest) {
|
|||||||
if (importData.data.usersV2 && Array.isArray(importData.data.usersV2)) {
|
if (importData.data.usersV2 && Array.isArray(importData.data.usersV2)) {
|
||||||
for (const userV2 of importData.data.usersV2) {
|
for (const userV2 of importData.data.usersV2) {
|
||||||
try {
|
try {
|
||||||
// 跳过站长(站长使用环境变量认证)
|
// 跳过环境变量中的站长(站长使用环境变量认证)
|
||||||
if (userV2.role === 'owner') {
|
if (userV2.username === process.env.USERNAME) {
|
||||||
|
console.log(`跳过站长 ${userV2.username} 的导入`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +109,12 @@ export async function POST(req: NextRequest) {
|
|||||||
const passwordV2 = userData?.passwordV2;
|
const passwordV2 = userData?.passwordV2;
|
||||||
|
|
||||||
if (passwordV2) {
|
if (passwordV2) {
|
||||||
|
// 将站长角色转换为普通角色
|
||||||
|
const importedRole = userV2.role === 'owner' ? 'user' : userV2.role;
|
||||||
|
if (userV2.role === 'owner') {
|
||||||
|
console.log(`用户 ${userV2.username} 的角色从 owner 转换为 user`);
|
||||||
|
}
|
||||||
|
|
||||||
// 直接使用加密后的密码创建用户
|
// 直接使用加密后的密码创建用户
|
||||||
const storage = (db as any).storage;
|
const storage = (db as any).storage;
|
||||||
if (storage && typeof storage.client?.hset === 'function') {
|
if (storage && typeof storage.client?.hset === 'function') {
|
||||||
@@ -115,7 +122,7 @@ export async function POST(req: NextRequest) {
|
|||||||
const createdAt = userV2.created_at || Date.now();
|
const createdAt = userV2.created_at || Date.now();
|
||||||
|
|
||||||
const userInfo: any = {
|
const userInfo: any = {
|
||||||
role: userV2.role,
|
role: importedRole,
|
||||||
banned: userV2.banned,
|
banned: userV2.banned,
|
||||||
password: passwordV2,
|
password: passwordV2,
|
||||||
created_at: createdAt.toString(),
|
created_at: createdAt.toString(),
|
||||||
|
|||||||
@@ -274,8 +274,8 @@ export class DbManager {
|
|||||||
|
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
try {
|
try {
|
||||||
// 跳过站长(站长使用环境变量认证,不需要迁移)
|
// 跳过环境变量中的站长(站长使用环境变量认证,不需要迁移)
|
||||||
if (user.role === 'owner') {
|
if (user.username === process.env.USERNAME) {
|
||||||
console.log(`跳过站长 ${user.username} 的迁移`);
|
console.log(`跳过站长 ${user.username} 的迁移`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -295,11 +295,6 @@ export class DbManager {
|
|||||||
password = crypto.randomUUID();
|
password = crypto.randomUUID();
|
||||||
console.log(`用户 ${user.username} (OIDC用户) 使用随机密码迁移`);
|
console.log(`用户 ${user.username} (OIDC用户) 使用随机密码迁移`);
|
||||||
}
|
}
|
||||||
// 如果是站长,使用环境变量中的密码
|
|
||||||
else if (user.username === process.env.USERNAME && process.env.PASSWORD) {
|
|
||||||
password = process.env.PASSWORD;
|
|
||||||
console.log(`用户 ${user.username} (站长) 使用环境变量密码迁移`);
|
|
||||||
}
|
|
||||||
// 尝试从旧的存储中获取密码
|
// 尝试从旧的存储中获取密码
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
@@ -322,11 +317,17 @@ export class DbManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将站长角色转换为普通角色
|
||||||
|
const migratedRole = user.role === 'owner' ? 'user' : user.role;
|
||||||
|
if (user.role === 'owner') {
|
||||||
|
console.log(`用户 ${user.username} 的角色从 owner 转换为 user`);
|
||||||
|
}
|
||||||
|
|
||||||
// 创建新用户
|
// 创建新用户
|
||||||
await this.createUserV2(
|
await this.createUserV2(
|
||||||
user.username,
|
user.username,
|
||||||
password,
|
password,
|
||||||
user.role,
|
migratedRole,
|
||||||
user.tags,
|
user.tags,
|
||||||
(user as any).oidcSub,
|
(user as any).oidcSub,
|
||||||
user.enabledApis
|
user.enabledApis
|
||||||
|
|||||||
Reference in New Issue
Block a user