import { assert } from 'oak-domain/lib/utils/assert'; import { LocalSDK } from 'oak-external-sdk'; import Local from './local'; export default class LocalBackend extends Local { getConfigAndInstance(application) { const { config, account } = this.getConfig(application); const instance = 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; } assert(bucket2); const b = buckets.find((ele) => ele.name === bucket2); assert(b, `${bucket2}不是一个有效的桶配置`); Object.assign(extraFile, { bucket: bucket2, uploadMeta: instance.getUploadInfo(bucket2, key), }); } async checkWhetherSuccess(application, extraFile) { return true; } async removeFile(application, extraFile) { } } ;