feat: move all upload logic to BinaryOutputService

This commit is contained in:
karishmas6
2024-10-16 13:40:26 +05:30
parent a75d40918b
commit 04fbf17c3a

View File

@@ -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<void> {
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 };