oss兼容
continuous-integration/drone/push Build is passing Details

main
wangxiaoshuang 2024-06-04 11:00:54 +08:00
parent 304ab2bf62
commit 656ebeb3e9
3 changed files with 30 additions and 10 deletions

View File

@ -103,12 +103,14 @@ Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.handleTree = handleTree
Vue.prototype.$getObjectName = (url) => {
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;
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;
}
return value.split(basePath)[1];
}
Vue.prototype.getGuid = (text) => {
text = md5(text)

View File

@ -19,6 +19,7 @@ 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
switch (res.Result.ObjectStoreUse) {
case 'AliyunOSS':
@ -39,7 +40,7 @@ async function ossGenerateSTS() {
if (res && res.url) {
resolve({
name: objectName,
url: Vue.prototype.OSSclientConfig.viewEndpoint + objectName
url: res.url
})
} else {
reject()
@ -77,7 +78,7 @@ async function ossGenerateSTS() {
} else {
resolve({
name: objectName,
url: Vue.prototype.OSSclientConfig.viewEndpoint + objectName
url: Vue.prototype.OSSclientConfig.viewEndpoint + decodeUtf8(objectName)
})
}
})
@ -94,6 +95,14 @@ 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

@ -977,7 +977,15 @@ const PDFViewerApplication = {
await Promise.all(promises);
},
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+'?'+str.join("?");
},
async open(file, args) {
if (this.pdfLoadingTask) {
await this.close();
@ -992,6 +1000,7 @@ const PDFViewerApplication = {
const parameters = Object.create(null);
if (typeof file === "string") {
file = this.decodeUtf8(file);
this.setTitleUsingUrl(file, file);
parameters.url = file;
} else if (file && "byteLength" in file) {