diff --git a/src/main/utils/upYunUpload.js b/src/main/utils/upYunUpload.js index 2c52b95..1f9ebf0 100644 --- a/src/main/utils/upYunUpload.js +++ b/src/main/utils/upYunUpload.js @@ -8,12 +8,12 @@ import MD5 from 'md5' // generate COS signature string const generateSignature = (fileName) => { const options = db.read().get('picBed.upyun').value() - // const apiKey = options.apiKey + const path = options.path || '' const operator = options.operator const password = options.password const md5Password = MD5(password) const date = new Date().toGMTString() - const uri = `/${options.bucket}/${encodeURI(fileName)}` + const uri = `/${options.bucket}/${path}${encodeURI(fileName)}` const value = `PUT&${uri}&${date}` const sign = crypto.createHmac('sha1', md5Password).update(value).digest('base64') return `UPYUN ${operator}:${sign}` @@ -22,9 +22,10 @@ const generateSignature = (fileName) => { const postOptions = (fileName, signature, imgBase64) => { const options = db.read().get('picBed.upyun').value() const bucket = options.bucket + const path = options.path || '' return { method: 'PUT', - url: `https://v0.api.upyun.com/${bucket}/${encodeURI(fileName)}`, + url: `https://v0.api.upyun.com/${bucket}/${path}${encodeURI(fileName)}`, headers: { Authorization: signature, Date: new Date().toGMTString() @@ -41,24 +42,21 @@ const upYunUpload = async (img, type, webContents) => { webContents.send('uploadProgress', 30) const length = imgList.length const upyunOptions = db.read().get('picBed.upyun').value() + const path = upyunOptions.path || '' for (let i in imgList) { const singature = generateSignature(imgList[i].fileName) const options = postOptions(imgList[i].fileName, singature, imgList[i].base64Image) const body = await request(options) if (body.statusCode === 200) { delete imgList[i].base64Image - imgList[i]['imgUrl'] = `${upyunOptions.url}/${imgList[i].fileName}${upyunOptions.options}` + imgList[i]['imgUrl'] = `${upyunOptions.url}/${path}${imgList[i].fileName}${upyunOptions.options}` imgList[i]['type'] = 'upyun' if (i - length === -1) { webContents.send('uploadProgress', 60) } } else { webContents.send('uploadProgress', -1) - const notification = new Notification({ - title: '上传失败!', - body: '服务端出错,请稍后再试' - }) - notification.show() + return new Error() } } webContents.send('uploadProgress', 100) diff --git a/src/main/utils/weiboUpload.js b/src/main/utils/weiboUpload.js index a919a77..1c6f3c6 100644 --- a/src/main/utils/weiboUpload.js +++ b/src/main/utils/weiboUpload.js @@ -83,6 +83,7 @@ const weiboUpload = async function (img, type, webContents) { body: res.body.msg }) notification.show() + return new Error() } } catch (err) { webContents.send('uploadProgress', -1) diff --git a/src/renderer/components/SettingView/UpYun.vue b/src/renderer/components/SettingView/UpYun.vue index 69cd686..dd40e57 100644 --- a/src/renderer/components/SettingView/UpYun.vue +++ b/src/renderer/components/SettingView/UpYun.vue @@ -48,6 +48,11 @@ > + + + 确定 @@ -70,7 +75,8 @@ export default { bucket: '', operator: '', password: '', - options: '' + options: '', + path: '' } } },