From a0b89365c2be987bb5c0834a9b591a0205934729 Mon Sep 17 00:00:00 2001 From: Michele Bigi Date: Mon, 21 Sep 2026 08:00:08 +0200 Subject: [PATCH] Type directory picker without DOM FileSystemDirectoryHandle.entries. --- .../components/upload/file-upload-zone.tsx | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/periscope/src/frontend/src/components/upload/file-upload-zone.tsx b/periscope/src/frontend/src/components/upload/file-upload-zone.tsx index 90e1da6..d404800 100644 --- a/periscope/src/frontend/src/components/upload/file-upload-zone.tsx +++ b/periscope/src/frontend/src/components/upload/file-upload-zone.tsx @@ -94,23 +94,20 @@ function mergeSelection(current: File[], incoming: File[], multiple: boolean, di return [...current, ...incoming]; } -async function filesFromDirectoryHandle( - handle: FileSystemDirectoryHandle, - prefix = "", -): Promise { +type DirHandle = { + name: string; + entries: () => AsyncIterable<[string, { kind: string; getFile?: () => Promise } & DirHandle]>; +}; + +async function filesFromDirectoryHandle(handle: DirHandle, prefix = ""): Promise { const out: File[] = []; for await (const [name, child] of handle.entries()) { if (SKIP_DIR.test(name)) continue; - if (child.kind === "file") { + if (child.kind === "file" && child.getFile) { const file = await child.getFile(); out.push(stampRelativePath(file, prefix + name)); } else if (child.kind === "directory") { - out.push( - ...(await filesFromDirectoryHandle( - child as FileSystemDirectoryHandle, - prefix + name + "/", - )), - ); + out.push(...(await filesFromDirectoryHandle(child, prefix + name + "/"))); } } return out; @@ -137,9 +134,7 @@ function pickFolderViaHiddenInput(): Promise { async function pickProjectFolder(): Promise { const picker = ( - window as Window & { - showDirectoryPicker?: () => Promise; - } + window as Window & { showDirectoryPicker?: () => Promise } ).showDirectoryPicker; if (typeof picker === "function") { try {