nest-qiniu-oss
Version:
nest 七牛云 oss 插件
70 lines (69 loc) • 2.77 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); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QiniuOSSService = void 0;
const common_1 = require("@nestjs/common");
const qiniu = require("qiniu");
const constants_1 = require("../constants");
let QiniuOSSService = class QiniuOSSService {
constructor(qiniuOSSOptions) {
this.qiniuOSSOptions = qiniuOSSOptions;
}
get engine() {
return qiniu;
}
get options() {
return this.qiniuOSSOptions;
}
createRegionsProvider(regionId, options) {
const region = qiniu.httpc.Region.fromRegionId(regionId || this.options.region, options);
return {
getRegions: async () => [region]
};
}
createConfig(config) {
return new this.engine.conf.Config({
zone: this.options.zone,
regionsProvider: this.createRegionsProvider(),
...config
});
}
mac() {
return new this.engine.auth.digest.Mac(this.options.accessKey, this.options.secretKey, this.options.macOptions);
}
createPutPolicy(options) {
return new this.engine.rs.PutPolicy({
scope: this.options.bucket,
...options
});
}
createUploadToken(options) {
return this.createPutPolicy(options).uploadToken(this.mac());
}
createBucketManager(config) {
return new this.engine.rs.BucketManager(this.mac(), {
...this.createConfig(),
...config
});
}
createCdnManager(mac) {
return new this.engine.cdn.CdnManager(mac || this.mac());
}
};
exports.QiniuOSSService = QiniuOSSService;
exports.QiniuOSSService = QiniuOSSService = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, common_1.Inject)(constants_1.QINIU_OSS_MODULE_OPTIONS)),
__metadata("design:paramtypes", [Object])
], QiniuOSSService);
;