diff --git a/src/main/index.js b/src/main/index.js index 0548b2d..204c086 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -102,6 +102,15 @@ function createTray () { db.read().set('picBed.current', 'upyun') .write() } + }, + { + label: 'GitHub图床', + type: 'radio', + checked: db.read().get('picBed.current').value() === 'github', + click () { + db.read().set('picBed.current', 'github') + .write() + } } ] }, diff --git a/src/main/utils/githubUpload.js b/src/main/utils/githubUpload.js new file mode 100644 index 0000000..46f0046 --- /dev/null +++ b/src/main/utils/githubUpload.js @@ -0,0 +1,62 @@ +import request from 'request-promise' +import * as img2Base64 from './img2base64' +import db from '../../datastore/index' +import { Notification } from 'electron' + +const postOptions = (fileName, options, data) => { + const path = options.path || '' + const {token, repo} = options + return { + method: 'PUT', + url: `https://api.github.com/repos/${repo}/contents/${path}${encodeURI(fileName)}`, + headers: { + Authorization: `token ${token}`, + 'User-Agent': 'PicGo' + }, + body: data, + json: true + } +} + +const githubUpload = async function (img, type, webContents) { + try { + webContents.send('uploadProgress', 0) + const imgList = await img2Base64[type](img) + const length = imgList.length + const githubOptions = db.read().get('picBed.github').value() + webContents.send('uploadProgress', 30) + for (let i in imgList) { + const data = { + message: 'Upload by PicGo', + branch: githubOptions.branch, + content: imgList[i].base64Image, + path: githubOptions.path + encodeURI(imgList[i].fileName) + } + const postConfig = postOptions(imgList[i].fileName, githubOptions, data) + const body = await request(postConfig) + if (body) { + delete imgList[i].base64Image + imgList[i]['imgUrl'] = body.content.download_url + imgList[i]['type'] = 'github' + if (i - length === -1) { + webContents.send('uploadProgress', 60) + } + } 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 githubUpload diff --git a/src/main/utils/uploader.js b/src/main/utils/uploader.js index 1a26fa0..f136838 100644 --- a/src/main/utils/uploader.js +++ b/src/main/utils/uploader.js @@ -2,6 +2,7 @@ import weiboUpload from './weiboUpload' import qiniuUpload from './qiniuUpload' import tcYunUpload from './tcYunUpload' import upYunUpload from './upYunUpload' +import githubUpload from './githubUpload' import db from '../../datastore/index' const checkUploader = (type) => { @@ -25,6 +26,8 @@ const uploader = (img, type, webContents) => { return tcYunUpload(img, type, webContents) case 'upyun': return upYunUpload(img, type, webContents) + case 'github': + return githubUpload(img, type, webContents) } } else { return false diff --git a/src/renderer/assets/fonts/iconfont.css b/src/renderer/assets/fonts/iconfont.css index b8512ec..9746133 100644 --- a/src/renderer/assets/fonts/iconfont.css +++ b/src/renderer/assets/fonts/iconfont.css @@ -1,10 +1,10 @@ @font-face {font-family: "iconfont"; - src: url('iconfont.eot?t=1513753554908'); /* IE9*/ - src: url('iconfont.eot?t=1513753554908#iefix') format('embedded-opentype'), /* IE6-IE8 */ - url('data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAAmkAAsAAAAADaAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADMAAABCsP6z7U9TLzIAAAE8AAAARAAAAFZW7kg7Y21hcAAAAYAAAACAAAABzpdE03RnbHlmAAACAAAABYcAAAcM5PoEemhlYWQAAAeIAAAALwAAADYP352haGhlYQAAB7gAAAAcAAAAJAfeA4hobXR4AAAH1AAAABMAAAAcG+kAAGxvY2EAAAfoAAAAEAAAABAFmgdAbWF4cAAAB/gAAAAfAAAAIAEXAMxuYW1lAAAIGAAAAUUAAAJtPlT+fXBvc3QAAAlgAAAAQgAAAFQeKhOyeJxjYGRgYOBikGPQYWB0cfMJYeBgYGGAAJAMY05meiJQDMoDyrGAaQ4gZoOIAgCKIwNPAHicY2Bk/ss4gYGVgYOpk+kMAwNDP4RmfM1gxMjBwMDEwMrMgBUEpLmmMDgwVDzzYW7438AQw9zA0AAUZgTJAQAqnwy9eJzFkdENhSAMRU9BzQsxLqAjvDHepwM4xvsyTNw1tKX8OIGXHNJeSkooMALZ+BoDyIng+psrzc+U5g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B4nGWPTU7DMBCFX/oHpBKqqGCH5AViASj9EatuWFRq911036ZOmyqJI8et1ANwHo7ACTgC3IA78EgnmzaWx9+8eWNPANzgBx6O3y33kT1cMjtyDRe4F65TfxBukF+Em2jjVbhF/U3YxzOmwm10YXmD17hi9oR3YQ8dfAjXcI1P4Tr1L+EG+Vu4iTv8CrfQ8erCPuZeV7iNRy/2x1YvnF6p5UHFockikzm/gple75KFrdLqnGtbxCZTg6BfSVOdaVvdU+zXQ+ciFVmTqgmrOkmMyq3Z6tAFG+fyUa8XiR6EJuVYY/62xgKOcQWFJQ6MMUIYZIjK6Og7VWb0r7FDwl57Vj3N53RbFNT/c4UBAvTPXFO6stJ5Ok+BPV8bUnV0K27LnpQ0kV7NSRKyQl7WtlRC6gE2ZVeOEXpc0Yk/KGdI/wAJWm7IAAAAeJxjYGKAAC4G7ICdkYmRmZGFkZWRjZGdkYOBsYK1PDUzKZ+1JLmyNI+ttCAnPzGFtTAzL7OUtbQAKMTAAADg/QwGAAA=') format('woff'), - url('iconfont.ttf?t=1513753554908') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/ - url('iconfont.svg?t=1513753554908#iconfont') format('svg'); /* iOS 4.1- */ + src: url('iconfont.eot?t=1523001890286'); /* IE9*/ + src: url('iconfont.eot?t=1523001890286#iefix') format('embedded-opentype'), /* IE6-IE8 */ + url('data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAApcAAsAAAAADqAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADMAAABCsP6z7U9TLzIAAAE8AAAARAAAAFZW7kmaY21hcAAAAYAAAACMAAAB5Jz6bNVnbHlmAAACDAAABisAAAfkf7GmJ2hlYWQAAAg4AAAALwAAADYQ+dpBaGhlYQAACGgAAAAcAAAAJAfeA4lobXR4AAAIhAAAABQAAAAgH+kAAGxvY2EAAAiYAAAAEgAAABII+gbebWF4cAAACKwAAAAfAAAAIAEYAMxuYW1lAAAIzAAAAUUAA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a') format('woff'), + url('iconfont.ttf?t=1523001890286') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/ + url('iconfont.svg?t=1523001890286#iconfont') format('svg'); /* iOS 4.1- */ } [class*=" el-icon-ui"], [class^=el-icon-ui] { @@ -15,6 +15,8 @@ -moz-osx-font-smoothing: grayscale; } +.el-icon-ui-github:before { content: "\e7ab"; } + .el-icon-ui-weibo:before { content: "\e61c"; } .el-icon-ui-tcyun:before { content: "\e64c"; } diff --git a/src/renderer/assets/fonts/iconfont.eot b/src/renderer/assets/fonts/iconfont.eot index 1523bca..f29f338 100644 Binary files a/src/renderer/assets/fonts/iconfont.eot and b/src/renderer/assets/fonts/iconfont.eot differ diff --git a/src/renderer/assets/fonts/iconfont.svg b/src/renderer/assets/fonts/iconfont.svg index ca5c855..d1ae62e 100644 --- a/src/renderer/assets/fonts/iconfont.svg +++ b/src/renderer/assets/fonts/iconfont.svg @@ -27,6 +27,9 @@ t9.5 -10.5t21.5 -4h37h67h81h80h64h36q23 0 34 12t2 38q-5 13 -9.5 30.5t-9.5 34.5q- + + + diff --git a/src/renderer/assets/fonts/iconfont.ttf b/src/renderer/assets/fonts/iconfont.ttf index efa9c77..78d7302 100644 Binary files a/src/renderer/assets/fonts/iconfont.ttf and b/src/renderer/assets/fonts/iconfont.ttf differ diff --git a/src/renderer/assets/fonts/iconfont.woff b/src/renderer/assets/fonts/iconfont.woff index d01359e..186ca41 100644 Binary files a/src/renderer/assets/fonts/iconfont.woff and b/src/renderer/assets/fonts/iconfont.woff differ diff --git a/src/renderer/components/SettingPage.vue b/src/renderer/components/SettingPage.vue index 1693e27..a7c0997 100644 --- a/src/renderer/components/SettingPage.vue +++ b/src/renderer/components/SettingPage.vue @@ -38,6 +38,10 @@ 又拍云设置 + + + GitHub设置 + diff --git a/src/renderer/components/SettingView/GitHub.vue b/src/renderer/components/SettingView/GitHub.vue new file mode 100644 index 0000000..402e0f3 --- /dev/null +++ b/src/renderer/components/SettingView/GitHub.vue @@ -0,0 +1,124 @@ + + + diff --git a/src/renderer/router/index.js b/src/renderer/router/index.js index 90fac1b..c16e32d 100644 --- a/src/renderer/router/index.js +++ b/src/renderer/router/index.js @@ -40,6 +40,11 @@ export default new Router({ component: require('@/components/SettingView/UpYun').default, name: 'upyun' }, + { + path: 'github', + component: require('@/components/SettingView/GitHub').default, + name: 'github' + }, { path: 'gallery', component: require('@/components/SettingView/Gallery').default,