Files
drhider/upload/frontend/zip/list_zip_files.js
T

23 lines
998 B
JavaScript

// listZipFiles — рекурсивно достать из ZIP только документы (вложенные zip — разворачиваются).
import { parseZip } from './parse_zip.js';
export async function listZipFiles(file, allowedExt) {
const buf = new Uint8Array(await file.arrayBuffer());
const entries = await parseZip(buf);
const out = [];
// Из ZIP вытаскиваем только документы. Всё прочее (изображения и т.п.) пропускаем.
for (const e of entries) {
if (e.isDir) continue;
const low = e.name.toLowerCase();
if (low.endsWith('.zip')) {
const sub = new File([e.data], e.name, { lastModified: e.dosMs });
out.push(...(await listZipFiles(sub, allowedExt)));
} else if (allowedExt.some(ext => low.endsWith(ext))) {
out.push(new File([e.data], e.name, { lastModified: e.dosMs }));
}
// иначе — не документ, пропускаем
}
return out;
}