2024-10-14 23:48:31 +05:30
|
|
|
import { Client } from 'minio';
|
2024-10-15 19:16:48 +05:30
|
|
|
import Run from '../models/Run';
|
2024-10-14 23:48:31 +05:30
|
|
|
|
|
|
|
|
const minioClient = new Client({
|
|
|
|
|
endPoint: process.env.MINIO_ENDPOINT || 'localhost',
|
|
|
|
|
port: parseInt(process.env.MINIO_PORT || '9000'),
|
|
|
|
|
useSSL: false,
|
|
|
|
|
accessKey: process.env.MINIO_ACCESS_KEY || 'minio-access-key',
|
|
|
|
|
secretKey: process.env.MINIO_SECRET_KEY || 'minio-secret-key',
|
|
|
|
|
});
|
2024-10-14 23:51:15 +05:30
|
|
|
|
2024-10-15 22:47:19 +05:30
|
|
|
minioClient.bucketExists('maxun-test')
|
|
|
|
|
.then((exists) => {
|
|
|
|
|
if (exists) {
|
|
|
|
|
console.log('MinIO was connected successfully.');
|
|
|
|
|
} else {
|
|
|
|
|
console.log('Bucket does not exist, but MinIO was connected.');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.error('Error connecting to MinIO:', err);
|
|
|
|
|
})
|
|
|
|
|
|
2024-10-15 19:16:48 +05:30
|
|
|
class BinaryOutputService {
|
|
|
|
|
private bucketName: string;
|
|
|
|
|
|
|
|
|
|
constructor(bucketName: string) {
|
|
|
|
|
this.bucketName = bucketName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Uploads binary data to Minio and stores references in PostgreSQL.
|
|
|
|
|
* @param run - The run object representing the current process.
|
|
|
|
|
* @param binaryOutput - The binary output object containing data to upload.
|
|
|
|
|
* @returns A map of Minio URLs pointing to the uploaded binary data.
|
|
|
|
|
*/
|
|
|
|
|
async uploadAndStoreBinaryOutput(run: Run, binaryOutput: Record<string, any>): Promise<Record<string, string>> {
|
|
|
|
|
const uploadedBinaryOutput: Record<string, string> = {};
|
|
|
|
|
|
|
|
|
|
for (const key of Object.keys(binaryOutput)) {
|
|
|
|
|
const binaryData = binaryOutput[key];
|
2024-10-15 19:17:54 +05:30
|
|
|
const bufferData = Buffer.from(binaryData, 'binary');
|
2024-10-15 19:16:48 +05:30
|
|
|
const minioKey = `${run.runId}/${key}`;
|
|
|
|
|
|
|
|
|
|
await run.uploadBinaryOutputToMinioBucket(minioKey, bufferData);
|
|
|
|
|
|
|
|
|
|
// Save the Minio URL in the result object
|
|
|
|
|
uploadedBinaryOutput[key] = `minio://${this.bucketName}/${minioKey}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the run with the Minio URLs for binary output
|
|
|
|
|
await run.update({
|
|
|
|
|
binaryOutput: uploadedBinaryOutput
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return uploadedBinaryOutput;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-15 19:17:54 +05:30
|
|
|
export { minioClient, BinaryOutputService };
|