62 lines
No EOL
1.4 KiB
JavaScript
62 lines
No EOL
1.4 KiB
JavaScript
// 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; |