nestjs-minio
Version:
Minio object storage with nestjs
50 lines (49 loc) • 2.45 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var NestMinioService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestMinioService = void 0;
const common_1 = require("@nestjs/common");
const minio = require("minio");
const nest_minio_module_definition_1 = require("./nest-minio.module-definition");
const rxjs_1 = require("rxjs");
let NestMinioService = NestMinioService_1 = class NestMinioService {
constructor(nestMinioOptions) {
this.nestMinioOptions = nestMinioOptions;
this.logger = new common_1.Logger(NestMinioService_1.name);
}
getMinio() {
if (!this._minioConnection) {
const { retries, ...options } = this.nestMinioOptions;
this._minioConnection = new minio.Client(options);
}
return this._minioConnection;
}
checkConnection() {
const { retries = 5, retryDelay = 1000 } = this.nestMinioOptions;
(0, rxjs_1.lastValueFrom)((0, rxjs_1.from)(this._minioConnection.listBuckets()).pipe((0, rxjs_1.retry)({ count: retries, delay: retryDelay })))
.then(() => {
this.logger.log("Successfully connected to minio.");
})
.catch(error => {
this.logger.error(error);
});
}
};
exports.NestMinioService = NestMinioService;
exports.NestMinioService = NestMinioService = NestMinioService_1 = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, common_1.Inject)(nest_minio_module_definition_1.MODULE_OPTIONS_TOKEN)),
__metadata("design:paramtypes", [Object])
], NestMinioService);
;