@@ -4,14 +4,15 @@ import {FatalError, logger} from "./logger";
44import AdmZip = require( "adm-zip" ) ;
55import { v4 as uuidv4 } from "uuid" ;
66import * as os from "node:os" ;
7+ import { FileConstants } from "./file.constants" ;
78
89export class FileService {
910 public static readonly fileDownloadedMessage = "File downloaded successfully. New filename: " ;
1011
1112 public writeToFileWithGivenName ( data : any , filename : string ) : void {
1213 fs . writeFileSync ( path . resolve ( process . cwd ( ) , filename ) , this . getSerializedFileContent ( data ) , {
1314 encoding : "utf-8" ,
14- mode : "0600" ,
15+ mode : FileConstants . DEFAULT_FILE_PERMISSIONS ,
1516 } ) ;
1617 }
1718
@@ -35,7 +36,7 @@ export class FileService {
3536 }
3637
3738 public extractExportedZipWithNestedZipsToDir ( zipFile : AdmZip , targetDir : string ) : string {
38- fs . mkdirSync ( targetDir , { recursive : true , mode : 0o700 } ) ;
39+ fs . mkdirSync ( targetDir , { recursive : true , mode : FileConstants . DEFAULT_FOLDER_PERMISSIONS } ) ;
3940 zipFile . extractAllTo ( targetDir , true , true ) ;
4041
4142 const files = fs . readdirSync ( targetDir ) ;
@@ -45,7 +46,7 @@ export class FileService {
4546 const nestedZip = new AdmZip ( innerZipPath ) ;
4647 const nestedDir = innerZipPath . replace ( / \. z i p $ / , "" ) ;
4748
48- fs . mkdirSync ( nestedDir , { recursive : true , mode : 0o700 } ) ;
49+ fs . mkdirSync ( nestedDir , { recursive : true , mode : FileConstants . DEFAULT_FOLDER_PERMISSIONS } ) ;
4950 nestedZip . extractAllTo ( nestedDir , true , true ) ;
5051 fs . rmSync ( innerZipPath ) ; // Optionally remove the inner zip
5152 }
@@ -75,16 +76,16 @@ export class FileService {
7576 zip . addLocalFolder ( fullPath ) ;
7677 const zippedBuffer = zip . toBuffer ( ) ;
7778
78- finalZip . addFile ( `${ file } .zip` , zippedBuffer , "" , 0x600 ) ;
79+ finalZip . addFile ( `${ file } .zip` , zippedBuffer , "" , FileConstants . DEFAULT_FILE_PERMISSIONS ) ;
7980 } else if ( stat . isFile ( ) ) {
8081 finalZip . addLocalFile ( fullPath ) ;
8182 }
8283 } ) ;
8384
8485 const tempDir = path . join ( os . tmpdir ( ) , "content-cli-exports" ) ;
85- fs . mkdirSync ( tempDir , { recursive : true , mode : 0o700 } ) ;
86+ fs . mkdirSync ( tempDir , { recursive : true , mode : FileConstants . DEFAULT_FOLDER_PERMISSIONS } ) ;
8687 const zipFilePath = path . join ( tempDir , `export_${ uuidv4 ( ) } .zip` ) ;
87- finalZip . writeZip ( zipFilePath , ( ) => fs . chmodSync ( zipFilePath , 0o600 ) ) ;
88+ finalZip . writeZip ( zipFilePath , ( ) => fs . chmodSync ( zipFilePath , FileConstants . DEFAULT_FILE_PERMISSIONS ) ) ;
8889
8990 return zipFilePath ;
9091 }
@@ -99,10 +100,10 @@ export class FileService {
99100 for ( const file of files ) {
100101 const filePath = path . join ( targetDir , file ) ;
101102 if ( fs . statSync ( filePath ) ?. isDirectory ( ) ) {
102- fs . chmodSync ( filePath , 0o700 ) ;
103+ fs . chmodSync ( filePath , FileConstants . DEFAULT_FOLDER_PERMISSIONS ) ;
103104 this . restrictFilePermissions ( filePath ) ;
104105 } else {
105- fs . chmodSync ( filePath , 0o600 ) ;
106+ fs . chmodSync ( filePath , FileConstants . DEFAULT_FILE_PERMISSIONS ) ;
106107 }
107108 }
108109 }
0 commit comments