33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
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')) {
|
|
if (!cfg.allowedExt.some((extension) => file.name.toLowerCase().endsWith(extension.toLowerCase()))) {
|
|
continue;
|
|
}
|
|
addFileWithDedup(state, {
|
|
id: crypto.randomUUID(), kind: 'file', name: file.name, path: file.name,
|
|
file, children: [], expanded: true,
|
|
});
|
|
continue;
|
|
}
|
|
try {
|
|
addFileWithDedup(state, await listZipFiles(file, cfg.allowedExt));
|
|
} catch (error) {
|
|
addFileWithDedup(state, {
|
|
id: crypto.randomUUID(), kind: 'zip', name: file.name, path: file.name,
|
|
file, children: [], expanded: true, error: 'Не удалось раскрыть ZIP',
|
|
});
|
|
}
|
|
}
|
|
render(state, elements);
|
|
}
|
|
|
|
export function onFilesChange(state, cfg, elements) {
|
|
return () => {
|
|
if (!state.busy) addFiles(state, cfg, elements.fileInputEl.files, elements);
|
|
};
|
|
} |