From 8c7c3b28dd09755361dd55f3efbdc85bfef986a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E8=90=8C=E5=93=92=E8=B5=AB=E8=90=9D?= Date: Sun, 9 Apr 2023 23:35:41 +0800 Subject: [PATCH] :sparkles: Feature: add url encode setting --- package.json | 2 +- public/i18n/en.yml | 2 ++ public/i18n/zh-CN.yml | 1 + public/i18n/zh-TW.yml | 2 ++ src/main/utils/pasteTemplate.ts | 8 ++++++-- src/renderer/pages/PicGoSetting.vue | 28 +++++++++++++++++++++++++--- src/renderer/pages/Upload.vue | 2 +- src/universal/types/i18n.d.ts | 1 + src/universal/types/view.d.ts | 3 ++- yarn.lock | 8 ++++---- 10 files changed, 45 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 24543d3d..cddf34d9 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "mime-types": "^2.1.35", "mitt": "^3.0.0", "nodejs-file-downloader": "^4.10.6", - "piclist": "^0.3.3", + "piclist": "^0.5.0", "pinia": "^2.0.32", "pinia-plugin-persistedstate": "^3.1.0", "qiniu": "^7.8.0", diff --git a/public/i18n/en.yml b/public/i18n/en.yml index 4e39fb27..d25bd7fb 100644 --- a/public/i18n/en.yml +++ b/public/i18n/en.yml @@ -191,6 +191,8 @@ SETTINGS_COMPRESS_AND_WATERMARK: Compress and Watermark SETTINGS_SYNC_DELETE_CLOUD: Sync delete from cloud storage of gallery SETTINGS_ISHIDEDOCK: Hide Dock Icon SETTINGS_ISHIDEDOCK_TIPS: Not support hide dock and tray at the same time +SETTINGS_ENCODE_OUTPUT_URL: Encode Output(or Copyed) URL + # shortcut-page BUILTIN_CLIPBOARD_TIPS: Use builtin clipboard function to upload instead of using scripts diff --git a/public/i18n/zh-CN.yml b/public/i18n/zh-CN.yml index 2f6747e7..18f1f055 100644 --- a/public/i18n/zh-CN.yml +++ b/public/i18n/zh-CN.yml @@ -192,6 +192,7 @@ SETTINGS_COMPRESS_AND_WATERMARK: 设置图片水印和压缩-格式转换等参 SETTINGS_SYNC_DELETE_CLOUD: 相册内删除时同步删除云端文件 SETTINGS_ISHIDEDOCK: 是否隐藏dock图标 SETTINGS_ISHIDEDOCK_TIPS: 不支持同时隐藏dock和托盘 +SETTINGS_ENCODE_OUTPUT_URL: 输出(复制) URL 时进行转义 # shortcut-page diff --git a/public/i18n/zh-TW.yml b/public/i18n/zh-TW.yml index ac29e4bb..4f364d06 100644 --- a/public/i18n/zh-TW.yml +++ b/public/i18n/zh-TW.yml @@ -192,6 +192,8 @@ SETTINGS_COMPRESS_AND_WATERMARK: 設置圖片浮水印和壓縮-格式轉換等 SETTINGS_SYNC_DELETE_CLOUD: 從相簿中刪除並同步從雲端刪除 SETTINGS_ISHIDEDOCK: 是否隱藏dock圖示 SETTINGS_ISHIDEDOCK_TIPS: 不支持同時隱藏dock和托盘 +SETTINGS_ENCODE_OUTPUT_URL: 輸出(複製) URL 時進行轉義 + # shortcut-page SHORTCUT_NAME: 快捷鍵名稱 diff --git a/src/main/utils/pasteTemplate.ts b/src/main/utils/pasteTemplate.ts index 42272fae..d9d381e2 100644 --- a/src/main/utils/pasteTemplate.ts +++ b/src/main/utils/pasteTemplate.ts @@ -1,5 +1,6 @@ import { IPasteStyle } from '#/types/enum' import { handleUrlEncode } from '#/utils/common' +import db from 'apis/core/datastore' const formatCustomLink = (customLink: string, item: ImgInfo) => { const fileName = item.fileName!.replace(new RegExp(`\\${item.extname}$`), '') @@ -21,8 +22,11 @@ const formatCustomLink = (customLink: string, item: ImgInfo) => { } export default (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => { - const url = handleUrlEncode(item.url || item.imgUrl) - const _customLink = customLink || '$url' + let url = item.url || item.imgUrl + if (db.get('settings.encodeOutputURL') !== false) { + url = handleUrlEncode(url) + } + const _customLink = customLink || '![$fileName]($url)' const tpl = { markdown: `![](${url})`, HTML: ``, diff --git a/src/renderer/pages/PicGoSetting.vue b/src/renderer/pages/PicGoSetting.vue index 2508431c..95b7b165 100644 --- a/src/renderer/pages/PicGoSetting.vue +++ b/src/renderer/pages/PicGoSetting.vue @@ -335,6 +335,16 @@ @change="useBuiltinClipboardChange" /> + + + ({ deleteCloudFile: false, isCustomMiniIcon: false, customMiniIcon: '', - isHideDock: false + isHideDock: false, + encodeOutputURL: true }) const languageList = i18nManager.languageList.map(item => ({ @@ -1061,7 +1072,7 @@ const proxyVisible = ref(false) const mainWindowSizeVisible = ref(false) const customLink = reactive({ - value: '$url' + value: '![$fileName]($url)' }) const shortKey = reactive({ @@ -1132,13 +1143,14 @@ 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.deleteCloudFile = settings.deleteCloudFile || false form.isCustomMiniIcon = settings.isCustomMiniIcon || false form.customMiniIcon = settings.customMiniIcon || '' form.isHideDock = settings.isHideDock || false currentLanguage.value = settings.language ?? 'zh-CN' currentStartMode.value = settings.startMode || 'quiet' - customLink.value = settings.customLink || '$url' + customLink.value = settings.customLink || '![$fileName]($url)' shortKey.upload = settings.shortKey.upload proxy.value = picBed.proxy || '' npmRegistry.value = settings.registry || '' @@ -1200,6 +1212,16 @@ function confirmCustomLink () { }) } +function handleEncodeOutputURL (val: ICheckBoxValueType) { + saveConfig('settings.encodeOutputURL', val) + const successNotification = new Notification($T('SETTINGS_ENCODE_OUTPUT_URL'), { + body: $T('TIPS_SET_SUCCEED') + }) + successNotification.onclick = () => { + return true + } +} + async function cancelProxy () { proxyVisible.value = false proxy.value = await getConfig('picBed.proxy') || '' diff --git a/src/renderer/pages/Upload.vue b/src/renderer/pages/Upload.vue index d16e0e7f..5cfea8a6 100644 --- a/src/renderer/pages/Upload.vue +++ b/src/renderer/pages/Upload.vue @@ -602,7 +602,7 @@ function ipcSendFiles (files: FileList) { async function getPasteStyle () { pasteStyle.value = await getConfig('settings.pasteStyle') || 'markdown' - customLink.value = await getConfig('settings.customLink') || '$url' + customLink.value = await getConfig('settings.customLink') || '![$fileName]($url)' } function handlePasteStyleChange (val: string | number | boolean) { diff --git a/src/universal/types/i18n.d.ts b/src/universal/types/i18n.d.ts index f455d49b..1c88e2df 100644 --- a/src/universal/types/i18n.d.ts +++ b/src/universal/types/i18n.d.ts @@ -186,6 +186,7 @@ interface ILocales { SETTINGS_SYNC_DELETE_CLOUD: string SETTINGS_ISHIDEDOCK: string SETTINGS_ISHIDEDOCK_TIPS: string + SETTINGS_ENCODE_OUTPUT_URL: string SHORTCUT_NAME: string SHORTCUT_BIND: string SHORTCUT_STATUS: string diff --git a/src/universal/types/view.d.ts b/src/universal/types/view.d.ts index b3d435c3..0ba96c36 100644 --- a/src/universal/types/view.d.ts +++ b/src/universal/types/view.d.ts @@ -15,7 +15,8 @@ interface ISettingForm { deleteCloudFile: boolean, isCustomMiniIcon: boolean, customMiniIcon: string, - isHideDock: boolean + isHideDock: boolean, + encodeOutputURL: boolean } interface IShortKeyMap { diff --git a/yarn.lock b/yarn.lock index c741033b..fbcf6325 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11022,10 +11022,10 @@ performance-now@^2.1.0: resolved "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow== -piclist@^0.3.3: - version "0.3.3" - resolved "https://registry.npmjs.org/piclist/-/piclist-0.3.3.tgz#eedd346beaee732179b0ce50738f115097fe54e0" - integrity sha512-mN9rNZzNUoOW7yjb0HKsvyOOL2s0KEKMKicEMqhIxQx4QIKjhtMundYSSWck43Ulj65b/DethKU0io2vEBC6lw== +piclist@^0.5.0: + version "0.5.0" + resolved "https://registry.npmjs.org/piclist/-/piclist-0.5.0.tgz#0eedf84e475514724b690de826c4f24631862890" + integrity sha512-bFdGsp7fLQ4uSf2y5cAct4tAUgry21vEFRCUE1ywIOf3nPTXPzrsNBt+rITANrIaVjQH/8MDirxnmgM7Cbll1Q== dependencies: "@picgo/i18n" "^1.0.0" "@picgo/store" "^2.0.4"