first commit
This commit is contained in:
commit
c809bb3893
40 files changed
+3836
No files matched your search
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
import * as Minio from 'minio';
|
||||
import { secrets } from './secret-manager.js';
|
||||
import { Readable } from 'stream';
|
||||
export class MinioClient {
|
||||
client;
|
||||
bucketName = 'wiki-server';
|
||||
constructor() {
|
||||
const endpoint = secrets?.['MINIO_ENDPOINT'];
|
||||
const accessKey = secrets?.['MINIO_ACCESS_KEY'];
|
||||
const secretKey = secrets?.['MINIO_SECRET_KEY'];
|
||||
if (!endpoint || !accessKey || !secretKey) {
|
||||
throw new Error('Missing MinIO credentials in secrets');
|
||||
}
|
||||
this.client = new Minio.Client({
|
||||
endPoint: endpoint,
|
||||
port: 443,
|
||||
useSSL: true,
|
||||
accessKey: accessKey,
|
||||
secretKey: secretKey,
|
||||
});
|
||||
}
|
||||
async downloadFile(s3ObjectKey) {
|
||||
const stream = await this.client.getObject(this.bucketName, s3ObjectKey);
|
||||
return new Promise((resolve, reject) => {
|
||||
const chunks = [];
|
||||
stream.on('data', (chunk) => chunks.push(chunk));
|
||||
stream.on('end', () => resolve(Buffer.concat(chunks)));
|
||||
stream.on('error', reject);
|
||||
});
|
||||
}
|
||||
async uploadFile(s3ObjectKey, buffer, contentType) {
|
||||
const metaData = {
|
||||
'Content-Type': contentType,
|
||||
'X-Amz-Meta-serviceName': 'image-derivaties-generation',
|
||||
};
|
||||
await this.client.putObject(this.bucketName, s3ObjectKey, buffer, buffer.length, metaData);
|
||||
}
|
||||
async fileExists(s3ObjectKey) {
|
||||
try {
|
||||
await this.client.statObject(this.bucketName, s3ObjectKey);
|
||||
return true;
|
||||
}
|
||||
catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=minio.js.map
|
||||
Reference in new issue
Block a user