Fix file picker extension filtering
This commit is contained in:
@@ -15,12 +15,10 @@ export async function addFiles(state, cfg, files, elements) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
addFileWithDedup(state, await listZipFiles(file, cfg.allowedExt));
|
||||
const zipTree = await listZipFiles(file, cfg.allowedExt);
|
||||
if (zipTree) addFileWithDedup(state, zipTree);
|
||||
} catch (error) {
|
||||
addFileWithDedup(state, {
|
||||
id: crypto.randomUUID(), kind: 'zip', name: file.name, path: file.name,
|
||||
file, children: [], expanded: true, error: 'Не удалось раскрыть ZIP',
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
render(state, elements);
|
||||
|
||||
@@ -41,12 +41,12 @@ export function onFolderChange(state, cfg, elements) {
|
||||
if (lowerPath.endsWith('.zip')) {
|
||||
try {
|
||||
const zip = await listZipFiles(file, cfg.allowedExt);
|
||||
rebaseTree(zip, rootName);
|
||||
addToFolder(zip);
|
||||
if (zip) {
|
||||
rebaseTree(zip, rootName);
|
||||
addToFolder(zip);
|
||||
}
|
||||
} catch (error) {
|
||||
addToFolder({ id: crypto.randomUUID(), kind: 'zip', name: parts.at(-1),
|
||||
path: relativePath, file, children: [], expanded: true,
|
||||
error: 'Не удалось раскрыть ZIP' });
|
||||
continue;
|
||||
}
|
||||
} else if (cfg.allowedExt.some((extension) => lowerPath.endsWith(extension))) {
|
||||
addToFolder({ id: crypto.randomUUID(), kind: 'file', name: parts.at(-1),
|
||||
|
||||
@@ -44,16 +44,18 @@ async function listEntries(data, zipName, allowedExt, depth) {
|
||||
if (entryName.endsWith('/')) continue;
|
||||
if (entryName.toLowerCase().endsWith('.zip')) {
|
||||
const nested = await listEntries(entryData, entryName, allowedExt, depth + 1);
|
||||
rebaseTree(nested, zipName);
|
||||
nested.name = entryName.split('/').pop();
|
||||
addPath(root, entryName.split('/'), nested);
|
||||
if (nested) {
|
||||
rebaseTree(nested, zipName);
|
||||
nested.name = entryName.split('/').pop();
|
||||
addPath(root, entryName.split('/'), nested);
|
||||
}
|
||||
} else if (extensionAllowed(entryName, allowedExt)) {
|
||||
const path = `${zipName}/${entryName}`;
|
||||
const file = makeFile(entryData, path);
|
||||
addPath(root, entryName.split('/'), node('file', entryName.split('/').pop(), path, [], file));
|
||||
}
|
||||
}
|
||||
return root;
|
||||
return root.children.length ? root : null;
|
||||
}
|
||||
|
||||
export async function listZipFiles(file, allowedExt) {
|
||||
|
||||
Reference in New Issue
Block a user