29 lines
886 B
JavaScript
29 lines
886 B
JavaScript
import { listZipFiles } from '../zip/list_zip_files.js';
|
|
import { addFileWithDedup } from './add_file_with_dedup.js';
|
|
import { render } from './render.js';
|
|
|
|
export async function addFiles(state, cfg, files, elements) {
|
|
for (const file of Array.from(files)) {
|
|
if (!file.name.toLowerCase().endsWith('.zip')) {
|
|
addFileWithDedup(state, file, cfg);
|
|
continue;
|
|
}
|
|
try {
|
|
const extracted = await listZipFiles(file, cfg.allowedExt);
|
|
if (extracted.length) {
|
|
extracted.forEach((item) => addFileWithDedup(state, item, cfg));
|
|
} else {
|
|
addFileWithDedup(state, file, cfg);
|
|
}
|
|
} catch (error) {
|
|
addFileWithDedup(state, file, cfg);
|
|
}
|
|
}
|
|
render(state, elements);
|
|
}
|
|
|
|
export function onFilesChange(state, cfg, elements) {
|
|
return () => {
|
|
if (!state.busy) addFiles(state, cfg, elements.fileInputEl.files, elements);
|
|
};
|
|
} |