From 9e2834c0f90c860f65e0b7e21684c0861faace1b Mon Sep 17 00:00:00 2001 From: Molunerfinn Date: Mon, 4 Jun 2018 20:13:17 +0800 Subject: [PATCH] Added: support for upload notice & auto rename before upload --- src/main/utils/img2base64.js | 24 ++++++++++++++----- src/main/utils/uploader.js | 6 +++++ .../components/SettingView/PicGoSetting.vue | 16 ++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/main/utils/img2base64.js b/src/main/utils/img2base64.js index 1ffcd1f..077e3c4 100644 --- a/src/main/utils/img2base64.js +++ b/src/main/utils/img2base64.js @@ -32,10 +32,16 @@ const createRenameWindow = () => { const imgFromPath = async (imgPath) => { let results = [] - let rename = db.read().get('picBed.rename').value() + const rename = db.read().get('picBed.rename').value() + const autoRename = db.read().get('picBed.autoRename').value() await Promise.all(imgPath.map(async item => { let name - let fileName = path.basename(item) + let fileName + if (autoRename) { + fileName = fecha.format(new Date(), 'YYYYMMDDHHmmss') + path.extname(item) + } else { + fileName = path.basename(item) + } if (rename) { const window = createRenameWindow() await waitForShow(window.webContents) @@ -81,22 +87,28 @@ const imgFromClipboard = async (file) => { const imgFromUploader = async (files) => { let results = [] - let rename = db.read().get('picBed.rename').value() + const rename = db.read().get('picBed.rename').value() + const autoRename = db.read().get('picBed.autoRename').value() await Promise.all(files.map(async item => { let name + let fileName + if (autoRename) { + fileName = fecha.format(new Date(), 'YYYYMMDDHHmmss') + path.extname(item.name) + } else { + fileName = path.basename(item.path) + } if (rename) { const window = createRenameWindow() await waitForShow(window.webContents) - window.webContents.send('rename', item.name, window.webContents.id) + window.webContents.send('rename', fileName, window.webContents.id) name = await waitForRename(window, window.webContents.id) } let buffer = await fs.readFile(item.path) let base64Image = Buffer.from(buffer, 'binary').toString('base64') - let fileName = name || item.name let imgSize = sizeOf(item.path) results.push({ base64Image, - fileName, + fileName: name || fileName, width: imgSize.width, height: imgSize.height, extname: path.extname(item.name) diff --git a/src/main/utils/uploader.js b/src/main/utils/uploader.js index f136838..d182a46 100644 --- a/src/main/utils/uploader.js +++ b/src/main/utils/uploader.js @@ -4,6 +4,7 @@ import tcYunUpload from './tcYunUpload' import upYunUpload from './upYunUpload' import githubUpload from './githubUpload' import db from '../../datastore/index' +import { Notification } from 'electron' const checkUploader = (type) => { const currentUploader = db.read().get(`picBed.${type}`).value() @@ -15,6 +16,11 @@ const checkUploader = (type) => { } const uploader = (img, type, webContents) => { + const notification = new Notification({ + title: '上传进度', + body: '正在上传' + }) + notification.show() const uploadType = db.read().get('picBed.current').value() if (checkUploader(uploadType)) { switch (uploadType) { diff --git a/src/renderer/components/SettingView/PicGoSetting.vue b/src/renderer/components/SettingView/PicGoSetting.vue index 6b1a38d..2d3544a 100644 --- a/src/renderer/components/SettingView/PicGoSetting.vue +++ b/src/renderer/components/SettingView/PicGoSetting.vue @@ -51,6 +51,16 @@ @change="handleRename" > + + + @@ -143,7 +153,8 @@ export default { updateHelper: this.$db.get('picBed.showUpdateTip').value(), showPicBedList: [], autoStart: this.$db.get('picBed.autoStart').value() || false, - rename: this.$db.get('picBed.rename').value() || false + rename: this.$db.get('picBed.rename').value() || false, + autoRename: this.$db.get('picBed.autoRename').value() || false }, picBed: this.$picBed, keyBindingVisible: false, @@ -217,6 +228,9 @@ export default { }, handleRename (val) { this.$db.read().set('picBed.rename', val).write() + }, + handleAutoRename (val) { + this.$db.read().set('picBed.autoRename', val).write() } }, beforeDestroy () {