File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
apps/playground/src/utils Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -50,17 +50,30 @@ export async function loadEditorFilesFromNative(files: File[]) {
5050
5151export 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 ;
You can’t perform that action at this time.
0 commit comments