Add hierarchical file picker
This commit is contained in:
@@ -5,18 +5,22 @@ 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);
|
||||
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 {
|
||||
const extracted = await listZipFiles(file, cfg.allowedExt);
|
||||
if (extracted.length) {
|
||||
extracted.forEach((item) => addFileWithDedup(state, item, cfg));
|
||||
} else {
|
||||
addFileWithDedup(state, file, cfg);
|
||||
}
|
||||
addFileWithDedup(state, await listZipFiles(file, cfg.allowedExt));
|
||||
} catch (error) {
|
||||
addFileWithDedup(state, file, cfg);
|
||||
addFileWithDedup(state, {
|
||||
id: crypto.randomUUID(), kind: 'zip', name: file.name, path: file.name,
|
||||
file, children: [], expanded: true, error: 'Не удалось раскрыть ZIP',
|
||||
});
|
||||
}
|
||||
}
|
||||
render(state, elements);
|
||||
|
||||
Reference in New Issue
Block a user