From b6d5c1c0f258298a97a41810336b43c8fc04a4f0 Mon Sep 17 00:00:00 2001 From: zhx Date: Thu, 25 Jun 2026 20:26:35 +0800 Subject: [PATCH] fix: upload assets through backend --- .env.development | 5 ++--- .env.prod-atyou | 4 ++-- .env.production | 4 ++-- .env.staging | 4 ++-- mock/banner.js | 2 +- mock/props.js | 2 +- package.json | 1 - src/api/oss.js | 43 +++++++++++++++++-------------------------- 项目说明.md | 4 ++-- 9 files changed, 29 insertions(+), 40 deletions(-) diff --git a/.env.development b/.env.development index 4eb91fe..52590e9 100644 --- a/.env.development +++ b/.env.development @@ -10,12 +10,11 @@ VUE_APP_BASE_URL ='https://console.atuchat.com' # VUE_APP_BASE_URL = 'https://console.azizichat.com' # oss -VUE_APP_OSS_BUCKET = 'tkm-likei' -VUE_APP_OSS_URL = 'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com' +VUE_APP_OSS_BUCKET = 'asset-global-interaction-1420526837' +VUE_APP_OSS_URL = 'https://asset.global-interaction.com' # h5 VUE_APP_H5_BASE_URL = 'https://h5.azizichat.com' # start mock VUE_APP_START_MOCK = false - diff --git a/.env.prod-atyou b/.env.prod-atyou index eb2b461..4945607 100644 --- a/.env.prod-atyou +++ b/.env.prod-atyou @@ -10,8 +10,8 @@ VUE_CLI_BABEL_TRANSPILE_MODULES = true VUE_APP_BASE_URL ='https://console.atuchat.com' # oss -VUE_APP_OSS_BUCKET = 'tkm-likei' -VUE_APP_OSS_URL = 'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com' +VUE_APP_OSS_BUCKET = 'asset-global-interaction-1420526837' +VUE_APP_OSS_URL = 'https://asset.global-interaction.com' # h5 VUE_APP_H5_BASE_URL = 'https://h5.azizichat.com' diff --git a/.env.production b/.env.production index 468d196..fdb7722 100644 --- a/.env.production +++ b/.env.production @@ -8,8 +8,8 @@ VUE_APP_BASE_API = '/console' VUE_APP_BASE_URL = 'https://console.azizichat.com' # oss -VUE_APP_OSS_BUCKET = 'tkm-likei' -VUE_APP_OSS_URL = 'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com' +VUE_APP_OSS_BUCKET = 'asset-global-interaction-1420526837' +VUE_APP_OSS_URL = 'https://asset.global-interaction.com' # h5 VUE_APP_H5_BASE_URL = 'https://h5.azizichat.com' diff --git a/.env.staging b/.env.staging index f47904f..b9368de 100644 --- a/.env.staging +++ b/.env.staging @@ -9,8 +9,8 @@ VUE_APP_BASE_API = '/console' VUE_APP_BASE_URL = 'https://console.azizichat.com' # oss -VUE_APP_OSS_BUCKET = 'tkm-likei' -VUE_APP_OSS_URL = 'https://tkm-likei.oss-ap-southeast-1.aliyuncs.com' +VUE_APP_OSS_BUCKET = 'asset-global-interaction-1420526837' +VUE_APP_OSS_URL = 'https://asset.global-interaction.com' # h5 VUE_APP_H5_BASE_URL = 'https://h5.azizichat.com' diff --git a/mock/banner.js b/mock/banner.js index f72877f..94c9336 100644 --- a/mock/banner.js +++ b/mock/banner.js @@ -16,7 +16,7 @@ export default [ 'updateUser': '23', 'id': '1354012611532255233', 'link': 'ddd', - 'cover': 'http://sugartime-dev.oss-accelerate.aliyuncs.com/manager-e22186b3-e630-4451-8816-daeecf6377b2.jpg', + 'cover': 'https://asset.global-interaction.com/mock/manager-e22186b3-e630-4451-8816-daeecf6377b2.jpg', 'showcase': true, 'expiredTime': '2021-01-11 02:03:02', 'depict': 'dee' diff --git a/mock/props.js b/mock/props.js index 547bde4..459bb31 100644 --- a/mock/props.js +++ b/mock/props.js @@ -17,7 +17,7 @@ export default [ 'userId': '1351021829418778626', 'propsId': '1351727566616408065', 'propsCandy': 50.00, - 'propsPhoto': 'http://sugartime-dev.oss-accelerate.aliyuncs.com/manager-80db3c54-4164-4f9b-a1d3-28ae96525c64.jpg', + 'propsPhoto': 'https://asset.global-interaction.com/mock/manager-80db3c54-4164-4f9b-a1d3-28ae96525c64.jpg', 'propsName': 'yy', 'typeName': '头像框', 'userBaseInfo': { diff --git a/package.json b/package.json index fab5eb3..dc84ba4 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ }, "dependencies": { "@lucky-canvas/vue": "0.0.5", - "ali-oss": "^6.12.0", "axios": "0.18.1", "codemirror": "5.45.0", "current-device": "0.10.2", diff --git a/src/api/oss.js b/src/api/oss.js index 0b7007f..4bc2af6 100644 --- a/src/api/oss.js +++ b/src/api/oss.js @@ -1,5 +1,3 @@ - -import OSS from 'ali-oss' import request from '@/utils/request' import { uuid } from '@/utils' @@ -18,6 +16,9 @@ const getAccessImgUrl = (key) => { if (!key) { return '' } + if (/^https?:\/\//i.test(key)) { + return key + } if (key.startsWith('/')) { return `${process.env.VUE_APP_OSS_URL}${key}` } @@ -30,32 +31,22 @@ const getAccessImgUrl = (key) => { */ const simpleUploadFlie = (fileObj, dir) => { return new Promise((resolve, reject) => { + const filename = fileObj.customFilename || radmonFilename(fileObj.file.name) + const key = `${dir || 'other'}/${filename}` + const formData = new FormData() + formData.append('file', fileObj.file) + formData.append('key', key) request({ - url: '/ali-yun/oss/sts', - method: 'get' + url: '/ali-yun/oss/upload', + method: 'post', + data: formData }).then(res => { - const stsResult = res.body - if (stsResult) { - const client = new OSS({ - endpoint: 'oss-accelerate.aliyuncs.com', - accessKeyId: stsResult['AccessKeyId'], - accessKeySecret: stsResult['AccessKeySecret'], - stsToken: stsResult['SecurityToken'], - bucket: process.env.VUE_APP_OSS_BUCKET - }) - try { - const filename = fileObj.customFilename || radmonFilename(fileObj.file.name) - client.put(`${dir || 'other'}/${filename}`, fileObj.file).then(ossRes => { - resolve(ossRes) - }).catch(er => { - console.error('error:', er) - reject(er) - }) - } catch (er) { - console.error('error:', er) - reject(er) - } - } + const body = res.body || {} + resolve({ + name: body.name || key, + url: body.url || getAccessImgUrl(body.name || key), + res: body.res || { status: 200 } + }) }).catch(er => { console.error(er) reject(er) diff --git a/项目说明.md b/项目说明.md index 21be8e2..b8bb2e9 100644 --- a/项目说明.md +++ b/项目说明.md @@ -28,7 +28,7 @@ | **国际化** | 自研 i18n 插件(基于时区自动检测语言) | | **样式** | SCSS + normalize.css,支持暗色主题切换 | | **富媒体** | Video.js 8、SVGA Player、libpag(PAG 动效) | -| **文件存储** | 阿里云 OSS(ali-oss SDK) | +| **文件存储** | 腾讯云 COS(通过后端接口上传) | | **WebSocket** | SockJS + StompJS(实时消息) | | **Mock** | Mock.js(开发环境可选启用) | | **代码规范** | ESLint(babel-eslint)+ EditorConfig | @@ -222,7 +222,7 @@ meta: { ## 十、OSS 文件上传 -阿里云 OSS,Bucket 分类: +腾讯云 COS,目录分类: | Bucket Key | 用途 | |------------|------|