-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/158222 158279 bulk export for file upload types other than s3/gcs #9467
Feat/158222 158279 bulk export for file upload types other than s3/gcs #9467
Conversation
|
@@ -164,7 +164,7 @@ export abstract class AbstractFileUploader implements FileUploader { | |||
throw new Error('Multipart upload not available for file upload type'); | |||
} | |||
|
|||
abstract uploadAttachment(readStream: ReadStream, attachment: IAttachmentDocument): Promise<void>; | |||
abstract uploadAttachment(readable: Readable, attachment: IAttachmentDocument): Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Archiver のインスタンスが渡せるように Readable に変更
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここデグレしないか慎重になる必要がある
attachment.js が TypeScript になっていないせいで createAttachment メソッドが型安全じゃない状態。
fs.createReadStream()
の返り値は Readable にそのまま入れられる、でいいのだろうか。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
メモ: attachment.js で createReadStream を使用している部分
const fileStream = fs.createReadStream(file.path, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ただ、すみません、aws と gcs の uploadAttachment の引数の定義を Readable に書き換えるのを忘れており、gcs は ReadStream のメソッドも使っていたため、Readable で完結するように修正しました。
a6a9607
(詳細は apps/app/src/server/service/file-uploader/gcs/index.ts のコメントに記載
@@ -157,7 +157,7 @@ class PageBulkExportJobCronService extends CronService implements IPageBulkExpor | |||
exportPagesToFsAsync.bind(this)(pageBulkExportJob); | |||
} | |||
else if (pageBulkExportJob.status === PageBulkExportJobStatus.uploading) { | |||
await compressAndUploadAsync.bind(this)(user, pageBulkExportJob); | |||
compressAndUpload.bind(this)(user, pageBulkExportJob); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multipart upload の準備のエラーをキャッチするために await していたが、multipart upload しなくなったため await を除外。
(また、await してしまうと、compressAndUpload 内の uploadAttachment を待つようになってしまう
@@ -1,117 +0,0 @@ | |||
import { Writable, pipeline } from 'stream'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ファイル名を compress-and-upload.ts に変更
return pageArchiver; | ||
} | ||
|
||
function getMultipartUploadWritable( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このメソッドは削除し、final で実行していた後処理だけ postProcess メソッドとして抽出。
@@ -164,7 +164,7 @@ export abstract class AbstractFileUploader implements FileUploader { | |||
throw new Error('Multipart upload not available for file upload type'); | |||
} | |||
|
|||
abstract uploadAttachment(readStream: ReadStream, attachment: IAttachmentDocument): Promise<void>; | |||
abstract uploadAttachment(readable: Readable, attachment: IAttachmentDocument): Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここデグレしないか慎重になる必要がある
attachment.js が TypeScript になっていないせいで createAttachment メソッドが型安全じゃない状態。
fs.createReadStream()
の返り値は Readable にそのまま入れられる、でいいのだろうか。
@@ -164,7 +164,7 @@ export abstract class AbstractFileUploader implements FileUploader { | |||
throw new Error('Multipart upload not available for file upload type'); | |||
} | |||
|
|||
abstract uploadAttachment(readStream: ReadStream, attachment: IAttachmentDocument): Promise<void>; | |||
abstract uploadAttachment(readable: Readable, attachment: IAttachmentDocument): Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -121,11 +122,12 @@ class GcsFileUploader extends AbstractFileUploader { | |||
const filePath = getFilePathOnStorage(attachment); | |||
const contentHeaders = new ContentHeaders(attachment); | |||
|
|||
await myBucket.upload(readStream.path.toString(), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
元々 ReadStream の path を読み取ってアップロードしていましたが、Readable に変更すると path がないため、これができなくなります。
ここでは ReadStream はパスを渡すためだけのインターフェース化しており、stream としての役割を果たしていません。
stream を使ってアップロードする方法が公式サンプルにあったため、そちらを参考にし、Readable stream を使用するコードに修正しました。
https://github.com/googleapis/nodejs-storage/blob/main/samples/streamFileUpload.js
目的
s3/gcs 以外のファイルアップロード設定でも bulk export を可能にする
実装内容
task
https://redmine.weseek.co.jp/issues/158279