Skip to content

Commit

Permalink
✨ Feature: url encode in manage page
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed May 2, 2023
1 parent b97f79b commit 9fa989e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/renderer/manage/pages/bucketPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ https://www.baidu.com/img/bd_logo1.png"
size="20"
style="cursor: pointer;"
color="#409EFF"
@click="copyToClipboard(formatLink(item.url, item.fileName, manageStore.config.settings.pasteForma ?? '$markdown', manageStore.config.settings.customPasteFormat ?? '$url'))"
@click="copyToClipboard(formatLink(item.url, item.fileName, manageStore.config.settings.pasteFormat ?? '$markdown', manageStore.config.settings.customPasteFormat ?? '$url'))"
>
<CopyDocument />
</el-icon>
Expand Down Expand Up @@ -1506,7 +1506,7 @@ const isShowVideoFileDialog = ref(false)
const videoFileUrl = ref('')
const videoPlayerHeaders = ref({})
const showFileStyle = ref<'list' | 'grid'>('grid')
const isUploadKeepDirStructure = ref(manageStore.config.settings.isUploadKeepDirStructure ?? true)
const isUploadKeepDirStructure = computed(() => manageStore.config.settings.isUploadKeepDirStructure ?? true)
const isShowBatchRenameDialog = ref(false)
const batchRenameMatch = ref('')
const batchRenameReplace = ref('')
Expand Down Expand Up @@ -3489,7 +3489,7 @@ const columns: Column<any>[] = [
size="20"
style="cursor: pointer;"
color="#409EFF"
onClick={() => copyToClipboard(formatLink(item.url, item.fileName, manageStore.config.settings.pasteForma ?? '$markdown', manageStore.config.settings.customPasteFormat ?? '$url'))}
onClick={() => copyToClipboard(formatLink(item.url, item.fileName, manageStore.config.settings.pasteFormat ?? '$markdown', manageStore.config.settings.customPasteFormat ?? '$url'))}
>
<CopyDocument />
</ElIcon>
Expand Down Expand Up @@ -3629,6 +3629,7 @@ const columns: Column<any>[] = [
]
onBeforeMount(async () => {
console.log('onBeforeMount')
await manageStore.refreshConfig()
showLoadingPage.value = true
await initCustomUrlList()
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/manage/pages/manageSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
style="width: 100%;"
>
<el-form
lable-position="left"
label-position="left"
label-width="50%"
size="default"
style="position: relative;width: 100%;"
Expand Down Expand Up @@ -422,7 +422,7 @@
<el-radio label="markdown">
{{ $T('MANAGE_SETTING_CHOOSE_COPY_FORMAT_MARKDOWN') }}
</el-radio>
<el-radio lable="markdown-with-link">
<el-radio label="markdown-with-link">
{{ $T('MANAGE_SETTING_CHOOSE_COPY_FORMAT_MARKDOWN_WITH_LINK') }}
</el-radio>
<el-radio label="rawurl">
Expand Down Expand Up @@ -573,7 +573,7 @@ async function initData () {
form.customRename = config.settings.customRename ?? false
customRenameFormat.value = config.settings.customRenameFormat ?? '{filename}'
customPasteFormat.value = config.settings.customPasteFormat ?? '$url'
form.pasteFormat = config.settings.pasteForma ?? 'markdown'
pasteFormat.value = config.settings.pasteFormat ?? 'markdown'
downloadDir.value = config.settings.downloadDir ?? ''
form.isAutoRefresh = config.settings.isAutoRefresh ?? false
form.isShowThumbnail = config.settings.isShowThumbnail ?? false
Expand Down
17 changes: 9 additions & 8 deletions src/renderer/manage/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,25 @@ export function renameFile (typeMap : IStringKeyMap, oldName: string): string {
}

export function formatLink (url: string, fileName: string, type: string, format?: string) : string {
const encodedUrl = encodeURI(url)
switch (type) {
case 'markdown':
return `![${fileName}](${url})`
return `![${fileName}](${encodedUrl})`
case 'html':
return `<img src="${url}" alt="${fileName}"/>`
return `<img src="${encodedUrl}" alt="${fileName}"/>`
case 'bbcode':
return `[img]${url}[/img]`
return `[img]${encodedUrl}[/img]`
case 'url':
return url
return encodedUrl
case 'markdown-with-link':
return `[![${fileName}](${url})](${url})`
return `[![${fileName}](${encodedUrl})](${encodedUrl})`
case 'custom':
if (format && (format.includes('$url') || format.includes('$fileName'))) {
return format.replace(/\$url/g, url).replace(/\$fileName/g, fileName)
return format.replace(/\$url/g, encodedUrl).replace(/\$fileName/g, fileName)
}
return url
return encodedUrl
default:
return url
return encodedUrl
}
}

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 @@ -17,7 +17,7 @@
id="upload-view-title"
@click="handlePicBedNameClick(picBedName, picBedConfigName)"
>
{{ $T('PICTURE_UPLOAD') }} - {{ picBedName }} - {{ picBedConfigName }}
{{ picBedName }} - {{ picBedConfigName }}
</span>
</el-tooltip>
<el-icon
Expand Down

0 comments on commit 9fa989e

Please sign in to comment.