Feature: optimize url encode and filename encode

This commit is contained in:
萌萌哒赫萝
2023-05-07 17:05:58 +08:00
parent f5b89ceaa9
commit 8d1b8173bd
7 changed files with 18 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
import fs from 'fs-extra'
import db from '~/main/apis/core/datastore'
import { clipboard, Notification, dialog } from 'electron'
import { handleUrlEncode } from '~/universal/utils/common'
export const handleCopyUrl = (str: string): void => {
if (db.get('settings.autoCopy') !== false) {
@@ -110,3 +111,5 @@ export const getClipboardFilePath = (): string => {
}
return ''
}
export const handleUrlEncodeWithSetting = (url: string) => db.get('settings.encodeOutputURL') ? handleUrlEncode(url) : url

View File

@@ -1,6 +1,7 @@
import { IPasteStyle } from '#/types/enum'
import { handleUrlEncode, generateShortUrl } from '#/utils/common'
import { generateShortUrl } from '#/utils/common'
import db from '~/main/apis/core/datastore'
import { handleUrlEncodeWithSetting } from './common'
export const formatCustomLink = (customLink: string, item: ImgInfo) => {
const fileName = item.fileName!.replace(new RegExp(`\\${item.extname}$`), '')
@@ -23,9 +24,7 @@ export const formatCustomLink = (customLink: string, item: ImgInfo) => {
export default async (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) => {
let url = item.url || item.imgUrl
if (db.get('settings.encodeOutputURL') !== false) {
url = handleUrlEncode(url)
}
url = handleUrlEncodeWithSetting(item.url || item.imgUrl)
const useShortUrl = db.get('settings.useShortUrl') || false
if (useShortUrl) {
url = await generateShortUrl(url)