From 9211c9461cfc280faf863d661c944a9f6fa145ba Mon Sep 17 00:00:00 2001 From: Quan HL Date: Fri, 28 Jul 2023 20:51:27 +0700 Subject: [PATCH] fix --- lib/record/google-storage.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/record/google-storage.js b/lib/record/google-storage.js index 577caa6..499b723 100644 --- a/lib/record/google-storage.js +++ b/lib/record/google-storage.js @@ -6,15 +6,17 @@ class GoogleStorageUploadStream extends Writable { constructor(logger, opts) { super(opts); this.logger = logger; + this.metadata = opts.metadata; const storage = new Storage(opts.bucketCredential); this.gcsFile = storage.bucket(opts.bucketName).file(opts.Key); - this.writeStream = this.gcsFile.createWriteStream({ - metadata: opts.metadata - }); + this.writeStream = this.gcsFile.createWriteStream(); this.writeStream.on('error', (err) => this.logger.error(err)); - this.writeStream.on('finish', () => this.logger.info('google storage Upload completed.')); + this.writeStream.on('finish', () => { + this.logger.info('google storage Upload completed.'); + this._addMetadata(); + }); } _write(chunk, encoding, callback) { @@ -25,6 +27,15 @@ class GoogleStorageUploadStream extends Writable { this.writeStream.end(); this.writeStream.once('finish', callback); } + + async _addMetadata() { + try { + await this.gcsFile.setMetadata(this.metadata); + this.logger.info('Google storage Upload and metadata setting completed.'); + } catch (err) { + this.logger.error(err, 'Google storage An error occurred while setting metadata'); + } + } } module.exports = GoogleStorageUploadStream;