fix: upload images (#101)

This commit is contained in:
Yang Libin 2021-11-25 22:08:58 +08:00 committed by GitHub
parent 650ceb439f
commit 9af9319d39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,12 +91,12 @@ async function ghFileUpload(content, filename) {
message: `Upload by ${window.location.href}`, message: `Upload by ${window.location.href}`,
}, },
}); });
const githubResourceUrl = `raw.githubusercontent.com/${username}/${repo}/${branch}/`; const githubResourceUrl = `raw.githubusercontent.com/${username}/${repo}/${branch}/`;
const cdnResourceUrl = `cdn.jsdelivr.net/gh/${username}/${repo}@${branch}/`; const cdnResourceUrl = `cdn.jsdelivr.net/gh/${username}/${repo}@${branch}/`;
res.content = res.data?.content || res.content;
return useDefault return useDefault
? res.data.content.download_url.replace(githubResourceUrl, cdnResourceUrl) ? res.content.download_url.replace(githubResourceUrl, cdnResourceUrl)
: res.data.content.download_url; : res.content.download_url;
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -122,7 +122,8 @@ async function giteeUpload(content, filename) {
message: `Upload by ${window.location.href}`, message: `Upload by ${window.location.href}`,
}, },
}); });
return encodeURI(res.data.content.download_url); res.content = res.data?.content || res.content;
return encodeURI(res.content.download_url);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -235,7 +236,7 @@ async function formCustomUpload(content, file) {
async (CUSTOM_ARG) => { async (CUSTOM_ARG) => {
${localStorage.getItem(`formCustomConfig`)} ${localStorage.getItem(`formCustomConfig`)}
} }
` `;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const exportObj = { const exportObj = {
content, // 待上传图片的 base64 content, // 待上传图片的 base64
@ -254,11 +255,11 @@ async function formCustomUpload(content, file) {
}, },
okCb: resolve, // 重要: 上传成功后给此回调传 url 即可 okCb: resolve, // 重要: 上传成功后给此回调传 url 即可
errCb: reject, // 上传失败调用的函数 errCb: reject, // 上传失败调用的函数
} };
eval(str)(exportObj).catch(err => { eval(str)(exportObj).catch((err) => {
console.error(err) console.error(err);
reject(err) reject(err);
}) });
}); });
} }