oss兼容aws
parent
31a2b6c6fb
commit
cf4b6887da
24
src/main.js
24
src/main.js
|
@ -96,24 +96,14 @@ Vue.prototype.selectDictLabel = selectDictLabel
|
||||||
// Vue.prototype.download = download
|
// Vue.prototype.download = download
|
||||||
Vue.prototype.handleTree = handleTree
|
Vue.prototype.handleTree = handleTree
|
||||||
Vue.prototype.$getObjectName = (url) => {
|
Vue.prototype.$getObjectName = (url) => {
|
||||||
// console.log(Vue.prototype.)
|
// console.log(url,'url')
|
||||||
// console.log(url)
|
// console.log(Vue.prototype.OSSclientConfig.viewEndpoint,'url')
|
||||||
var value = 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)
|
|
||||||
let basePath = Vue.prototype.OSSclientConfig.viewEndpoint;
|
let basePath = Vue.prototype.OSSclientConfig.viewEndpoint;
|
||||||
let basePathHttp = Vue.prototype.OSSclientConfig.viewEndpoint.replace("https", 'http')
|
if (Vue.prototype.OSSclientConfig.ObjectStoreUse === 'AliyunOSS') {
|
||||||
let arr = value.split(basePath);
|
basePath = Vue.prototype.OSSclientConfig.endPoint.split('https://').length > 1 ? Vue.prototype.OSSclientConfig.endPoint.split('https://')[1] : Vue.prototype.OSSclientConfig.endPoint;
|
||||||
let name = null;
|
|
||||||
if (arr.length > 1) {
|
|
||||||
name = arr[1];
|
|
||||||
} else {
|
|
||||||
name = value.split(basePathHttp)[1];
|
|
||||||
}
|
}
|
||||||
// console.log(name)
|
return value.split(basePath)[1];
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
Vue.prototype.getGuid = (text) => {
|
Vue.prototype.getGuid = (text) => {
|
||||||
text = md5(text)
|
text = md5(text)
|
||||||
|
@ -355,7 +345,7 @@ async function VueInit() {
|
||||||
_vm.$store.dispatch('user/logout').then(res => {
|
_vm.$store.dispatch('user/logout').then(res => {
|
||||||
// window.location.href = `/login`
|
// window.location.href = `/login`
|
||||||
router.push("/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!', {
|
_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',
|
type: 'warning',
|
||||||
})
|
})
|
||||||
|
|
|
@ -20,8 +20,8 @@ function blobToBuffer(blob, fileName) {
|
||||||
async function ossGenerateSTS() {
|
async function ossGenerateSTS() {
|
||||||
let res = await GetObjectStoreToken()
|
let res = await GetObjectStoreToken()
|
||||||
Vue.prototype.OSSclientConfig = { ...res.Result[res.Result.ObjectStoreUse] }
|
Vue.prototype.OSSclientConfig = { ...res.Result[res.Result.ObjectStoreUse] }
|
||||||
|
Vue.prototype.OSSclientConfig.ObjectStoreUse = res.Result.ObjectStoreUse;
|
||||||
Vue.prototype.OSSclientConfig.basePath = Vue.prototype.OSSclientConfig.viewEndpoint
|
Vue.prototype.OSSclientConfig.basePath = Vue.prototype.OSSclientConfig.viewEndpoint
|
||||||
console.log(Vue.prototype.OSSclientConfig.basePath)
|
|
||||||
switch (res.Result.ObjectStoreUse) {
|
switch (res.Result.ObjectStoreUse) {
|
||||||
case 'AliyunOSS':
|
case 'AliyunOSS':
|
||||||
Vue.prototype.OSSclientConfig.bucket = Vue.prototype.OSSclientConfig.bucketName
|
Vue.prototype.OSSclientConfig.bucket = Vue.prototype.OSSclientConfig.bucketName
|
||||||
|
@ -71,14 +71,14 @@ async function ossGenerateSTS() {
|
||||||
reader.onload = (ex) => {
|
reader.onload = (ex) => {
|
||||||
const bufferStream = new stream.PassThrough()
|
const bufferStream = new stream.PassThrough()
|
||||||
bufferStream.end(Buffer.from(ex.target.result))
|
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) {
|
if (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
reject()
|
reject()
|
||||||
} else {
|
} else {
|
||||||
resolve({
|
resolve({
|
||||||
name: objectName,
|
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) => {
|
reader.onload = (ex) => {
|
||||||
const bufferStream = new stream.PassThrough()
|
const bufferStream = new stream.PassThrough()
|
||||||
bufferStream.end(Buffer.from(ex.target.result))
|
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) {
|
if (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
reject()
|
reject()
|
||||||
} else {
|
} else {
|
||||||
|
console.log(objectName);
|
||||||
resolve({
|
resolve({
|
||||||
name: objectName,
|
name: objectName,
|
||||||
url: 'http://www.abc.com' + objectName
|
url: Vue.prototype.OSSclientConfig.viewEndpoint + decodeUtf8(objectName)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -130,7 +131,15 @@ async function ossGenerateSTS() {
|
||||||
}
|
}
|
||||||
return
|
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
|
export const OSSclient = ossGenerateSTS
|
||||||
|
|
|
@ -6,7 +6,6 @@ const CopyPlugin = require('copy-webpack-plugin')
|
||||||
const WebpackAliyunOss = require('webpack-aliyun-oss')
|
const WebpackAliyunOss = require('webpack-aliyun-oss')
|
||||||
const moment = require('moment')
|
const moment = require('moment')
|
||||||
var distDate = moment(new Date()).format('YYYY-MM-DD')
|
var distDate = moment(new Date()).format('YYYY-MM-DD')
|
||||||
console.log(distDate)
|
|
||||||
function resolve(dir) {
|
function resolve(dir) {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
return path.join(__dirname, dir)
|
return path.join(__dirname, dir)
|
||||||
|
@ -36,7 +35,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
'/UploadHub': {
|
'/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:8001', // 国内生产环境
|
||||||
// target: 'http://123.56.181.144:8060/api', // 国内测试环境1
|
// target: 'http://123.56.181.144:8060/api', // 国内测试环境1
|
||||||
// target: 'http://123.56.181.144:8000/api', // 国内测试环境
|
// target: 'http://123.56.181.144:8000/api', // 国内测试环境
|
||||||
|
@ -57,15 +56,15 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'/api': {
|
'/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:8001', // 国内生产环境
|
||||||
// target: 'http://123.56.181.144:8060/api', // 国内测试环境1
|
// target: 'http://123.56.181.144:8060/api', // 国内测试环境1
|
||||||
// target: 'http://123.56.181.144:8000/api', // 国内测试环境
|
// target: 'http://123.56.181.144:8000/api', // 国内测试环境
|
||||||
// target: 'http://123.56.94.154:8079', // 国内测试环境2
|
// target: 'http://123.56.94.154:8079', // 国内测试环境2
|
||||||
// target: 'http://123.56.94.154:7000', // 国内测试环境2
|
// target: 'http://123.56.94.154:7000', // 国内测试环境2
|
||||||
// target: 'http://123.56.94.154:30668',
|
// target: 'http://123.56.94.154:30668',
|
||||||
target: 'http://106.14.89.110:30000',
|
// target: 'http://106.14.89.110:30000',
|
||||||
// target: 'http://123.56.181.144:7000',
|
target: 'http://123.56.181.144:7000',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false,
|
secure: false,
|
||||||
pathRewrite: {
|
pathRewrite: {
|
||||||
|
|
Loading…
Reference in New Issue