From 04fbf17c3a35bc46f8b1b14f921ffc4a81b8e171 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 16 Oct 2024 13:40:26 +0530 Subject: [PATCH] feat: move all upload logic to BinaryOutputService --- server/src/storage/mino.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/src/storage/mino.ts b/server/src/storage/mino.ts index 849060b8..e8ddd6f3 100644 --- a/server/src/storage/mino.ts +++ b/server/src/storage/mino.ts @@ -74,7 +74,7 @@ class BinaryOutputService { try { const minioKey = `${plainRun.runId}/${key}`; - await run.uploadBinaryOutputToMinioBucket(minioKey, binaryData); + await this.uploadBinaryOutputToMinioBucket(run, minioKey, binaryData); // Save the Minio URL in the result object uploadedBinaryOutput[key] = `minio://${this.bucketName}/${minioKey}`; @@ -94,6 +94,20 @@ class BinaryOutputService { return uploadedBinaryOutput; } + + async uploadBinaryOutputToMinioBucket(run: Run, key: string, data: Buffer): Promise { + const bucketName = 'maxun-run-screenshots'; + try { + console.log(`Uploading to bucket ${bucketName} with key ${key}`); + await minioClient.putObject(bucketName, key, data, data.length, { 'Content-Type': 'image/png' }); + const plainRun = run.toJSON(); + plainRun.binaryOutput[key] = `minio://${bucketName}/${key}`; + console.log(`Successfully uploaded to MinIO: minio://${bucketName}/${key}`); + } catch (error) { + console.error(`Error uploading to MinIO bucket: ${bucketName} with key: ${key}`, error); + throw error; + } + } } export { minioClient, BinaryOutputService }; \ No newline at end of file