Commit 29a20ad7 by renmanyi

Merge branch 'feature/renmanyi/20260121/tx-upload' into 'master'

Feature/renmanyi/20260121/tx upload

See merge request !97
parents 0e333b1d 97c09c43
......@@ -137,7 +137,8 @@ module.exports = function (webpackEnv) {
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
// Stop compilation early in production
bail: isEnvProduction,
devtool: isEnvProduction ? (shouldUseSourceMap ? 'source-map' : false) : isEnvDevelopment && 'cheap-module-source-map',
devtool: false,
// devtool: isEnvProduction ? (shouldUseSourceMap ? 'source-map' : false) : isEnvDevelopment && 'cheap-module-source-map',
// These are the "entry points" to our application.
// This means they will be the "root" imports that are included in JS bundle.
entry: [
......
......@@ -21,7 +21,8 @@
"@types/underscore": "^1.10.22",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"ali-oss": "6.17.1",
"ali-oss": "^6.23.0",
"cos-js-sdk-v5": "^1.10.1",
"antd": "^4.16.3",
"array-move": "^3.0.1",
"axios": "^0.20.0",
......
/*
* @Author: 吴文洁
* @Date: 2020-08-31 09:34:51
* @LastEditors: wufan
* @LastEditTime: 2021-01-06 20:18:46
* @LastEditors: renmanyi
* @LastEditTime: 2026-02-03 15:29:54
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -34,10 +34,7 @@ class Service {
static get(url: string, params: any, option?: any) {
return Axios.post('GET', url, params, option);
}
static MFS(url: string, params: any, option: any) {
return Axios.post('POST', `mfs/${url}`, params, option);
}
}
export default Service;
\ No newline at end of file
import { func } from "prop-types";
import Service from '@/common/js/service';
import User from '@/common/js/user';
import { message } from 'antd';
/*
* @Author: 吴文洁
* @Date: 2020-08-11 11:47:14
* @LastEditors: wufan
* @LastEditTime: 2021-01-03 21:04:30
* @LastEditors: renmanyi
* @LastEditTime: 2026-02-03 15:28:25
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -22,73 +21,29 @@ class Upload {
return Service.Hades('public/hades/commonOssAuthority', param).then((res) => {
const signInfo = res.result;
const { fileUrl } = res.result
return this.uploadBlobToNewOSS(Blob, name, dir, signInfo.signatureVO || signInfo).then(() => {
console.log('url2222222',fileUrl);
return dataType === 'url' ? fileUrl : signInfo
});
if (signInfo.vendorType === 'TENCENT_COS') {
return this.uploadBlobToNewOSSTx(Blob, name, signInfo.signatureVO || signInfo).then(() => {
return dataType === 'url' ? fileUrl : signInfo
})
} else {
return this.uploadBlobToNewOSS(
Blob,
name,
signInfo.signatureVO || signInfo
).then(() => {
return dataType === 'url' ? fileUrl : signInfo
});
}
})
};
static asyncUploadVideoToOSS(Blob, name, complete, dir, needSize) {
name = window.encodeURI(name.toLowerCase());
let ossSignServerAddress = UPLOAD + 'xm/oss/web/token?bucket=v';
const xhr = new XMLHttpRequest();
xhr.open('GET', ossSignServerAddress, true);
xhr.onload = () => {
const signInfo = JSON.parse(xhr.responseText);
const fd = new FormData();
fd.append('Filename', name);
fd.append('callback', signInfo.callback);
fd.append('expire', signInfo.expire);
fd.append('policy', signInfo.policy);
fd.append('signature', signInfo.signature);
fd.append('OSSAccessKeyId', signInfo.accessid);
fd.append('success_action_status', 200);
if (!dir) {
dir = Blob.type == 'text/html' ? 'html/' : '';
}
fd.append('key', signInfo.dir + dir + name);
fd.append('file', Blob);
xhr.open('POST', signInfo.host, true);
xhr.onload = () => {
const result = JSON.parse(xhr.responseText);
if (needSize) {
complete(result);
} else {
complete((result.url || false).replace(/http:/, "https:"));
}
};
xhr.send(fd);
};
xhr.onerror = () => {
complete(false);
}
xhr.send(null);
return xhr;
}
static getVideoParseRoute(videoUrl) {
return Service.MFS('anon/video/parse', { videoUrl }).then((res) => {
return Service.Sales('anon/resource/parseVideo', { videoUrl }).then((res) => {
return res.result.sdUrl || videoUrl;
})
}
// mfs上传文件
static uploadBlobToMFSOSS(signInfoUrl, signInfoParams, Blob, name, dir) {
return Service.post(signInfoUrl, signInfoParams).then(res => {
var signInfo = res.result;
return this.uploadBlobToNewOSS(Blob, name, dir, signInfo.signatureVO || signInfo).then((res) => {
return signInfo;
});
})
}
static uploadBlobToNewOSS(Blob, name, dir, signInfo) {
static uploadBlobToNewOSS(Blob, name, signInfo) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
var fd = new FormData();
......@@ -102,6 +57,9 @@ class Upload {
// dir = Blob.type == 'text/html' ? 'html/' : '';
// }
fd.append('key', signInfo.key);
if(signInfo.securityToken) {
fd.append("x-oss-security-token", signInfo.securityToken);
}
fd.append('file', Blob);
fd.append('success_action_status', 200);
xhr.open('POST', signInfo.host.replace(/http:/, "https:"), true);
......@@ -119,33 +77,36 @@ class Upload {
};
// 监听多媒体上传进度
static uploadToOSSEvent(Blob, name, onInit=()=>{}, onProgress=()=>{}, onLoad=()=>{}, onError=()=>{}) {
Service.MFS('anon/mfs/webTokenWithAccessUrl', { resourceName: name, instId: (!!window.currentUserInstInfo && window.currentUserInstInfo.instId) || LS.get('instId') || '' }).then((res) => {
const signInfo = res.result;
const { url } = res.result;
const xhr = new XMLHttpRequest();
const fd = new FormData();
fd.append('OSSAccessKeyId', signInfo.accessId);
static uploadBlobToNewOSSTx(Blob, name, signInfo={}) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
var fd = new FormData();
let timeVal = JSON.parse(signInfo.extAttrs)['q-key-time'];
fd.append('q-sign-algorithm', 'sha1');
fd.append('key', signInfo.key);
fd.append('q-ak', signInfo.accessKeyId);
fd.append('policy', signInfo.policy);
fd.append('callback', signInfo.callback);
fd.append('q-signature', signInfo.signature);
fd.append('success_action_status', '200');
fd.append('x-cos-callback', signInfo.callback);
signInfo.securityToken && fd.append("x-cos-security-token", signInfo.securityToken);
fd.append('q-key-time', timeVal);
fd.append('Filename', name);
fd.append('expire', signInfo.expire);
fd.append('signature', signInfo.signature);
fd.append('key', signInfo.key);
fd.append('file', Blob);
fd.append('success_action_status', 200);
onInit(url,xhr,signInfo)
xhr.open('POST', signInfo.host);
xhr.upload.addEventListener("progress", onProgress, false);
xhr.onload = onLoad;
xhr.onerror = onError;
xhr.open('POST', signInfo.host, true);
xhr.onload = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
const res = JSON.parse(xhr.responseText);
resolve(res.result.url);
} else {
console.error('Error: ' + xhr.status);
}
}
};
xhr.send(fd);
})
}
});
};
static uploadTextToOSS(string, name, success, error) {
if (!string) return success();
......@@ -156,25 +117,42 @@ class Upload {
resourceName: name,
}
Service.Hades('/public/hades/ossAuthority', params).then((res) => {
const { resourceId, accessId, policy, callback, signature,key, host } = res.result;
const xhr = new XMLHttpRequest();
const formData = new FormData();
formData.append("OSSAccessKeyId", accessId);
formData.append("policy", policy);
formData.append("callback", callback);
formData.append("Signature", signature);
formData.append("key", key);
formData.append("file", new Blob([string]));
formData.append("success_action_status", 200);
xhr.open("POST", host);
xhr.onload = () => {
success(resourceId);
};
xhr.onerror = () => {
error();
const signInfo = res.result;
const { resourceId } = res.result;
if (signInfo.vendorType === 'TENCENT_COS') {
// 腾讯云 COS 上传
this.uploadBlobToNewOSSTx(new Blob([string]), name, signInfo.signatureVO || signInfo).then(() => {
success(resourceId);
}).catch(() => {
error();
});
} else {
// 阿里云 OSS 上传
const { accessId, policy, callback, signature, key, host } = signInfo;
const xhr = new XMLHttpRequest();
const formData = new FormData();
formData.append("OSSAccessKeyId", accessId);
formData.append("policy", policy);
formData.append("callback", callback);
formData.append("Signature", signature);
formData.append("key", key);
if(signInfo.securityToken) {
formData.append("x-oss-security-token", signInfo.securityToken);
}
formData.append("file", new Blob([string]));
formData.append("success_action_status", 200);
xhr.open("POST", host);
xhr.onload = () => {
success(resourceId);
};
xhr.onerror = () => {
error();
}
xhr.send(formData);
}
xhr.send(formData);
})
}).catch(() => {
error();
});
}
}
......
/*
* @Author: wufan
* @Date: 2020-12-01 17:21:21
* @LastEditors: Please set LastEditors
* @LastEditTime: 2021-07-09 15:33:33
* @LastEditors: renmanyi
* @LastEditTime: 2026-02-03 15:38:02
* @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
......@@ -72,11 +72,12 @@ export const getOssClient = (
resourceName: string,
accessTypeEnum: string
) => {
return Service.postJSON('mfs/anon/mfs/multiPartUpload', {
return Service.postJSON('business/public/mfs/commonUpload', {
data,
instId,
bizCode,
resourceName,
needSecret: true,
accessTypeEnum
});
}
......
/*
* @Author: 吴文洁
* @Date: 2020-10-10 18:21:47
* @LastEditors: wufan
* @LastEditTime: 2020-12-09 16:05:24
* @LastEditors: renmanyi
* @LastEditTime: 2026-02-03 15:38:06
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -15,11 +15,12 @@ export const getOssClient = (
resourceName: string,
accessTypeEnum: string
) => {
return Service.postJSON('mfs/anon/mfs/multiPartUpload', {
return Service.postJSON('business/public/mfs/commonUpload', {
data,
instId,
bizCode,
resourceName,
needSecret: true,
accessTypeEnum
});
}
\ No newline at end of file
/*
* @Author: 吴文洁
* @Date: 2020-10-10 18:19:34
* @LastEditors: 吴文洁
* @LastEditTime: 2020-10-13 18:09:39
* @LastEditors: renmanyi
* @LastEditTime: 2026-02-03 15:39:33
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
import OSS from 'ali-oss';
import COS from 'cos-js-sdk-v5';
import { UPLOAD_REGION } from '@/domains/resource-disk/constants';
import { getOssClient } from '@/data-source/basic/basic-apis';
......@@ -31,32 +32,26 @@ export default class UploadFileService {
accessTypeEnum
).then((res) => {
const { result = {} } = res;
const {
bucket,
callBack,
resourceId,
accessKeyId,
securityToken,
accessKeySecret,
callbackBody,
ossUri
} = result;
const ossClient = new OSS({
bucket,
accessKeyId,
accessKeySecret,
region: UPLOAD_REGION,
stsToken: securityToken,
});
resolve({
ossClient,
resourceId,
callBack,
callbackBody,
ossUri
});
const { bucket, resourceId, accessKeyId, securityToken, accessKeySecret, key, vendorType, callbackData, callback } = result;
let client;
if (vendorType === 'TENCENT_COS') {
// 腾讯云配置
client = new COS({
SecretId: accessKeyId,
SecretKey: accessKeySecret,
SecurityToken: securityToken
});
} else {
// 阿里云配置
client = new OSS({
bucket,
accessKeyId,
accessKeySecret,
region: UPLOAD_REGION,
stsToken: securityToken
});
}
resolve({ ossClient: client, resourceId, ossUri:key, vendorType,bucket,callbackData,callback });
})
})
}
......
/*
* @Author: 吴文洁
* @Date: 2020-08-20 09:21:40
* @LastEditors: yuananting
* @LastEditTime: 2021-07-15 11:48:58
* @LastEditors: renmanyi
* @LastEditTime: 2026-02-03 15:45:43
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -172,6 +172,7 @@ const NON_COMPLIANT_FILE_MAP = {
// 文件上传
const UPLOAD_REGION = 'oss-cn-hangzhou';
const TX_UPLOAD_REGION = 'ap-shanghai';
const UPLOAD_PART_SIZE = 1024 * 1024; // 每个分片大小(byte)
const UPLOAD_PARALLEL = 5; // 同时上传的分片数
......@@ -185,6 +186,7 @@ export {
DISK_MAP,
SUFFIX_MAP,
UPLOAD_REGION,
TX_UPLOAD_REGION,
UPLOAD_PART_SIZE,
UPLOAD_PARALLEL,
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment