Add hierarchical file picker

This commit is contained in:
“Naeel”
2026-09-05 09:29:03 +03:00
parent 85605fe8c6
commit a965f181d9
11 changed files with 181 additions and 97 deletions
+12 -8
View File
@@ -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);