🔨 Refactor(custom): refactored imports

This commit is contained in:
Kuingsmile
2024-06-09 18:39:12 +08:00
parent e87e3999b4
commit 19c12b6b02
30 changed files with 207 additions and 216 deletions

View File

@@ -1,3 +1,5 @@
import path from 'path'
export const isUrl = (url: string): boolean => {
try {
return Boolean(new URL(url))
@@ -68,3 +70,39 @@ export function encodeFilePath (filePath: string) {
.map(encodeURIComponent)
.join('/')
}
export const getExtension = (fileName: string) => path.extname(fileName).slice(1)
export const isImage = (fileName: string) =>
['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'ico', 'svg'].includes(getExtension(fileName))
export const formatEndpoint = (endpoint: string, sslEnabled: boolean): string =>
!/^https?:\/\//.test(endpoint)
? `${sslEnabled ? 'https' : 'http'}://${endpoint}`
: sslEnabled
? endpoint.replace('http://', 'https://')
: endpoint.replace('https://', 'http://')
export const trimPath = (path: string) => path.replace(/^\/+|\/+$/g, '').replace(/\/+/g, '/')
export const formatHttpProxy = (proxy: string | undefined, type: 'object' | 'string'): IHTTPProxy | undefined | string => {
if (!proxy) return undefined
if (/^https?:\/\//.test(proxy)) {
const { protocol, hostname, port } = new URL(proxy)
return type === 'string'
? `${protocol}//${hostname}:${port}`
: {
host: hostname,
port: Number(port),
protocol: protocol.slice(0, -1)
}
}
const [host, port] = proxy.split(':')
return type === 'string'
? `http://${host}:${port}`
: {
host,
port: port ? Number(port) : 80,
protocol: 'http'
}
}

View File

@@ -3,6 +3,12 @@ export const RELEASE_URL = 'https://api.github.com/repos/Kuingsmile/PicList/rele
export const RELEASE_URL_BACKUP = 'https://release.piclist.cn'
export const STABLE_RELEASE_URL = 'https://github.com/Kuingsmile/PicList/releases/latest'
export const DEFAULT_AES_PASSWORD = 'aesPassword'
export const cancelDownloadLoadingFileList = 'cancelDownloadLoadingFileList'
export const refreshDownloadFileTransferList = 'refreshDownloadFileTransferList'
export const selectDownloadFolder = 'selectDownloadFolder'
export const picBedsCanbeDeleted = [
'aliyun',
'alist',
@@ -63,5 +69,3 @@ export const picBedManualUrlList: IStringKeyMap = {
webdavplist: 'https://piclist.cn/en/configure.html#webdav'
}
}
export const DEFAULT_AES_PASSWORD = 'aesPassword'