feat: implement song rating system with admin view and user persistence
This commit is contained in:
@@ -33,23 +33,33 @@ async function restoreSongs() {
|
||||
|
||||
const title = metadata.common.title || 'Unknown Title';
|
||||
const artist = metadata.common.artist || 'Unknown Artist';
|
||||
const genres = metadata.common.genre || [];
|
||||
|
||||
// Try to find matching cover
|
||||
// This is a best-effort guess based on timestamp or just null if we can't link it easily
|
||||
// Since we don't store the link between file and cover in filename, we might lose cover association
|
||||
// unless we re-extract it. But we already have cover files.
|
||||
// For now, let's just restore the song entry. Re-extracting cover would duplicate files.
|
||||
// If the user wants covers back perfectly, we might need to re-parse or just leave null.
|
||||
// Let's leave null for now to avoid clutter, or maybe try to find a cover with similar timestamp if possible?
|
||||
// Actually, the cover filename is not easily deducible from song filename.
|
||||
// Let's just restore the song data.
|
||||
// Create or find genres
|
||||
const genreConnect = [];
|
||||
for (const genreName of genres) {
|
||||
if (!genreName) continue;
|
||||
|
||||
// Simple normalization
|
||||
const normalizedGenre = genreName.trim();
|
||||
|
||||
// Upsert genre (we can't use upsert easily with connect, so find or create first)
|
||||
let genre = await prisma.genre.findUnique({ where: { name: normalizedGenre } });
|
||||
if (!genre) {
|
||||
genre = await prisma.genre.create({ data: { name: normalizedGenre } });
|
||||
console.log(`Created genre: ${normalizedGenre}`);
|
||||
}
|
||||
genreConnect.push({ id: genre.id });
|
||||
}
|
||||
|
||||
await prisma.song.create({
|
||||
data: {
|
||||
title,
|
||||
artist,
|
||||
filename,
|
||||
// coverImage: null // We lose the cover link unfortunately, unless we re-extract
|
||||
genres: {
|
||||
connect: genreConnect
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user