WIP blurash & sync card ?
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { eq, notInArray } from 'drizzle-orm'
|
||||
import { useDB, schema } from '../db'
|
||||
import { scanMusicFolder } from '../utils/fileScanner'
|
||||
import { generateBlurhash } from '../utils/blurHash'
|
||||
|
||||
const { cards } = schema
|
||||
|
||||
@@ -21,27 +22,34 @@ export async function syncCardsWithDatabase(folderPath: string) {
|
||||
const scannedEsids = new Set(scannedCards.map((t) => t.esid))
|
||||
const cardsToDelete = existingCards.filter((t) => !scannedEsids.has(t.esid))
|
||||
|
||||
// 4. Insérer les nouvelles cards
|
||||
// 4. Insérer les nouvelles cartes
|
||||
if (cardsToInsert.length > 0) {
|
||||
// Dans la fonction syncCardsWithDatabase
|
||||
await db.insert(cards).values(
|
||||
cardsToInsert.map((card) => ({
|
||||
url_audio: card.url_audio,
|
||||
url_image: card.url_image,
|
||||
year: card.year,
|
||||
month: card.month,
|
||||
day: card.day,
|
||||
hour: card.hour,
|
||||
artist: card.artist,
|
||||
title: card.title,
|
||||
esid: card.esid,
|
||||
slug: card.slug,
|
||||
createdAt: card.createdAt,
|
||||
suit: card.suit,
|
||||
rank: card.rank
|
||||
}))
|
||||
// Générer tous les blurhash en parallèle
|
||||
const cardsWithBlurhash = await Promise.all(
|
||||
cardsToInsert.map(async (card) => {
|
||||
const blurhash = await generateBlurhash(card.url_image)
|
||||
return {
|
||||
url_audio: card.url_audio,
|
||||
url_image: card.url_image,
|
||||
year: card.year,
|
||||
month: card.month,
|
||||
day: card.day,
|
||||
hour: card.hour,
|
||||
artist: card.artist,
|
||||
title: card.title,
|
||||
esid: card.esid,
|
||||
slug: card.slug,
|
||||
createdAt: card.createdAt,
|
||||
suit: card.suit,
|
||||
rank: card.rank,
|
||||
blurhash: blurhash
|
||||
}
|
||||
})
|
||||
)
|
||||
console.log(`✅ ${cardsToInsert.length} cards ajoutées`)
|
||||
|
||||
// Insérer les cartes avec les blurhash déjà résolus
|
||||
await db.insert(cards).values(cardsWithBlurhash)
|
||||
console.log(`✅ ${cardsToInsert.length} cartes ajoutées`)
|
||||
}
|
||||
|
||||
// 5. Supprimer les cards obsolètes avec une requête distincte pour chaque esid
|
||||
|
||||
Reference in New Issue
Block a user