| 44 | |
| 45 | // UPLOADER UTILITIES |
| 46 | export async function readDirectoryRecursive(dirHandle: any, prefix = "") { |
| 47 | let files: { path: string, content: string }[] = []; |
| 48 | for await (const entry of dirHandle.values()) { |
| 49 | if (entry.kind === 'file') { |
| 50 | if (entry.name.match(/\.(js|ts|jsx|tsx|py|c|h|cpp|hpp|cc|cs|go|rs|rb|php|swift|kt|kts|dart)$/)) { |
| 51 | const file = await entry.getFile(); |
| 52 | files.push({ path: `${prefix}/${entry.name}`, content: await file.text() }); |
| 53 | } |
| 54 | } else if (entry.kind === 'directory') { |
| 55 | if (!['node_modules', '.git', 'dist', 'build', '.idea', '__pycache__'].includes(entry.name)) { |
| 56 | files = files.concat(await readDirectoryRecursive(entry, `${prefix}/${entry.name}`)); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | return files; |
| 61 | } |
| 62 | |
| 63 | export async function unzipFiles(zipBuffer: ArrayBuffer) { |
| 64 | const jszip = await JSZip.loadAsync(zipBuffer); |