Skip to content

Commit

Permalink
✨ Feature: add url encode setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Apr 9, 2023
1 parent 09ad102 commit 8c7c3b2
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions public/i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions public/i18n/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions public/i18n/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 快捷鍵名稱
Expand Down
8 changes: 6 additions & 2 deletions src/main/utils/pasteTemplate.ts
Original file line number Diff line number Diff line change
@@ -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}$`), '')
Expand All @@ -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: `<img src="${url}"/>`,
Expand Down
28 changes: 25 additions & 3 deletions src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@
@change="useBuiltinClipboardChange"
/>
</el-form-item>
<el-form-item
:label="$T('SETTINGS_ENCODE_OUTPUT_URL')"
>
<el-switch
v-model="form.encodeOutputURL"
:active-text="$T('SETTINGS_OPEN')"
:inactive-text="$T('SETTINGS_CLOSE')"
@change="handleEncodeOutputURL"
/>
</el-form-item>
<el-form-item
:style="{ marginRight: '-64px' }"
:label="$T('CHOOSE_SHOWED_PICBED')"
Expand Down Expand Up @@ -1040,7 +1050,8 @@ const form = reactive<ISettingForm>({
deleteCloudFile: false,
isCustomMiniIcon: false,
customMiniIcon: '',
isHideDock: false
isHideDock: false,
encodeOutputURL: true
})
const languageList = i18nManager.languageList.map(item => ({
Expand All @@ -1061,7 +1072,7 @@ const proxyVisible = ref(false)
const mainWindowSizeVisible = ref(false)
const customLink = reactive({
value: '$url'
value: '![$fileName]($url)'
})
const shortKey = reactive<IShortKeyMap>({
Expand Down Expand Up @@ -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 || ''
Expand Down Expand Up @@ -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<string>('picBed.proxy') || ''
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/pages/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/universal/types/i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/universal/types/view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ interface ISettingForm {
deleteCloudFile: boolean,
isCustomMiniIcon: boolean,
customMiniIcon: string,
isHideDock: boolean
isHideDock: boolean,
encodeOutputURL: boolean
}

interface IShortKeyMap {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8c7c3b2

Please sign in to comment.