// api_v1/scanner/scanPhotoCartella.js const scanCartella = require('./scanCartella'); const scanPhotoSingle = require('./scanPhotoSingle'); const { log } = require('./logger'); async function scanPhotoCartella( db, user, cartella, absCartella, newFiles, updateStatusFile, CURRENT, TOTAL_FILES, start, deleteThumbsById, deleteFromDB, onProgress // ๐Ÿ”ฅ AGGIUNTO ) { log(`๐Ÿ“ Scan cartella: ${cartella}`); // Recupera gli ID giร  presenti nel DB const rows = await db('photos') .where({ user, cartella }) .select('id'); const idsSet = new Set(rows.map(r => r.id)); // Scansiona i file della cartella for await (const f of scanCartella(user, cartella, absCartella, db)) { // Aggiorna il contatore CURRENT.value++; // ๐Ÿ”ฅ Aggiorna stato avanzamento (vecchio sistema) await updateStatusFile(CURRENT, TOTAL_FILES, start); // ๐Ÿ”ฅ Aggiorna stato avanzamento (nuovo sistema) if (onProgress) { await onProgress(); } // Processa il file const meta = await scanPhotoSingle(db, user, cartella, f, newFiles); // Anche se identico, NON รจ orfano idsSet.delete(f.id); } // Gestione orfani for (const orphanId of idsSet) { log(`๐Ÿ”ด Orfano: ${orphanId}`); await deleteThumbsById(orphanId); await deleteFromDB(orphanId, user); } } module.exports = scanPhotoCartella;