From ccfc40139059b7186174d0c339a088de58a2ee03 Mon Sep 17 00:00:00 2001 From: Kane <150378@qq.com> Date: Tue, 12 Dec 2023 16:23:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91OSS=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=85=AC=E7=BD=91=E8=AE=BF=E9=97=AE=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file/src/file.ts | 16 +++++++++++++--- file/src/interface.ts | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/file/src/file.ts b/file/src/file.ts index 2911d4f..13f531e 100644 --- a/file/src/file.ts +++ b/file/src/file.ts @@ -78,7 +78,13 @@ export class CoolFile { this.client = new QINIU.auth.digest.Mac(accessKeyId, accessKeySecret); } if (aws) { - const { accessKeyId, secretAccessKey, region, publicDomain, forcePathStyle } = aws; + const { + accessKeyId, + secretAccessKey, + region, + publicDomain, + forcePathStyle, + } = aws; this.client = new S3Client({ region, credentials: { accessKeyId, secretAccessKey }, @@ -173,7 +179,8 @@ export class CoolFile { if (isCloud) { if (oss) { const ossClient: OSS = this.getMetaFileObj(); - return (await ossClient.put(name, data)).url; + const { url } = await ossClient.put(name, data); + return oss.publicDomain ? `${oss.publicDomain}/${name}` : url; } if (cos) { const cosClient: COS = this.getMetaFileObj(); @@ -244,7 +251,8 @@ export class CoolFile { if (mode == MODETYPE.CLOUD) { if (oss) { const ossClient: OSS = this.getMetaFileObj(); - return (await ossClient.put(key, data)).url; + const { url } = await ossClient.put(key, data); + return oss.publicDomain ? `${oss.publicDomain}/${key}` : url; } if (cos) { const cosClient: COS = this.getMetaFileObj(); @@ -391,6 +399,7 @@ export class CoolFile { expAfter = 300000, maxSize = 200 * 1024 * 1024, host, + publicDomain, } = this.config.oss; const oss = { bucket, @@ -420,6 +429,7 @@ export class CoolFile { signature, policy, host: newHost, + publicDomain, OSSAccessKeyId: accessKeyId, success_action_status: 200, }; diff --git a/file/src/interface.ts b/file/src/interface.ts index 70e8178..eaedc56 100644 --- a/file/src/interface.ts +++ b/file/src/interface.ts @@ -67,6 +67,8 @@ export interface OSSConfig { maxSize?: number; // host host?: string; + // 阿里云oss的公网访问地址 + publicDomain: string; } /**