// api_v1/scanner/scanPhotoCartella.js const scanCartella = require('./scanCartella'); const scanPhotoSingle = require('./scanPhotoSingle'); const { log } = require('./logger'); const recordChange = require('./recordChange'); // ๐Ÿ‘ˆ AGGIUNTO async function scanPhotoCartella( db, user, cartella, absCartella, newFiles, updateStatusFile, CURRENT, TOTAL_FILES, start, deleteThumbsById, deleteFromDB ) { 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 await updateStatusFile(CURRENT, TOTAL_FILES, start); // 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); // ๐Ÿ‘‡ REGISTRAZIONE MODIFICA await recordChange(db, orphanId, user, "removed"); } } module.exports = scanPhotoCartella;