feat(ui): aggiunge barra di progresso durante lo smistamento

Mostra una progress bar con messaggio contestuale nelle 4 fasi:
scansione sorgente, analisi cartella destinazione (con contatore
cartelle), ricerca duplicati (con contatore file CAD), smistamento
(N / totale). La barra è indeterminata nelle prime tre fasi e
determinata durante la copia. Il canale IPC progress viene
aperto all'inizio e chiuso al termine dell'operazione
This commit is contained in:
2026-03-16 14:54:23 +01:00
parent 57f8b230b2
commit b0bcea2f10
8 changed files with 133 additions and 19 deletions

View File

@@ -27,7 +27,7 @@ async function buildZipHighestNumericVersionByCadKey(zipPath) {
try {
directory = await unzipper.Open.file(zipPath);
} catch {
return index;
return { index, total: 0 };
}
for (const row of directory.files || []) {
@@ -53,14 +53,17 @@ async function buildZipHighestNumericVersionByCadKey(zipPath) {
}
}
return index;
return { index, total: (directory.files || []).filter((f) => f.type === 'File').length };
}
async function processZip(zipPath, config) {
async function processZip(zipPath, config, onProgress) {
onProgress?.({ phase: 'scan' });
const { index: sourceMaxVersions, total } = await buildZipHighestNumericVersionByCadKey(zipPath);
const destinationIndex = await buildDestinationIndex(config?.destination, onProgress);
const existingCadKeys = await buildExistingCadKeyIndex(config?.destination, onProgress);
const stream = fs.createReadStream(zipPath).pipe(unzipper.Parse({ forceStream: true }));
const destinationIndex = await buildDestinationIndex(config?.destination);
const existingCadKeys = await buildExistingCadKeyIndex(config?.destination);
const sourceMaxVersions = await buildZipHighestNumericVersionByCadKey(zipPath);
const result = {
scanned: 0,
copied: 0,
@@ -70,6 +73,8 @@ async function processZip(zipPath, config) {
details: [],
};
let current = 0;
for await (const entry of stream) {
if (entry.type !== 'File') {
entry.autodrain();
@@ -78,7 +83,9 @@ async function processZip(zipPath, config) {
const file = entry.path;
const baseName = path.basename(file);
current += 1;
result.scanned += 1;
onProgress?.({ phase: 'copy', current, total, file: baseName });
const cadInfo = getCadInfo(baseName);
if (!cadInfo) {