Skip to content

Commit be0ffb4

Browse files
committed
fix: allow uploading zip with single directory
1 parent f134ad2 commit be0ffb4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

apps/playground/src/utils/load.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,30 @@ export async function loadEditorFilesFromNative(files: File[]) {
5050

5151
export async function loadEditorFilesFromZip(zip: JSZip) {
5252
const editorFiles: EditorFile[] = [];
53+
54+
const dirs = zip.filter((_, file) => file.dir);
55+
56+
if (dirs.length > 1) {
57+
throw new Error(`Archive contains more than one directory: ${dirs.map(({ name }) => name).join(', ')}`);
58+
}
59+
60+
const basename = dirs.length ? dirs[0]!.name : '';
61+
5362
for (const file of Object.values(zip.files)) {
63+
if (file.dir) {
64+
continue;
65+
}
66+
const filename = file.name.slice(basename.length, file.name.length);
5467
let content: string;
55-
const isBase64 = isBase64EncodedFileType(file.name);
68+
const isBase64 = isBase64EncodedFileType(filename);
5669
if (isBase64) {
5770
content = await file.async('base64');
5871
} else {
5972
content = await file.async('string');
6073
}
6174
editorFiles.push({
6275
content,
63-
name: file.name
76+
name: filename
6477
});
6578
}
6679
return editorFiles;

0 commit comments

Comments
 (0)