Explorar o código

fix: bulk export minimal version update

Ryotaro Nagahara hai 1 mes
pai
achega
8a06681b61

+ 11 - 2
apps/app/src/features/page-bulk-export/server/service/page-bulk-export-job-cron/steps/compress-and-upload.ts

@@ -1,3 +1,4 @@
+import { PassThrough } from 'node:stream';
 import type { Archiver } from 'archiver';
 import type { Archiver } from 'archiver';
 import archiver from 'archiver';
 import archiver from 'archiver';
 
 
@@ -77,10 +78,18 @@ export async function compressAndUpload(
 
 
   pageArchiver.directory(this.getTmpOutputDir(pageBulkExportJob), false);
   pageArchiver.directory(this.getTmpOutputDir(pageBulkExportJob), false);
   pageArchiver.finalize();
   pageArchiver.finalize();
-  this.setStreamsInExecution(pageBulkExportJob._id, pageArchiver);
+
+  // Wrap with Node.js native PassThrough so that AWS SDK recognizes the stream as a native Readable
+  const uploadStream = new PassThrough();
+  pageArchiver.pipe(uploadStream);
+  pageArchiver.on('error', (err) => {
+    uploadStream.destroy(err);
+  });
+
+  this.setStreamsInExecution(pageBulkExportJob._id, pageArchiver, uploadStream);
 
 
   try {
   try {
-    await fileUploadService.uploadAttachment(pageArchiver, attachment);
+    await fileUploadService.uploadAttachment(uploadStream, attachment);
   } catch (e) {
   } catch (e) {
     logger.error(e);
     logger.error(e);
     this.handleError(e, pageBulkExportJob);
     this.handleError(e, pageBulkExportJob);