oak-general-business/lib/utils/cos/local.backend.js

87 lines
3.2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const assert_1 = require("oak-domain/lib/utils/assert");
const oak_external_sdk_1 = require("oak-external-sdk");
const local_1 = tslib_1.__importDefault(require("./local"));
const types_1 = require("oak-domain/lib/types");
class LocalBackend extends local_1.default {
getConfigAndInstance(application) {
const { config, account } = this.getConfig(application);
const instance = oak_external_sdk_1.LocalSDK.getInstance(account.accessKey, account.secretKey);
return {
config,
instance,
};
}
async composeFileUrlBackend(options) {
const { application, extraFile, context, style } = options;
const { config: localConfig } = this.getConfig(application);
let bucket = localConfig.buckets.find((ele) => ele.name === extraFile.bucket);
if (bucket) {
const { domain, protocol, nginxPath } = bucket;
let protocol2 = protocol;
if (protocol instanceof Array) {
// protocol存在https: 说明域名有证书
const index = protocol.includes('https:')
? protocol.findIndex((ele) => ele === 'https:')
: 0;
protocol2 = protocol[index];
}
return `${protocol2}//${domain}${nginxPath ? '/' + nginxPath : ''}/${this.formKey(extraFile)}${style ? style : ''}`;
}
return '';
}
async formUploadMeta(application, extraFile) {
const { bucket } = extraFile;
// 构造文件上传所需的key
const key = this.formKey(extraFile);
const { instance, config: localCosConfig } = this.getConfigAndInstance(application);
const { buckets } = localCosConfig;
let bucket2 = bucket;
if (!bucket2) {
const { defaultBucket } = localCosConfig;
bucket2 = defaultBucket;
}
(0, assert_1.assert)(bucket2);
const b = buckets.find((ele) => ele.name === bucket2);
(0, assert_1.assert)(b, `${bucket2}不是一个有效的桶配置`);
Object.assign(extraFile, {
bucket: bucket2,
uploadMeta: instance.getUploadInfo(bucket2, key),
});
}
async checkWhetherSuccess(application, extraFile) {
return true;
}
async removeFile(application, extraFile) {
}
async composeChunkUploadInfo(application, extraFile, context) {
throw new types_1.OakPreConditionUnsetException('本地存储暂不支持分片上传');
return {
uploadId: '',
chunkSize: 0,
partCount: 0,
partSize: 0,
parts: [],
};
}
/**
* 完成分片上传后的合并操作
*/
async mergeChunkedUpload(application, extraFile, context) {
// Implementation here
}
async abortMultipartUpload(application, extraFile, context) {
const key = this.formKey(extraFile);
const { instance, config: aliyunCosConfig } = this.getConfigAndInstance(application);
}
async listMultipartUploads(application, extraFile, context) {
return {
parts: [],
};
}
}
exports.default = LocalBackend;
;