Skip to content

Commit

Permalink
🐛 Fix: fileName encode bug
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #1121
  • Loading branch information
Molunerfinn committed May 7, 2023
1 parent 80c05a1 commit 8d9a400
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"lodash-id": "^0.14.0",
"lowdb": "^1.0.0",
"mitt": "^3.0.0",
"picgo": "^1.5.1",
"picgo": "^1.5.3",
"qrcode.vue": "^3.3.3",
"shell-path": "2.1.0",
"uuidv4": "^6.2.11",
Expand Down
7 changes: 3 additions & 4 deletions src/main/apis/app/uploader/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { IWindowList } from '#/types/enum'
import uploader from '.'
import pasteTemplate from '~/main/utils/pasteTemplate'
import db, { GalleryDB } from '~/main/apis/core/datastore'
import { handleCopyUrl } from '~/main/utils/common'
import { handleUrlEncode } from '#/utils/common'
import { handleCopyUrl, handleUrlEncodeWithSetting } from '~/main/utils/common'
import { T } from '~/main/i18n/index'
// import dayjs from 'dayjs'

Expand Down Expand Up @@ -44,7 +43,7 @@ export const uploadClipboardFiles = async (): Promise<string> => {
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
}
return handleUrlEncode(img[0].imgUrl as string)
return handleUrlEncodeWithSetting(img[0].imgUrl as string)
} else {
const notification = new Notification({
title: T('UPLOAD_FAILED'),
Expand Down Expand Up @@ -76,7 +75,7 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
notification.show()
}, i * 100)
await GalleryDB.getInstance().insert(imgs[i])
result.push(handleUrlEncode(imgs[i].imgUrl!))
result.push(handleUrlEncodeWithSetting(imgs[i].imgUrl!))
}
handleCopyUrl(pasteText.join('\n'))
// trayWindow just be created in mac/windows, not in linux
Expand Down
8 changes: 8 additions & 0 deletions src/main/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs-extra'
import db from '~/main/apis/core/datastore'
import { clipboard, Notification, dialog } from 'electron'
import { handleUrlEncode } from '~/universal/utils/common'

export const handleCopyUrl = (str: string): void => {
if (db.get('settings.autoCopy') !== false) {
Expand Down Expand Up @@ -117,3 +118,10 @@ export const getClipboardFilePath = (): string => {
}
return ''
}

export const handleUrlEncodeWithSetting = (url: string) => {
if (db.get('settings.encodeOutputURL') === true) {
url = handleUrlEncode(url)
}
return url
}
8 changes: 2 additions & 6 deletions src/main/utils/pasteTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IPasteStyle } from '#/types/enum'
import db from 'apis/core/datastore'
import { handleUrlEncode } from '~/universal/utils/common'
import { handleUrlEncodeWithSetting } from './common'

const formatCustomLink = (customLink: string, item: ImgInfo) => {
const fileName = item.fileName!.replace(new RegExp(`\\${item.extname}$`), '')
Expand All @@ -22,10 +21,7 @@ const formatCustomLink = (customLink: string, item: ImgInfo) => {
}

export default (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => {
let url = item.url || item.imgUrl
if (db.get('settings.encodeOutputURL') !== false) {
url = handleUrlEncode(url)
}
const url = handleUrlEncodeWithSetting(item.url || item.imgUrl)
const _customLink = customLink || '$url'
const tpl = {
markdown: `![](${url})`,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ async function initData () {
form.checkBetaUpdate = settings.checkBetaUpdate === undefined ? true : settings.checkBetaUpdate
form.useBuiltinClipboard = settings.useBuiltinClipboard === undefined ? false : settings.useBuiltinClipboard
form.language = settings.language ?? 'zh-CN'
form.encodeOutputURL = settings.encodeOutputURL === undefined ? true : settings.encodeOutputURL
form.encodeOutputURL = settings.encodeOutputURL === undefined ? false : settings.encodeOutputURL
currentLanguage.value = settings.language ?? 'zh-CN'
customLink.value = settings.customLink || '$url'
shortKey.upload = settings.shortKey.upload
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9749,10 +9749,10 @@ pend@~1.2.0:
resolved "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50"
integrity sha1-elfrVQpng/kRUzH89GY9XI4AelA=

picgo@^1.5.1:
version "1.5.1"
resolved "https://registry.npmmirror.com/picgo/-/picgo-1.5.1.tgz#38fa6310fea6ec95964a82cb6e4bceb3704f08e8"
integrity sha512-rPtz7ADsBDRwBVXo3gfKli9COgawFIfqb4TkAdT0z5oYbBjLE8qGoX6D+h9SuCcsD2KNQ/B4l6fk13nSRSCxIQ==
picgo@^1.5.3:
version "1.5.3"
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.5.3.tgz#6dc46a1225c081ff333ab87faf9312f29d5efaf2"
integrity sha512-OZ5b0KySr+qsMj+/14wLZshvg9PQ4q0xMAGud2ub/fB9oGNvhpAtK2hktC4hoKJWP4Ohr0BYoly5C7BAC1r3aw==
dependencies:
"@picgo/i18n" "^1.0.0"
"@picgo/store" "^2.0.2"
Expand Down

0 comments on commit 8d9a400

Please sign in to comment.