diff --git a/src/assets/scripts/uploadImageFile.js b/src/assets/scripts/uploadImageFile.js index af73b74..023cac8 100644 --- a/src/assets/scripts/uploadImageFile.js +++ b/src/assets/scripts/uploadImageFile.js @@ -3,27 +3,24 @@ const githubResourceUrl = 'raw.githubusercontent.com/filess/images/master/'; const cdnResourceUrl = 'cdn.jsdelivr.net/gh/filess/images/'; export function uploadImgFile(file) { - - return new Promise((resolve, reject)=> { - const checkImageResult = isImageIllegal(file); + return new Promise((resolve, reject) => { + const checkImageResult = isImageIllegal(file); if (checkImageResult) { reject(checkImageResult); - } else { - const imgFile = new FileReader(); - imgFile.readAsDataURL(file); - - imgFile.onload = function() { - const base64Content = this.result.split(',').pop(); - fileApi.fileUpload(base64Content, file.name).then(res=> { - const imageUrl = res.content.download_url.replace(githubResourceUrl, cdnResourceUrl) - - resolve(imageUrl); - }).catch(err => { - console.log(err.message) - }) - } + return; + } + const imgFile = new FileReader(); + imgFile.readAsDataURL(file); + imgFile.onload = function () { + const base64Content = this.result.split(',').pop(); + fileApi.fileUpload(base64Content, file.name).then(res => { + const imageUrl = res.content.download_url.replace(githubResourceUrl, cdnResourceUrl); + resolve(imageUrl); + }).catch(err => { + console.log(err.message) + }) } }); } @@ -36,4 +33,4 @@ export function isImageIllegal(file) { return '由于公众号限制,图片大小不能超过 5.0M'; } return false; -} \ No newline at end of file +}