feat: 优化

This commit is contained in:
2026-03-02 01:28:46 +08:00
parent b2e5bb85f4
commit ce3d529f80
11 changed files with 88 additions and 33 deletions

View File

@@ -7,6 +7,7 @@ import { ref, reactive } from 'vue'
import { message } from 'ant-design-vue'
import { MaterialService } from '@/api/material'
import { useUserStore } from '@/stores/user'
import { OSS_ORIGINAL, isDev } from '@gold/config/api'
// GB转字节常量
const GB_TO_BYTES = 1073741824
@@ -106,11 +107,12 @@ export function useUpload() {
reject(new Error('网络错误,上传失败'))
})
// 发起PUT请求 - 使用代理路径
const uploadUrl = presignedData.presignedUrl.replace(
'https://muye-ai-chat.oss-cn-hangzhou.aliyuncs.com',
'/oss'
)
// 发起PUT请求
// 开发环境:使用 /oss 代理避免CORS问题
// 生产环境直接使用OSS原始域名需要OSS配置CORS
const uploadUrl = isDev()
? presignedData.presignedUrl.replace(OSS_ORIGINAL, '/oss')
: presignedData.presignedUrl
xhr.open('PUT', uploadUrl)
if (presignedData.headers && presignedData.headers['Content-Type']) {
xhr.setRequestHeader('Content-Type', presignedData.headers['Content-Type'])