diff --git a/src/datastore/pic-bed.js b/src/datastore/pic-bed.js
index 7762fe9..9f6ca5f 100644
--- a/src/datastore/pic-bed.js
+++ b/src/datastore/pic-bed.js
@@ -1,35 +1,46 @@
import db from './index'
-let picBed = db.read().get('picBed.list').value()
+let picBed = [
+ {
+ type: 'weibo',
+ name: '微博图床',
+ visible: true
+ },
+ {
+ type: 'qiniu',
+ name: '七牛图床',
+ visible: true
+ },
+ {
+ type: 'tcyun',
+ name: '腾讯云COS',
+ visible: true
+ },
+ {
+ type: 'upyun',
+ name: '又拍云图床',
+ visible: true
+ },
+ {
+ type: 'github',
+ name: 'GitHub图床',
+ visible: true
+ },
+ {
+ type: 'smms',
+ name: 'SM.MS图床',
+ visible: true
+ }
+]
-if (!picBed) {
- picBed = [
- {
- type: 'weibo',
- name: '微博图床',
- visible: true
- },
- {
- type: 'qiniu',
- name: '七牛图床',
- visible: true
- },
- {
- type: 'tcyun',
- name: '腾讯云COS',
- visible: true
- },
- {
- type: 'upyun',
- name: '又拍云图床',
- visible: true
- },
- {
- type: 'github',
- name: 'GitHub图床',
- 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
diff --git a/src/main/utils/smmsUpload.js b/src/main/utils/smmsUpload.js
new file mode 100644
index 0000000..ec362c8
--- /dev/null
+++ b/src/main/utils/smmsUpload.js
@@ -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
diff --git a/src/main/utils/uploader.js b/src/main/utils/uploader.js
index d182a46..ed6f361 100644
--- a/src/main/utils/uploader.js
+++ b/src/main/utils/uploader.js
@@ -3,6 +3,7 @@ import qiniuUpload from './qiniuUpload'
import tcYunUpload from './tcYunUpload'
import upYunUpload from './upYunUpload'
import githubUpload from './githubUpload'
+import smmsUpload from './smmsUpload'
import db from '../../datastore/index'
import { Notification } from 'electron'
@@ -34,6 +35,8 @@ const uploader = (img, type, webContents) => {
return upYunUpload(img, type, webContents)
case 'github':
return githubUpload(img, type, webContents)
+ case 'smms':
+ return smmsUpload(img, type, webContents)
}
} else {
return false
diff --git a/src/renderer/components/SettingPage.vue b/src/renderer/components/SettingPage.vue
index 1dc1289..ca8ddb0 100644
--- a/src/renderer/components/SettingPage.vue
+++ b/src/renderer/components/SettingPage.vue
@@ -38,7 +38,7 @@
:index="item.type"
:key="item.type"
>
-
+
{{ item.name }}
diff --git a/src/renderer/components/SettingView/SMMS.vue b/src/renderer/components/SettingView/SMMS.vue
new file mode 100644
index 0000000..7a331fa
--- /dev/null
+++ b/src/renderer/components/SettingView/SMMS.vue
@@ -0,0 +1,43 @@
+
+
+
+
+
+ SM.MS设置
+
+
+ 设为默认图床
+
+
+
+
+
+
+
diff --git a/src/renderer/router/index.js b/src/renderer/router/index.js
index f92eb58..d700acf 100644
--- a/src/renderer/router/index.js
+++ b/src/renderer/router/index.js
@@ -50,6 +50,11 @@ export default new Router({
component: require('@/components/SettingView/GitHub').default,
name: 'github'
},
+ {
+ path: 'smms',
+ component: require('@/components/SettingView/SMMS').default,
+ name: 'smms'
+ },
{
path: 'gallery',
component: require('@/components/SettingView/Gallery').default,