( files: HttpImportFile[], )
| 11 | } |
| 12 | |
| 13 | export async function expandZipFiles( |
| 14 | files: HttpImportFile[], |
| 15 | ): Promise<HttpImportFile[]> { |
| 16 | const expandedFiles: HttpImportFile[] = [] |
| 17 | |
| 18 | for (const file of files) { |
| 19 | if (!isZipFile(file)) { |
| 20 | expandedFiles.push(file) |
| 21 | continue |
| 22 | } |
| 23 | |
| 24 | const zip = await JSZip.loadAsync( |
| 25 | file.encoding === 'base64' ? decodeBase64(file.content) : file.content, |
| 26 | ) |
| 27 | |
| 28 | for (const [path, entry] of Object.entries(zip.files)) { |
| 29 | if (entry.dir) |
| 30 | continue |
| 31 | |
| 32 | const lowerPath = path.toLowerCase() |
| 33 | if ( |
| 34 | !lowerPath.endsWith('.yml') |
| 35 | && !lowerPath.endsWith('.yaml') |
| 36 | && !lowerPath.endsWith('.json') |
| 37 | ) { |
| 38 | continue |
| 39 | } |
| 40 | |
| 41 | expandedFiles.push({ |
| 42 | content: await entry.async('string'), |
| 43 | name: `${file.name}/${path}`, |
| 44 | }) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return expandedFiles |
| 49 | } |
no test coverage detected