From 95ee21f27913a863b16b2b69fe86e14551acccfc Mon Sep 17 00:00:00 2001 From: sugar Date: Fri, 12 Apr 2024 22:38:56 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B5=8B=E8=AF=95=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=85=BC=E5=AE=B9upyun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/utils/upyun.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/client/src/utils/upyun.ts b/packages/client/src/utils/upyun.ts index 5389afc..2cb3ea3 100644 --- a/packages/client/src/utils/upyun.ts +++ b/packages/client/src/utils/upyun.ts @@ -5,6 +5,7 @@ import type { UPYunConfig } from '@/store/modules/configStore' export async function uploadFile(file: File, ops: UPYunConfig) { const { bucket, prefix, scope, token, date, uriPrefix, domain } = ops + const service = new upyun.Service(bucket) const client = new upyun.Client(service, () => ({ 'Authorization': token, @@ -13,6 +14,10 @@ export async function uploadFile(file: File, ops: UPYunConfig) { 'X-Upyun-Expire': date, })) const key = await generateNewFileKey(file, prefix, scope) + // 测试逻辑 + if (import.meta.env.VITE_APP_FAKE_UPLOAD) { + return Promise.resolve(`${domain}/${key}`) + } const isSuccess = await client.putFile(key, file) return isSuccess ? Promise.resolve(`${domain}/${key}`) : Promise.reject(new Error('上传失败')) }