WIP blurash & sync card ?
All checks were successful
Deploy App / build (push) Successful in 26s
Deploy App / deploy (push) Successful in 18s

This commit is contained in:
valere
2026-02-21 09:07:45 +01:00
parent 543b513e08
commit aef705834b
8 changed files with 425 additions and 20 deletions

View File

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