DTP Base provides a scalable and secure Node.js application development harness ready for production service.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
1.7 KiB

// minio.js
// Copyright (C) 2024 DTP Technologies, LLC
// All Rights Reserved
'use strict';
import * as Minio from 'minio';
import { SiteService } from '../../lib/site-lib.js';
export default class MinioService extends SiteService {
static get name ( ) { return 'MinioService'; }
static get slug ( ) { return 'minio'; }
constructor (dtp) {
super(dtp, MinioService);
}
async start ( ) {
await super.start();
this.minio = new Minio.Client({
endPoint: process.env.MINIO_ENDPOINT,
port: parseInt(process.env.MINIO_PORT, 10),
useSSL: (process.env.MINIO_USE_SSL === 'enabled'),
accessKey: process.env.MINIO_ACCESS_KEY,
secretKey: process.env.MINIO_SECRET_KEY,
});
}
async uploadFile (fileInfo) {
const result = await this.minio.fPutObject(
fileInfo.bucket,
fileInfo.key,
fileInfo.filePath,
fileInfo.metadata
);
return result;
}
async downloadFile (fileInfo) {
const obj = await this.minio.fGetObject(fileInfo.bucket, fileInfo.key, fileInfo.filePath);
return obj;
}
async openDownloadStream (fi) {
if (fi.range) {
const length = fi.range.end - fi.range.start + 1;
const stream = await this.minio.getPartialObject(fi.bucket, fi.key, fi.range.start, length);
return stream;
}
const stream = await this.minio.getObject(fi.bucket, fi.key);
return stream;
}
async removeObject (bucket, key) {
await this.minio.removeObject(bucket, key);
}
async statObject (bucket, key) {
const stat = await this.minio.statObject(bucket, key);
return stat;
}
async statFile (file) {
return await this.statObject(file.bucket, file.key);
}
}