迁移收藏到新数据结构

This commit is contained in:
mtvpls
2025-12-30 22:00:36 +08:00
parent f43d9c7d0e
commit 39f2bb3450
6 changed files with 268 additions and 34 deletions

View File

@@ -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);

View File

@@ -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);