File tree Expand file tree Collapse file tree
packages/cli/src/lib/defaults/infra-modules/http/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919 "file-saver" : " 2.0.5" ,
2020 "jszip" : " 3.10.1" ,
2121 "fs-extra" : " 7.0.1" ,
22- "multer" : " 1.4.5-lts.1"
22+ "multer" : " 1.4.5-lts.1" ,
23+ "sanitize-filename" : " 1.6.3"
2324 },
2425 "devDependencies" : {
2526 "@types/express" : " 4.17.13" ,
Original file line number Diff line number Diff line change 11import JSZip from "jszip" ;
2+ import sanitize from "sanitize-filename" ;
23import fse from "fs-extra" ;
4+ import path from "path" ;
35
46export class Zip {
57 private _zip : JSZip ;
@@ -22,8 +24,13 @@ export class Zip {
2224 }
2325
2426 public createZip ( sourceDir : string , outputPath : string ) : Promise < boolean > {
27+ if ( ! fse . lstatSync ( sourceDir ) . isDirectory ( ) ) {
28+ throw new Error ( `Zip sourceDir '${ sourceDir } ' is not a directory.` ) ;
29+ }
30+
2531 fse . readdirSync ( sourceDir ) . forEach ( file => {
26- this . _zip . file ( file , fse . readFileSync ( `${ sourceDir } /${ file } ` ) )
32+ const filePath = path . join ( sourceDir , sanitize ( file ) ) ;
33+ this . _zip . file ( file , fse . readFileSync ( filePath ) )
2734 } )
2835 return this . _generateNodeZip ( outputPath ) ;
2936 }
You can’t perform that action at this time.
0 commit comments