mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-25 10:10:21 +08:00
✨ Feature: optimize url encode and filename encode
This commit is contained in:
@@ -7,8 +7,7 @@ import { IWindowList } from '#/types/enum'
|
||||
import uploader from '.'
|
||||
import pasteTemplate from '~/main/utils/pasteTemplate'
|
||||
import db, { GalleryDB } from '~/main/apis/core/datastore'
|
||||
import { handleCopyUrl } from '~/main/utils/common'
|
||||
import { handleUrlEncode } from '#/utils/common'
|
||||
import { handleCopyUrl, handleUrlEncodeWithSetting } from '~/main/utils/common'
|
||||
import { T } from '~/main/i18n/index'
|
||||
import ALLApi from '@/apis/allApi'
|
||||
import picgo from '@core/picgo'
|
||||
@@ -49,7 +48,7 @@ export const uploadClipboardFiles = async (): Promise<IStringKeyMap> => {
|
||||
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
|
||||
}
|
||||
return {
|
||||
url: handleUrlEncode(img[0].imgUrl as string),
|
||||
url: handleUrlEncodeWithSetting(img[0].imgUrl as string),
|
||||
fullResult: img[0]
|
||||
}
|
||||
} else {
|
||||
@@ -99,7 +98,7 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
|
||||
}, i * 100)
|
||||
await GalleryDB.getInstance().insert(imgs[i])
|
||||
result.push({
|
||||
url: handleUrlEncode(imgs[i].imgUrl!),
|
||||
url: handleUrlEncodeWithSetting(imgs[i].imgUrl!),
|
||||
fullResult: imgs[i]
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1282,7 +1282,7 @@ const form = reactive<ISettingForm>({
|
||||
customMiniIcon: '',
|
||||
isHideDock: false,
|
||||
autoImport: false,
|
||||
encodeOutputURL: true,
|
||||
encodeOutputURL: false,
|
||||
isAutoListenClipboard: false,
|
||||
useShortUrl: false,
|
||||
deleteLocalFile: false
|
||||
@@ -1421,7 +1421,7 @@ async function initData () {
|
||||
form.useBuiltinClipboard = settings.useBuiltinClipboard === undefined ? true : settings.useBuiltinClipboard
|
||||
form.isAutoListenClipboard = settings.isAutoListenClipboard || false
|
||||
form.language = settings.language ?? 'zh-CN'
|
||||
form.encodeOutputURL = settings.encodeOutputURL === undefined ? true : settings.encodeOutputURL
|
||||
form.encodeOutputURL = settings.encodeOutputURL === undefined ? false : settings.encodeOutputURL
|
||||
form.deleteCloudFile = settings.deleteCloudFile || false
|
||||
form.autoImport = settings.autoImport || false
|
||||
form.isCustomMiniIcon = settings.isCustomMiniIcon || false
|
||||
|
||||
@@ -123,7 +123,7 @@ async function copyTheLink (item: ImgInfo) {
|
||||
|
||||
async function pasteTemplate (style: IPasteStyle, item: ImgInfo, customLink: string | undefined) {
|
||||
let url = item.url || item.imgUrl
|
||||
if ((await getConfig('settings.encodeOutputURL')) !== false) {
|
||||
if ((await getConfig('settings.encodeOutputURL')) === true) {
|
||||
url = handleUrlEncode(url)
|
||||
}
|
||||
const useShortUrl = await getConfig('settings.useShortUrl') || false
|
||||
|
||||
Reference in New Issue
Block a user