Skip to content

Commit

Permalink
✨ Feature: add settings.encodeOutputURL options
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #731
  • Loading branch information
Molunerfinn committed Apr 9, 2023
1 parent 34657ae commit f75514d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lodash-id": "^0.14.0",
"lowdb": "^1.0.0",
"mitt": "^3.0.0",
"picgo": "^1.5.0",
"picgo": "^1.5.1",
"qrcode.vue": "^3.3.3",
"shell-path": "2.1.0",
"uuidv4": "^6.2.11",
Expand Down
1 change: 1 addition & 0 deletions public/i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ SETTINGS_CHOOSE_LANGUAGE: Choose Language
UPLOADER_CONFIG_NAME: Configuration Name
UPLOADER_CONFIG_PLACEHOLDER: Please Enter Configuration Name
SELECTED_SETTING_HINT: Selected
SETTINGS_ENCODE_OUTPUT_URL: Encode Output(or Copyed) URL

# shortcut-page

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 @@ -114,6 +114,7 @@ BUILTIN_CLIPBOARD_TIPS: 使用内置剪贴板函数而不是调用脚本获取
UPLOADER_CONFIG_NAME: 图床配置名
UPLOADER_CONFIG_PLACEHOLDER: 请输入配置名称
SELECTED_SETTING_HINT: 已选中
SETTINGS_ENCODE_OUTPUT_URL: 输出(复制) URL 时进行转义

# shortcut-page

Expand Down
1 change: 1 addition & 0 deletions public/i18n/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ BUILTIN_CLIPBOARD_TIPS: 使用內建剪貼簿函數而不是調用腳本取得
UPLOADER_CONFIG_NAME: 圖床配置名
UPLOADER_CONFIG_PLACEHOLDER: 請輸入配置名稱
SELECTED_SETTING_HINT: 已選中
SETTINGS_ENCODE_OUTPUT_URL: 輸出(複製) URL 時進行轉義

# shortcut-page

Expand Down
7 changes: 6 additions & 1 deletion src/main/utils/pasteTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { IPasteStyle } from '#/types/enum'
import db from 'apis/core/datastore'
import { handleUrlEncode } from '~/universal/utils/common'

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

export default (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => {
const url = item.url || item.imgUrl
let url = item.url || item.imgUrl
if (db.get('settings.encodeOutputURL') !== false) {
url = handleUrlEncode(url)
}
const _customLink = customLink || '$url'
const tpl = {
markdown: `![](${url})`,
Expand Down
24 changes: 23 additions & 1 deletion src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,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 @@ -558,7 +568,8 @@ const form = reactive<ISettingForm>({
checkBetaUpdate: true,
useBuiltinClipboard: false,
language: 'zh-CN',
logFileSizeLimit: 10
logFileSizeLimit: 10,
encodeOutputURL: true
})
const languageList = i18nManager.languageList.map(item => ({
Expand Down Expand Up @@ -643,6 +654,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
currentLanguage.value = settings.language ?? 'zh-CN'
customLink.value = settings.customLink || '$url'
shortKey.upload = settings.shortKey.upload
Expand Down Expand Up @@ -814,6 +826,16 @@ function handleAutoCopyUrl (val: ICheckBoxValueType) {
}
}
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
}
}
function confirmLogLevelSetting () {
if (form.logLevel.length === 0) {
return $message.error($T('TIPS_PLEASE_CHOOSE_LOG_LEVEL'))
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 @@ -109,6 +109,7 @@ interface ILocales {
UPLOADER_CONFIG_NAME: string
UPLOADER_CONFIG_PLACEHOLDER: string
SELECTED_SETTING_HINT: string
SETTINGS_ENCODE_OUTPUT_URL: string
SHORTCUT_NAME: string
SHORTCUT_BIND: string
SHORTCUT_STATUS: string
Expand Down
1 change: 1 addition & 0 deletions src/universal/types/view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface ISettingForm {
useBuiltinClipboard: boolean
language: string
logFileSizeLimit: number
encodeOutputURL: boolean
}

interface IShortKeyMap {
Expand Down
2 changes: 1 addition & 1 deletion src/universal/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const isUrlEncode = (url: string): boolean => {
return url !== decodeURI(url)
} catch (e) {
// if some error caught, try to let it go
return true
return false
}
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9737,10 +9737,10 @@ pend@~1.2.0:
resolved "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50"
integrity sha1-elfrVQpng/kRUzH89GY9XI4AelA=

picgo@^1.5.0:
version "1.5.0"
resolved "https://registry.npmjs.org/picgo/-/picgo-1.5.0.tgz#c7ac682253580148c8748efd54b788f98f939d39"
integrity sha512-4OB5s9ywXbY+ipjV1Rmb4mzvtrIEaU9c/ZdVFHM0cfLhQBJD3ghYbn6lWI3qtrC/ScJvnrCo7f8fCAFzFvH2NQ==
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==
dependencies:
"@picgo/i18n" "^1.0.0"
"@picgo/store" "^2.0.2"
Expand Down

0 comments on commit f75514d

Please sign in to comment.