Feature: add url encode setting

This commit is contained in:
萌萌哒赫萝
2023-04-09 23:35:41 +08:00
parent 09ad102fe8
commit 8c7c3b28dd
10 changed files with 45 additions and 12 deletions

View File

@@ -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: `<img src="${url}"/>`,

View File

@@ -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')"
@@ -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 => ({
@@ -1061,7 +1072,7 @@ const proxyVisible = ref(false)
const mainWindowSizeVisible = ref(false)
const customLink = reactive({
value: '$url'
value: '![$fileName]($url)'
})
const shortKey = reactive<IShortKeyMap>({
@@ -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<string>('picBed.proxy') || ''

View File

@@ -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) {

View File

@@ -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

View File

@@ -15,7 +15,8 @@ interface ISettingForm {
deleteCloudFile: boolean,
isCustomMiniIcon: boolean,
customMiniIcon: string,
isHideDock: boolean
isHideDock: boolean,
encodeOutputURL: boolean
}
interface IShortKeyMap {