@@ -136,15 +136,15 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
136136 throw new Error ( 'No data collected from the stream.' ) ;
137137 }
138138
139- const data = await handleFileProcessing ( fileExt , xmlData , cmsType , name ) ;
139+ const data = await handleFileProcessing ( fileExt , xmlData , cmsType , name ) ;
140140 res . status ( data ?. status || 200 ) . json ( data ) ;
141141 if ( data ?. status === 200 ) {
142142 const filePath = path . join ( __dirname , '..' , '..' , 'extracted_files' , `${ name } .json` ) ;
143143 createMapper ( filePath , projectId , app_token , affix , config ) ;
144144 }
145145 } ) ;
146146 }
147- else {
147+ else {
148148 // Create a writable stream to save the downloaded zip file
149149 let zipBuffer = Buffer . alloc ( 0 ) ;
150150
@@ -162,67 +162,67 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
162162 if ( ! zipBuffer ) {
163163 throw new Error ( 'No data collected from the stream.' ) ;
164164 }
165- const data = await handleFileProcessing ( fileExt , zipBuffer , cmsType , name ) ;
165+ const data = await handleFileProcessing ( fileExt , zipBuffer , cmsType , name ) ;
166166 res . status ( data ?. status || 200 ) . json ( data ) ;
167167 if ( data ?. status === 200 ) {
168168 const filePath = path . join ( __dirname , '..' , '..' , 'extracted_files' , name ) ;
169169 createMapper ( filePath , projectId , app_token , affix , config ) ;
170170 }
171171 } ) ;
172- }
173- }
174- } else {
175- const params = {
176- Bucket : config ?. awsData ?. bucketName ,
177- Key : config ?. awsData ?. buketKey
178- } ;
179- const getObjectCommand = new GetObjectCommand ( params ) ;
180- // Get the object from S3
181- const s3File = await client . send ( getObjectCommand ) ;
182- //file Name From key
183- const fileName = params ?. Key ?. split ?.( '/' ) ?. pop ?.( ) ?? '' ;
184- //file ext from fileName
185- const fileExt = fileName ?. split ?.( '.' ) ?. pop ?.( ) ?? 'test' ;
186-
187- if ( ! s3File ?. Body ) {
188- throw new Error ( 'Empty response body from S3' ) ;
189- }
172+ }
173+ }
174+ } else {
175+ const params = {
176+ Bucket : config ?. awsData ?. bucketName ,
177+ Key : config ?. awsData ?. bucketKey
178+ } ;
179+ const getObjectCommand = new GetObjectCommand ( params ) ;
180+ // Get the object from S3
181+ const s3File = await client . send ( getObjectCommand ) ;
182+ //file Name From key
183+ const fileName = params ?. Key ?. split ?.( '/' ) ?. pop ?.( ) ?? '' ;
184+ //file ext from fileName
185+ const fileExt = fileName ?. split ?.( '.' ) ?. pop ?.( ) ?? 'test' ;
186+
187+ if ( ! s3File ?. Body ) {
188+ throw new Error ( 'Empty response body from S3' ) ;
189+ }
190190
191- const bodyStream : Readable = s3File ?. Body as Readable ;
191+ const bodyStream : Readable = s3File ?. Body as Readable ;
192192
193- // Create a writable stream to save the downloaded zip file
194- const zipFileStream = createWriteStream ( `${ fileName } ` ) ;
193+ // Create a writable stream to save the downloaded zip file
194+ const zipFileStream = createWriteStream ( `${ fileName } ` ) ;
195195
196- // // Pipe the S3 object's body to the writable stream
197- bodyStream . pipe ( zipFileStream ) ;
196+ // // Pipe the S3 object's body to the writable stream
197+ bodyStream . pipe ( zipFileStream ) ;
198198
199- // Create a writable stream to save the downloaded zip file
200- let zipBuffer : Buffer | null = null ;
199+ // Create a writable stream to save the downloaded zip file
200+ let zipBuffer : Buffer | null = null ;
201201
202- // Collect the data from the stream into a buffer
203- bodyStream . on ( 'data' , ( chunk ) => {
204- if ( zipBuffer === null ) {
205- zipBuffer = chunk ;
206- } else {
207- zipBuffer = Buffer . concat ( [ zipBuffer , chunk ] ) ;
208- }
209- } ) ;
202+ // Collect the data from the stream into a buffer
203+ bodyStream . on ( 'data' , ( chunk ) => {
204+ if ( zipBuffer === null ) {
205+ zipBuffer = chunk ;
206+ } else {
207+ zipBuffer = Buffer . concat ( [ zipBuffer , chunk ] ) ;
208+ }
209+ } ) ;
210210
211- //buffer fully stremd
212- bodyStream . on ( 'end' , async ( ) => {
213- if ( ! zipBuffer ) {
214- throw new Error ( 'No data collected from the stream.' ) ;
215- }
211+ //buffer fully stremd
212+ bodyStream . on ( 'end' , async ( ) => {
213+ if ( ! zipBuffer ) {
214+ throw new Error ( 'No data collected from the stream.' ) ;
215+ }
216216
217- const data = await handleFileProcessing ( fileExt , zipBuffer , cmsType , fileName ) ;
218- res . json ( data ) ;
219- res . send ( 'file valited sucessfully.' ) ;
220- const filePath = path . join ( __dirname , '..' , '..' , 'extracted_files' , fileName ) ;
221- console . log ( "🚀 ~ bodyStream.on ~ filePath:" , filePath )
222- createMapper ( filePath , projectId , app_token , affix , config ) ;
223- } ) ;
217+ const data = await handleFileProcessing ( fileExt , zipBuffer , cmsType , fileName ) ;
218+ res . json ( data ) ;
219+ res . send ( 'file valited sucessfully.' ) ;
220+ const filePath = path . join ( __dirname , '..' , '..' , 'extracted_files' , fileName ) ;
221+ console . log ( "🚀 ~ bodyStream.on ~ filePath:" , filePath )
222+ createMapper ( filePath , projectId , app_token , affix , config ) ;
223+ } ) ;
224+ }
224225 }
225- }
226226 catch ( err : any ) {
227227 console . error ( '🚀 ~ router.get ~ err:' , err ) ;
228228 }
0 commit comments