diff --git a/src/main/utils/img2base64.js b/src/main/utils/img2base64.js index 3ffcfe73..f4bba7e5 100644 --- a/src/main/utils/img2base64.js +++ b/src/main/utils/img2base64.js @@ -50,7 +50,7 @@ const imgFromPath = async (imgPath) => { name = await waitForRename(window, window.webContents.id) } let buffer = await fs.readFile(item) - let base64Image = Buffer.from(buffer, 'binary').toString('base64') + let base64Image = Buffer.from(buffer).toString('base64') let imgSize = sizeOf(item) results.push({ base64Image, @@ -105,7 +105,7 @@ const imgFromUploader = async (files) => { name = await waitForRename(window, window.webContents.id) } let buffer = await fs.readFile(item.path) - let base64Image = Buffer.from(buffer, 'binary').toString('base64') + let base64Image = Buffer.from(buffer).toString('base64') let imgSize = sizeOf(item.path) results.push({ base64Image, diff --git a/src/main/utils/tcYunUpload.js b/src/main/utils/tcYunUpload.js index ad2f049d..0a217b62 100644 --- a/src/main/utils/tcYunUpload.js +++ b/src/main/utils/tcYunUpload.js @@ -3,6 +3,7 @@ import * as img2Base64 from './img2base64' import db from '../../datastore/index' import { Notification, clipboard } from 'electron' import crypto from 'crypto' +import mime from 'mime-types' // generate COS signature string const generateSignature = (fileName) => { @@ -67,7 +68,7 @@ const postOptions = (fileName, signature, imgBase64) => { headers: { Host: `${options.bucket}.cos.${options.area}.myqcloud.com`, Authorization: `q-sign-algorithm=sha1&q-ak=${options.secretId}&q-sign-time=${signature.signTime}&q-key-time=${signature.signTime}&q-header-list=host&q-url-param-list=&q-signature=${signature.signature}`, - contentType: 'multipart/form-data' + contentType: mime.lookup(fileName) }, body: Buffer.from(imgBase64, 'base64'), resolveWithFullResponse: true diff --git a/src/renderer/components/SettingView/Gallery.vue b/src/renderer/components/SettingView/Gallery.vue index a94a515a..e054c861 100644 --- a/src/renderer/components/SettingView/Gallery.vue +++ b/src/renderer/components/SettingView/Gallery.vue @@ -15,11 +15,13 @@ - + + + -
- 清空搜索 +
+ 批量复制
@@ -143,7 +145,7 @@ export default { this.idx = null }, copy (url) { - const style = this.$db.read().get('picBed.pasteStyle').value() + const style = this.$db.read().get('picBed.pasteStyle').value() || 'markdown' const copyLink = pasteStyle(style, url) const obj = { title: '复制链接成功', @@ -153,7 +155,7 @@ export default { const myNotification = new window.Notification(obj.title, obj) this.$electron.clipboard.writeText(copyLink) myNotification.onclick = () => { - return true + console.log(123) } }, remove (id) { @@ -239,6 +241,25 @@ export default { }) } }, + multiCopy () { + let copyString = '' + const style = this.$db.read().get('picBed.pasteStyle').value() || 'markdown' + Object.keys(this.choosedList).forEach(key => { + if (this.choosedList[key]) { + console.log(pasteStyle(style, this.$db.read().get('uploaded').getById(key).value().imgUrl), style) + copyString += pasteStyle(style, this.$db.read().get('uploaded').getById(key).value().imgUrl) + '\n' + } + }) + const obj = { + title: '复制链接成功', + body: copyString + } + const myNotification = new window.Notification(obj.title, obj) + this.$electron.clipboard.writeText(copyString) + myNotification.onclick = () => { + return true + } + }, toggleHandleBar () { this.handleBarActive = !this.handleBarActive } @@ -266,13 +287,20 @@ export default { cursor pointer font-size 13px transition all .2s ease-in-out + &.copy + cursor not-allowed + background #49B1F5 + &.active + cursor pointer + background #1B9EF3 + color #fff &.delete cursor not-allowed background #F47466 - &.delete.active - cursor pointer - background #F15140 - color #fff + &.active + cursor pointer + background #F15140 + color #fff .long-list width: calc(83.3333333% - 6px) #gallery-view diff --git a/src/renderer/components/TrayPage.vue b/src/renderer/components/TrayPage.vue index 02756ef8..d30be074 100644 --- a/src/renderer/components/TrayPage.vue +++ b/src/renderer/components/TrayPage.vue @@ -78,7 +78,7 @@ this.notification.body = item.imgUrl this.notification.icon = item.imgUrl const myNotification = new window.Notification(this.notification.title, this.notification) - const pasteStyle = this.$db.read().get('picBed.pasteStyle').value() + const pasteStyle = this.$db.read().get('picBed.pasteStyle').value() || 'markdown' this.$electron.clipboard.writeText(pasteTemplate(pasteStyle, item.imgUrl)) myNotification.onclick = () => { return true