fix: add fallback savetime

This commit is contained in:
shinya
2025-07-18 00:38:10 +08:00
parent da23e04564
commit e2aeb352a1
2 changed files with 9 additions and 6 deletions

View File

@@ -89,12 +89,12 @@ export async function POST(request: NextRequest) {
);
}
const favoriteWithoutUserId = {
const finalFavorite = {
...favorite,
save_time: favorite.save_time ?? Date.now(),
} as Omit<Favorite, 'user_id'>;
} as Favorite;
await db.saveFavorite(authInfo.username, source, id, favoriteWithoutUserId);
await db.saveFavorite(authInfo.username, source, id, finalFavorite);
return NextResponse.json({ success: true }, { status: 200 });
} catch (err) {

View File

@@ -36,8 +36,6 @@ export async function POST(request: NextRequest) {
}
const body = await request.json();
console.log('username', authInfo.username);
console.log('body', body);
const { key, record }: { key: string; record: PlayRecord } = body;
if (!key || !record) {
@@ -64,7 +62,12 @@ export async function POST(request: NextRequest) {
);
}
await db.savePlayRecord(authInfo.username, source, id, record);
const finalRecord = {
...record,
save_time: record.save_time ?? Date.now(),
} as PlayRecord;
await db.savePlayRecord(authInfo.username, source, id, finalRecord);
return NextResponse.json({ success: true }, { status: 200 });
} catch (err) {