73 lines
1.9 KiB
JavaScript
73 lines
1.9 KiB
JavaScript
// tools/listFolderIds.js
|
|
const fs = require('fs');
|
|
const fsp = require('fs/promises');
|
|
const path = require('path');
|
|
const readline = require('readline');
|
|
const { WEB_ROOT, INDEX_PATH } = require('../config');
|
|
|
|
async function buildIdsListForFolder(userName, cartella) {
|
|
const indexPath = path.resolve(__dirname, '..', '..', WEB_ROOT, INDEX_PATH);
|
|
const idsIndex = [];
|
|
|
|
console.log("\n[LIST] buildIdsListForFolder()");
|
|
console.log("[LIST] user =", userName);
|
|
console.log("[LIST] cartella=", cartella);
|
|
console.log("[LIST] indexPath =", indexPath);
|
|
|
|
if (!fs.existsSync(indexPath)) {
|
|
console.log("[LIST] index.json non trovato");
|
|
return idsIndex;
|
|
}
|
|
|
|
try {
|
|
const raw = await fsp.readFile(indexPath, 'utf8');
|
|
const index = JSON.parse(raw);
|
|
|
|
const userObj = index[userName];
|
|
if (!userObj) {
|
|
console.log(`[LIST] Nessuna entry per user=${userName}`);
|
|
return idsIndex;
|
|
}
|
|
|
|
const folder = userObj[cartella];
|
|
if (!folder) {
|
|
console.log(`[LIST] Nessuna cartella "${cartella}" per user=${userName}`);
|
|
return idsIndex;
|
|
}
|
|
|
|
const ids = Object.keys(folder).filter(k => k !== "_folderHash");
|
|
idsIndex.push(...ids);
|
|
|
|
console.log(`\n[LIST] ID trovati in ${userName}/${cartella}: ${idsIndex.length}`);
|
|
idsIndex.forEach(id => console.log(" -", id));
|
|
console.log("");
|
|
|
|
return idsIndex;
|
|
|
|
} catch (err) {
|
|
console.log("[LIST] Errore leggendo/parsing index.json:", err.message);
|
|
return idsIndex;
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
|
|
const ask = (q) => new Promise(res => rl.question(q, res));
|
|
|
|
try {
|
|
const user = await ask('User: ');
|
|
const cartella = await ask('Cartella: ');
|
|
|
|
await buildIdsListForFolder(user.trim(), cartella.trim());
|
|
} finally {
|
|
rl.close();
|
|
}
|
|
}
|
|
|
|
main().catch(err => {
|
|
console.error("Errore:", err);
|
|
});
|