mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-23 14:48:13 -05:00
parent
a693544291
commit
59d3eba86d
@ -1,7 +1,7 @@
|
||||
import db from '#/datastore'
|
||||
import { clipboard } from 'electron'
|
||||
|
||||
export function handleCopyUrl (str: string): void {
|
||||
export const handleCopyUrl = (str: string): void => {
|
||||
if (db.get('settings.autoCopy') !== false) {
|
||||
clipboard.writeText(str)
|
||||
}
|
||||
|
@ -1 +1,17 @@
|
||||
export const isUrl = (url: string): boolean => (url.startsWith('http://') || url.startsWith('https://'))
|
||||
export const isUrlEncode = (url: string): boolean => {
|
||||
url = url || ''
|
||||
try {
|
||||
return url !== decodeURI(url)
|
||||
} catch (e) {
|
||||
// if some error caught, try to let it go
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
export const handleUrlEncode = (url: string): string => {
|
||||
if (!isUrlEncode(url)) {
|
||||
url = encodeURI(url)
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
import db from '#/datastore'
|
||||
import { IPasteStyle } from '#/types/enum'
|
||||
import { handleUrlEncode } from './common'
|
||||
|
||||
const formatCustomLink = (customLink: string, item: ImgInfo) => {
|
||||
let fileName = item.fileName!.replace(new RegExp(`\\${item.extname}$`), '')
|
||||
let url = item.url || item.imgUrl
|
||||
const url = handleUrlEncode(item.url || item.imgUrl)
|
||||
const formatObj = {
|
||||
url,
|
||||
fileName
|
||||
@ -19,7 +20,7 @@ const formatCustomLink = (customLink: string, item: ImgInfo) => {
|
||||
}
|
||||
|
||||
export default (style: IPasteStyle, item: ImgInfo) => {
|
||||
let url = item.url || item.imgUrl
|
||||
const url = handleUrlEncode(item.url || item.imgUrl)
|
||||
const customLink = db.get('settings.customLink') || '$url'
|
||||
const tpl = {
|
||||
'markdown': `![](${url})`,
|
||||
|
Loading…
Reference in New Issue
Block a user