迁移收藏到新数据结构
This commit is contained in:
@@ -24,6 +24,7 @@ export async function GET(request: NextRequest) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
// 检查用户状态和执行迁移
|
||||
if (authInfo.username !== process.env.USERNAME) {
|
||||
// 非站长,检查用户存在或被封禁
|
||||
const userInfoV2 = await db.getUserInfoV2(authInfo.username);
|
||||
@@ -33,6 +34,19 @@ export async function GET(request: NextRequest) {
|
||||
if (userInfoV2.banned) {
|
||||
return NextResponse.json({ error: '用户已被封禁' }, { status: 401 });
|
||||
}
|
||||
|
||||
// 检查收藏迁移标识,没有迁移标识时执行迁移
|
||||
if (!userInfoV2.favorite_migrated) {
|
||||
console.log(`用户 ${authInfo.username} 收藏未迁移,开始执行迁移...`);
|
||||
await db.migrateFavorites(authInfo.username);
|
||||
}
|
||||
} else {
|
||||
// 站长也需要执行迁移(站长可能不在数据库中,直接尝试迁移)
|
||||
const userInfoV2 = await db.getUserInfoV2(authInfo.username);
|
||||
if (!userInfoV2 || !userInfoV2.favorite_migrated) {
|
||||
console.log(`站长 ${authInfo.username} 收藏未迁移,开始执行迁移...`);
|
||||
await db.migrateFavorites(authInfo.username);
|
||||
}
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
|
||||
@@ -17,6 +17,7 @@ export async function GET(request: NextRequest) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
// 检查用户状态和执行迁移
|
||||
if (authInfo.username !== process.env.USERNAME) {
|
||||
// 非站长,检查用户存在或被封禁
|
||||
const userInfoV2 = await db.getUserInfoV2(authInfo.username);
|
||||
@@ -32,6 +33,13 @@ export async function GET(request: NextRequest) {
|
||||
console.log(`用户 ${authInfo.username} 播放记录未迁移,开始执行迁移...`);
|
||||
await db.migratePlayRecords(authInfo.username);
|
||||
}
|
||||
} else {
|
||||
// 站长也需要执行迁移(站长可能不在数据库中,直接尝试迁移)
|
||||
const userInfoV2 = await db.getUserInfoV2(authInfo.username);
|
||||
if (!userInfoV2 || !userInfoV2.playrecord_migrated) {
|
||||
console.log(`站长 ${authInfo.username} 播放记录未迁移,开始执行迁移...`);
|
||||
await db.migratePlayRecords(authInfo.username);
|
||||
}
|
||||
}
|
||||
|
||||
const records = await db.getAllPlayRecords(authInfo.username);
|
||||
|
||||
Reference in New Issue
Block a user