oss兼容aws

uat_us
wangxiaoshuang 2024-06-04 10:52:53 +08:00
parent 31a2b6c6fb
commit cf4b6887da
3 changed files with 26 additions and 28 deletions

View File

@ -96,24 +96,14 @@ Vue.prototype.selectDictLabel = selectDictLabel
// Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.$getObjectName = (url) => {
// console.log(Vue.prototype.)
// console.log(url)
var value = url
// var str = value.split("//"); //https://进行分割,
// var index = str[1].indexOf("/")+1; //indexOf 获取第一个斜杠的索引,
// // console.log(str[1].substring(index)); //substring 截取,
// return '/' + str[1].substring(index)
// console.log(url,'url')
// console.log(Vue.prototype.OSSclientConfig.viewEndpoint,'url')
var value = url;
let basePath = Vue.prototype.OSSclientConfig.viewEndpoint;
let basePathHttp = Vue.prototype.OSSclientConfig.viewEndpoint.replace("https", 'http')
let arr = value.split(basePath);
let name = null;
if (arr.length > 1) {
name = arr[1];
} else {
name = value.split(basePathHttp)[1];
if (Vue.prototype.OSSclientConfig.ObjectStoreUse === 'AliyunOSS') {
basePath = Vue.prototype.OSSclientConfig.endPoint.split('https://').length > 1 ? Vue.prototype.OSSclientConfig.endPoint.split('https://')[1] : Vue.prototype.OSSclientConfig.endPoint;
}
// console.log(name)
return name;
return value.split(basePath)[1];
}
Vue.prototype.getGuid = (text) => {
text = md5(text)
@ -355,7 +345,7 @@ async function VueInit() {
_vm.$store.dispatch('user/logout').then(res => {
// window.location.href = `/login`
router.push("/login")
}).then(()=>{
}).then(() => {
_vm.$alert(lang === 'zh' ? '由于您长时间未操作,为保护您的数据安全已强制将您下线,如果需要继续操作请重新登陆!' : 'No operation for a long time non-operation, you have been forced logout to protect data security. If continue to operate, please login again!', {
type: 'warning',
})

View File

@ -20,8 +20,8 @@ function blobToBuffer(blob, fileName) {
async function ossGenerateSTS() {
let res = await GetObjectStoreToken()
Vue.prototype.OSSclientConfig = { ...res.Result[res.Result.ObjectStoreUse] }
Vue.prototype.OSSclientConfig.ObjectStoreUse = res.Result.ObjectStoreUse;
Vue.prototype.OSSclientConfig.basePath = Vue.prototype.OSSclientConfig.viewEndpoint
console.log(Vue.prototype.OSSclientConfig.basePath)
switch (res.Result.ObjectStoreUse) {
case 'AliyunOSS':
Vue.prototype.OSSclientConfig.bucket = Vue.prototype.OSSclientConfig.bucketName
@ -71,14 +71,14 @@ async function ossGenerateSTS() {
reader.onload = (ex) => {
const bufferStream = new stream.PassThrough()
bufferStream.end(Buffer.from(ex.target.result))
minioClient.putObject(Vue.prototype.OSSclientConfig.bucketName, objectName, bufferStream, function(err,etag) {
minioClient.putObject(Vue.prototype.OSSclientConfig.bucketName, objectName, bufferStream, function (err, etag) {
if (err) {
console.log(err)
reject()
} else {
resolve({
name: objectName,
url: 'http://www.abc.com' + objectName
url: Vue.prototype.OSSclientConfig.viewEndpoint + decodeUtf8(objectName)
})
}
})
@ -108,14 +108,15 @@ async function ossGenerateSTS() {
reader.onload = (ex) => {
const bufferStream = new stream.PassThrough()
bufferStream.end(Buffer.from(ex.target.result))
aws.putObject(Vue.prototype.OSSclientConfig.bucketName, objectName, bufferStream, function(err,etag) {
aws.putObject(Vue.prototype.OSSclientConfig.bucketName, objectName, bufferStream, function (err, etag) {
if (err) {
console.log(err)
reject()
} else {
console.log(objectName);
resolve({
name: objectName,
url: 'http://www.abc.com' + objectName
url: Vue.prototype.OSSclientConfig.viewEndpoint + decodeUtf8(objectName)
})
}
})
@ -130,7 +131,15 @@ async function ossGenerateSTS() {
}
return
}
function decodeUtf8(bytes) {
let str = bytes.split('?');
let str2 = str[0].split('/');
let name = str2[str2.length - 1];
name = encodeURIComponent(name);
str.shift();
str2.pop();
return str2.join("/") + '/' + name;
}
export const OSSclient = ossGenerateSTS

View File

@ -6,7 +6,6 @@ const CopyPlugin = require('copy-webpack-plugin')
const WebpackAliyunOss = require('webpack-aliyun-oss')
const moment = require('moment')
var distDate = moment(new Date()).format('YYYY-MM-DD')
console.log(distDate)
function resolve(dir) {
// eslint-disable-next-line no-undef
return path.join(__dirname, dir)
@ -36,7 +35,7 @@ module.exports = {
},
proxy: {
'/UploadHub': {
// target: 'http://47.90.210.20:8000', //美国服务器
// target: 'http://44.218.11.19:30000', //美国服务器
// target: 'http://123.56.181.144:8001', // 国内生产环境
// target: 'http://123.56.181.144:8060/api', // 国内测试环境1
// target: 'http://123.56.181.144:8000/api', // 国内测试环境
@ -57,15 +56,15 @@ module.exports = {
}
},
'/api': {
// target: 'http://47.90.210.20:8000', //美国服务器
// target: 'http://44.218.11.19:30000', //美国服务器
// target: 'http://123.56.181.144:8001', // 国内生产环境
// target: 'http://123.56.181.144:8060/api', // 国内测试环境1
// target: 'http://123.56.181.144:8000/api', // 国内测试环境
// target: 'http://123.56.94.154:8079', // 国内测试环境2
// target: 'http://123.56.94.154:7000', // 国内测试环境2
// target: 'http://123.56.94.154:30668',
target: 'http://106.14.89.110:30000',
// target: 'http://123.56.181.144:7000',
// target: 'http://106.14.89.110:30000',
target: 'http://123.56.181.144:7000',
changeOrigin: true,
secure: false,
pathRewrite: {