mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
Added: upYun path option
This commit is contained in:
parent
4010a09fe4
commit
25068a8949
@ -8,12 +8,12 @@ import MD5 from 'md5'
|
|||||||
// generate COS signature string
|
// generate COS signature string
|
||||||
const generateSignature = (fileName) => {
|
const generateSignature = (fileName) => {
|
||||||
const options = db.read().get('picBed.upyun').value()
|
const options = db.read().get('picBed.upyun').value()
|
||||||
// const apiKey = options.apiKey
|
const path = options.path || ''
|
||||||
const operator = options.operator
|
const operator = options.operator
|
||||||
const password = options.password
|
const password = options.password
|
||||||
const md5Password = MD5(password)
|
const md5Password = MD5(password)
|
||||||
const date = new Date().toGMTString()
|
const date = new Date().toGMTString()
|
||||||
const uri = `/${options.bucket}/${encodeURI(fileName)}`
|
const uri = `/${options.bucket}/${path}${encodeURI(fileName)}`
|
||||||
const value = `PUT&${uri}&${date}`
|
const value = `PUT&${uri}&${date}`
|
||||||
const sign = crypto.createHmac('sha1', md5Password).update(value).digest('base64')
|
const sign = crypto.createHmac('sha1', md5Password).update(value).digest('base64')
|
||||||
return `UPYUN ${operator}:${sign}`
|
return `UPYUN ${operator}:${sign}`
|
||||||
@ -22,9 +22,10 @@ const generateSignature = (fileName) => {
|
|||||||
const postOptions = (fileName, signature, imgBase64) => {
|
const postOptions = (fileName, signature, imgBase64) => {
|
||||||
const options = db.read().get('picBed.upyun').value()
|
const options = db.read().get('picBed.upyun').value()
|
||||||
const bucket = options.bucket
|
const bucket = options.bucket
|
||||||
|
const path = options.path || ''
|
||||||
return {
|
return {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
url: `https://v0.api.upyun.com/${bucket}/${encodeURI(fileName)}`,
|
url: `https://v0.api.upyun.com/${bucket}/${path}${encodeURI(fileName)}`,
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: signature,
|
Authorization: signature,
|
||||||
Date: new Date().toGMTString()
|
Date: new Date().toGMTString()
|
||||||
@ -41,24 +42,21 @@ const upYunUpload = async (img, type, webContents) => {
|
|||||||
webContents.send('uploadProgress', 30)
|
webContents.send('uploadProgress', 30)
|
||||||
const length = imgList.length
|
const length = imgList.length
|
||||||
const upyunOptions = db.read().get('picBed.upyun').value()
|
const upyunOptions = db.read().get('picBed.upyun').value()
|
||||||
|
const path = upyunOptions.path || ''
|
||||||
for (let i in imgList) {
|
for (let i in imgList) {
|
||||||
const singature = generateSignature(imgList[i].fileName)
|
const singature = generateSignature(imgList[i].fileName)
|
||||||
const options = postOptions(imgList[i].fileName, singature, imgList[i].base64Image)
|
const options = postOptions(imgList[i].fileName, singature, imgList[i].base64Image)
|
||||||
const body = await request(options)
|
const body = await request(options)
|
||||||
if (body.statusCode === 200) {
|
if (body.statusCode === 200) {
|
||||||
delete imgList[i].base64Image
|
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'
|
imgList[i]['type'] = 'upyun'
|
||||||
if (i - length === -1) {
|
if (i - length === -1) {
|
||||||
webContents.send('uploadProgress', 60)
|
webContents.send('uploadProgress', 60)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
webContents.send('uploadProgress', -1)
|
webContents.send('uploadProgress', -1)
|
||||||
const notification = new Notification({
|
return new Error()
|
||||||
title: '上传失败!',
|
|
||||||
body: '服务端出错,请稍后再试'
|
|
||||||
})
|
|
||||||
notification.show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
webContents.send('uploadProgress', 100)
|
webContents.send('uploadProgress', 100)
|
||||||
|
@ -83,6 +83,7 @@ const weiboUpload = async function (img, type, webContents) {
|
|||||||
body: res.body.msg
|
body: res.body.msg
|
||||||
})
|
})
|
||||||
notification.show()
|
notification.show()
|
||||||
|
return new Error()
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
webContents.send('uploadProgress', -1)
|
webContents.send('uploadProgress', -1)
|
||||||
|
@ -48,6 +48,11 @@
|
|||||||
>
|
>
|
||||||
<el-input v-model="form.options" @keyup.native.enter="confirm" placeholder="例如!imgslim"></el-input>
|
<el-input v-model="form.options" @keyup.native.enter="confirm" placeholder="例如!imgslim"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
label="指定存储路径"
|
||||||
|
>
|
||||||
|
<el-input v-model="form.path" @keyup.native.enter="confirm" placeholder="例如img/"></el-input>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button-group>
|
<el-button-group>
|
||||||
<el-button type="primary" @click="confirm" round>确定</el-button>
|
<el-button type="primary" @click="confirm" round>确定</el-button>
|
||||||
@ -70,7 +75,8 @@ export default {
|
|||||||
bucket: '',
|
bucket: '',
|
||||||
operator: '',
|
operator: '',
|
||||||
password: '',
|
password: '',
|
||||||
options: ''
|
options: '',
|
||||||
|
path: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user