(dirHandle, path = dirHandle.name)
| 27 | |
| 28 | // Recursive function that walks the directory structure. |
| 29 | const getFiles = async (dirHandle, path = dirHandle.name) => { |
| 30 | const dirs = []; |
| 31 | const files = []; |
| 32 | for await (const entry of dirHandle.values()) { |
| 33 | const nestedPath = `${path}/${entry.name}`; |
| 34 | if (entry.kind === "file") { |
| 35 | files.push( |
| 36 | entry.getFile().then((file) => { |
| 37 | file.directoryHandle = dirHandle; |
| 38 | file.handle = entry; |
| 39 | return Object.defineProperty(file, "webkitRelativePath", { |
| 40 | configurable: true, |
| 41 | enumerable: true, |
| 42 | get: () => nestedPath, |
| 43 | }); |
| 44 | }) |
| 45 | ); |
| 46 | } else if (entry.kind === "directory") { |
| 47 | dirs.push(getFiles(entry, nestedPath)); |
| 48 | } |
| 49 | } |
| 50 | return [ |
| 51 | ...(await Promise.all(dirs)).flat(), |
| 52 | ...(await Promise.all(files)), |
| 53 | ]; |
| 54 | }; |
| 55 | |
| 56 | try { |
| 57 | // Open the directory. |
no test coverage detected