Skip to content

Commit

Permalink
chore: 测试逻辑兼容upyun
Browse files Browse the repository at this point in the history
  • Loading branch information
ATQQ committed Apr 12, 2024
1 parent b0dab4c commit 95ee21f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/client/src/utils/upyun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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('上传失败'))
}

0 comments on commit 95ee21f

Please sign in to comment.