mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
Added: smms picbed
This commit is contained in:
parent
1b8400a458
commit
ffbbc74734
@ -1,9 +1,6 @@
|
|||||||
import db from './index'
|
import db from './index'
|
||||||
|
|
||||||
let picBed = db.read().get('picBed.list').value()
|
let picBed = [
|
||||||
|
|
||||||
if (!picBed) {
|
|
||||||
picBed = [
|
|
||||||
{
|
{
|
||||||
type: 'weibo',
|
type: 'weibo',
|
||||||
name: '微博图床',
|
name: '微博图床',
|
||||||
@ -28,8 +25,22 @@ if (!picBed) {
|
|||||||
type: 'github',
|
type: 'github',
|
||||||
name: 'GitHub图床',
|
name: 'GitHub图床',
|
||||||
visible: true
|
visible: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'smms',
|
||||||
|
name: 'SM.MS图床',
|
||||||
|
visible: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
let picBedFromDB = db.read().get('picBed.list').value() || []
|
||||||
|
let oldLength = picBedFromDB.length
|
||||||
|
let newLength = picBed.length
|
||||||
|
|
||||||
|
if (oldLength !== newLength) {
|
||||||
|
for (let i = oldLength; i < newLength; i++) {
|
||||||
|
picBedFromDB.push(picBed[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default picBed
|
export default picBedFromDB
|
||||||
|
47
src/main/utils/smmsUpload.js
Normal file
47
src/main/utils/smmsUpload.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import request from 'request-promise'
|
||||||
|
import * as img2Base64 from './img2base64'
|
||||||
|
import { Notification } from 'electron'
|
||||||
|
|
||||||
|
const postOptions = (fileName, imgBase64) => {
|
||||||
|
return {
|
||||||
|
method: 'POST',
|
||||||
|
url: `https://sm.ms/api/upload`,
|
||||||
|
formData: {
|
||||||
|
smfile: Buffer.from(imgBase64, 'base64'),
|
||||||
|
filename: fileName,
|
||||||
|
ssl: true
|
||||||
|
},
|
||||||
|
json: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const smmsUpload = async function (img, type, webContents) {
|
||||||
|
try {
|
||||||
|
webContents.send('uploadProgress', 0)
|
||||||
|
const imgList = await img2Base64[type](img)
|
||||||
|
webContents.send('uploadProgress', 30)
|
||||||
|
for (let i in imgList) {
|
||||||
|
const postConfig = postOptions(imgList[i].fileName, imgList[i].base64Image)
|
||||||
|
const body = await request(postConfig)
|
||||||
|
if (body) {
|
||||||
|
delete imgList[i].base64Image
|
||||||
|
imgList[i]['imgUrl'] = body.data.url
|
||||||
|
} else {
|
||||||
|
webContents.send('uploadProgress', -1)
|
||||||
|
return new Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
webContents.send('uploadProgress', 100)
|
||||||
|
return imgList
|
||||||
|
} catch (err) {
|
||||||
|
webContents.send('uploadProgress', -1)
|
||||||
|
const notification = new Notification({
|
||||||
|
title: '上传失败!',
|
||||||
|
body: '服务端出错,请重试'
|
||||||
|
})
|
||||||
|
notification.show()
|
||||||
|
throw new Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default smmsUpload
|
@ -3,6 +3,7 @@ import qiniuUpload from './qiniuUpload'
|
|||||||
import tcYunUpload from './tcYunUpload'
|
import tcYunUpload from './tcYunUpload'
|
||||||
import upYunUpload from './upYunUpload'
|
import upYunUpload from './upYunUpload'
|
||||||
import githubUpload from './githubUpload'
|
import githubUpload from './githubUpload'
|
||||||
|
import smmsUpload from './smmsUpload'
|
||||||
import db from '../../datastore/index'
|
import db from '../../datastore/index'
|
||||||
import { Notification } from 'electron'
|
import { Notification } from 'electron'
|
||||||
|
|
||||||
@ -34,6 +35,8 @@ const uploader = (img, type, webContents) => {
|
|||||||
return upYunUpload(img, type, webContents)
|
return upYunUpload(img, type, webContents)
|
||||||
case 'github':
|
case 'github':
|
||||||
return githubUpload(img, type, webContents)
|
return githubUpload(img, type, webContents)
|
||||||
|
case 'smms':
|
||||||
|
return smmsUpload(img, type, webContents)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
:index="item.type"
|
:index="item.type"
|
||||||
:key="item.type"
|
:key="item.type"
|
||||||
>
|
>
|
||||||
<i :class="`el-icon-ui-${item.type}`"></i>
|
<!-- <i :class="`el-icon-ui-${item.type}`"></i> -->
|
||||||
<span slot="title">{{ item.name }}</span>
|
<span slot="title">{{ item.name }}</span>
|
||||||
</el-menu-item>
|
</el-menu-item>
|
||||||
</template>
|
</template>
|
||||||
|
43
src/renderer/components/SettingView/SMMS.vue
Normal file
43
src/renderer/components/SettingView/SMMS.vue
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<template>
|
||||||
|
<div id="smms-view">
|
||||||
|
<el-row :gutter="16">
|
||||||
|
<el-col :span="16" :offset="4">
|
||||||
|
<div class="view-title">
|
||||||
|
SM.MS设置
|
||||||
|
</div>
|
||||||
|
<div style="text-align: center; margin-top: 20px;">
|
||||||
|
<el-button type="success" @click="confirm" round :disabled="defaultPicBed === 'smms'" size="mini">设为默认图床</el-button>
|
||||||
|
</div>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import mixin from '../mixin'
|
||||||
|
export default {
|
||||||
|
name: 'upyun',
|
||||||
|
mixins: [mixin],
|
||||||
|
data () {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
confirm () {
|
||||||
|
this.$db.set('picBed.smms', this.form).write()
|
||||||
|
this.setDefaultPicBed('smms')
|
||||||
|
const successNotification = new window.Notification('设置结果', {
|
||||||
|
body: '设置成功'
|
||||||
|
})
|
||||||
|
successNotification.onclick = () => {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang='stylus'>
|
||||||
|
.view-title
|
||||||
|
color #eee
|
||||||
|
font-size 20px
|
||||||
|
text-align center
|
||||||
|
margin 20px auto
|
||||||
|
</style>
|
@ -50,6 +50,11 @@ export default new Router({
|
|||||||
component: require('@/components/SettingView/GitHub').default,
|
component: require('@/components/SettingView/GitHub').default,
|
||||||
name: 'github'
|
name: 'github'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'smms',
|
||||||
|
component: require('@/components/SettingView/SMMS').default,
|
||||||
|
name: 'smms'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'gallery',
|
path: 'gallery',
|
||||||
component: require('@/components/SettingView/Gallery').default,
|
component: require('@/components/SettingView/Gallery').default,
|
||||||
|
Loading…
Reference in New Issue
Block a user