🚧 WIP(custom): v3.0.0 migrate to vite and esm

This commit is contained in:
Kuingsmile
2025-07-31 17:37:30 +08:00
parent cd76bc7c10
commit 054f4b4cff
597 changed files with 197292 additions and 13329 deletions

View File

@@ -1,5 +1,4 @@
import axios from 'axios'
import path from 'path'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
@@ -14,7 +13,7 @@ interface IConfigMap {
}
export default class AlistApi {
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const { fileName, config } = configMap
try {
const { version, url, uploadPath, token } = config
@@ -30,8 +29,8 @@ export default class AlistApi {
Authorization: token
},
data: {
dir: path.join('/', uploadPath, path.dirname(fileName)),
names: [path.basename(fileName)]
dir: window.node.path.join('/', uploadPath, window.node.path.dirname(fileName)),
names: [window.node.path.basename(fileName)]
}
})
if (result.data.code === 200) {

View File

@@ -1,5 +1,4 @@
import axios from 'axios'
import path from 'path'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
@@ -25,7 +24,7 @@ const getAListToken = async (url: string, username: string, password: string) =>
}
export default class AListplistApi {
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const { fileName, config } = configMap
try {
const { url, username, password, uploadPath } = config
@@ -45,8 +44,8 @@ export default class AListplistApi {
Authorization: token
},
data: {
dir: path.join('/', uploadPath, path.dirname(fileName)),
names: [path.basename(fileName)]
dir: window.node.path.join('/', uploadPath, window.node.path.dirname(fileName)),
names: [window.node.path.basename(fileName)]
}
})
if (result.data.code === 200) {

View File

@@ -1,5 +1,4 @@
import OSS from 'ali-oss'
import { IAliYunConfig, PartialKeys } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
@@ -8,14 +7,14 @@ interface IConfigMap {
}
export default class AliyunApi {
static #getKey(fileName: string, path?: string): string {
static #getKey (fileName: string, path?: string): string {
return path && path !== '/' ? `${path.replace(/^\/+|\/+$/, '')}/${fileName}` : fileName
}
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const { fileName, config } = configMap
try {
const client = new OSS({ ...config, region: config.area })
const client = new window.node.OSS({ ...config, region: config.area })
const key = AliyunApi.#getKey(fileName, config.path)
const result = await client.delete(key)
if (result.res.status === 204) {

View File

@@ -15,6 +15,7 @@ import SmmsApi from '@/apis/smms'
import TcyunApi from '@/apis/tcyun'
import UpyunApi from '@/apis/upyun'
import WebdavApi from '@/apis/webdav'
import { IStringKeyMap } from '#/types/types'
const apiMap: IStringKeyMap = {
alist: AlistApi,
@@ -38,7 +39,7 @@ const apiMap: IStringKeyMap = {
}
export default class ALLApi {
static async delete(configMap: IStringKeyMap): Promise<boolean> {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
const api = apiMap[configMap.type]
return api ? await api.delete(configMap) : false
}

View File

@@ -1,16 +1,12 @@
import { ipcRenderer } from 'electron'
import { getRawData, triggerRPC } from '@/utils/common'
import { removeFileFromS3InMain } from '~/utils/deleteFunc'
import { deleteFailedLog } from '#/utils/deleteLog'
import { getRawData } from '@/utils/common'
import { IRPCActionType } from '#/types/enum'
import { IStringKeyMap } from '#/types/types'
import { deleteFailedLog } from '#/utils/deleteLog'
export default class AwsS3Api {
static async delete(configMap: IStringKeyMap): Promise<boolean> {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
try {
return ipcRenderer
? (await triggerRPC(IRPCActionType.GALLERY_DELETE_AWS_S3_FILE, getRawData(configMap))) || false
: await removeFileFromS3InMain(getRawData(configMap))
return (await window.electron.triggerRPC(IRPCActionType.GALLERY_DELETE_AWS_S3_FILE, getRawData(configMap))) || false
} catch (error: any) {
deleteFailedLog(configMap.fileName, 'AWS S3', error)
return false

View File

@@ -1,17 +1,12 @@
import { ipcRenderer } from 'electron'
import { removeFileFromDogeInMain } from '~/utils/deleteFunc'
import { getRawData, triggerRPC } from '@/utils/common'
import { deleteFailedLog } from '#/utils/deleteLog'
import { getRawData } from '@/utils/common'
import { IRPCActionType } from '#/types/enum'
import { IStringKeyMap } from '#/types/types'
import { deleteFailedLog } from '#/utils/deleteLog'
export default class AwsS3Api {
static async delete(configMap: IStringKeyMap): Promise<boolean> {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
try {
return ipcRenderer
? (await triggerRPC(IRPCActionType.GALLERY_DELETE_DOGE_FILE, getRawData(configMap))) || false
: await removeFileFromDogeInMain(getRawData(configMap))
return (await window.electron.triggerRPC(IRPCActionType.GALLERY_DELETE_DOGE_FILE, getRawData(configMap))) || false
} catch (error: any) {
deleteFailedLog(configMap.fileName, 'DogeCloud', error)
return false

View File

@@ -1,5 +1,4 @@
import { Octokit } from '@octokit/rest'
import { IGitHubConfig, PartialKeys } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
@@ -9,18 +8,18 @@ interface IConfigMap {
}
export default class GithubApi {
static #createOctokit(token: string) {
return new Octokit({
static #createOctokit (token: string) {
return new window.node.Octokit({
auth: token
})
}
static #createKey(path: string | undefined, fileName: string): string {
static #createKey (path: string | undefined, fileName: string): string {
const formatedFileName = fileName.replace(/%2F/g, '/')
return path && path !== '/' ? `${path.replace(/^\/+|\/+$/, '')}/${formatedFileName}` : formatedFileName
}
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const {
fileName,
hash,

View File

@@ -1,17 +1,12 @@
import { ipcRenderer } from 'electron'
import { removeFileFromHuaweiInMain } from '~/utils/deleteFunc'
import { getRawData, triggerRPC } from '@/utils/common'
import { deleteFailedLog } from '#/utils/deleteLog'
import { getRawData } from '@/utils/common'
import { IRPCActionType } from '#/types/enum'
import { IStringKeyMap } from '#/types/types'
import { deleteFailedLog } from '#/utils/deleteLog'
export default class HuaweicloudApi {
static async delete(configMap: IStringKeyMap): Promise<boolean> {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
try {
return ipcRenderer
? (await triggerRPC(IRPCActionType.GALLERY_DELETE_HUAWEI_OSS_FILE, getRawData(configMap))) || false
: await removeFileFromHuaweiInMain(getRawData(configMap))
return (await window.electron.triggerRPC(IRPCActionType.GALLERY_DELETE_HUAWEI_OSS_FILE, getRawData(configMap))) || false
} catch (error: any) {
deleteFailedLog(configMap.fileName, 'HuaweiCloud', error)
return false

View File

@@ -1,5 +1,6 @@
import axios, { AxiosResponse } from 'axios'
import { IImgurConfig } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
@@ -10,7 +11,7 @@ interface IConfigMap {
export default class ImgurApi {
static #baseUrl = 'https://api.imgur.com/3'
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const { config: { clientId = '', username = '', accessToken = '' } = {}, hash = '' } = configMap
let Authorization: string, apiUrl: string

View File

@@ -1,5 +1,3 @@
import fs from 'fs-extra'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
@@ -7,7 +5,7 @@ interface IConfigMap {
}
export default class LocalApi {
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const { hash } = configMap
if (!hash) {
deleteLog(hash, 'Local', false, 'Local.delete: invalid params')
@@ -15,7 +13,7 @@ export default class LocalApi {
}
try {
await fs.remove(hash)
await window.node.fs.remove(hash)
deleteLog(hash, 'Local')
return true
} catch (error: any) {

View File

@@ -1,10 +1,8 @@
import axios, { AxiosResponse } from 'axios'
import https from 'https'
import { IStringKeyMap } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
export default class LskyplistApi {
static async delete(configMap: IStringKeyMap): Promise<boolean> {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
const { hash, config } = configMap
if (!hash || !config || !config.token) {
deleteLog(hash, 'Lskyplist', false, 'LskyplistApi.delete: invalid params')
@@ -22,11 +20,11 @@ export default class LskyplistApi {
Authorization: token || undefined
}
const requestAgent = new https.Agent({
const requestAgent = new window.node.https.Agent({
rejectUnauthorized: false
})
try {
const response: AxiosResponse = await axios.delete(`${host}/api/v1/images/${hash}`, {
const response: any = await window.node.axios.delete(`${host}/api/v1/images/${hash}`, {
headers: v2Headers,
timeout: 30000,
httpsAgent: requestAgent

View File

@@ -1,9 +1,8 @@
import axios, { AxiosResponse } from 'axios'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
import { IStringKeyMap } from '#/types/types'
import { deleteFailedLog, deleteLog } from '~/utils/deleteLog'
export default class PiclistApi {
static async delete(configMap: IStringKeyMap): Promise<boolean> {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
const { config, fullResult } = configMap
const { host, port } = config
if (!fullResult) return true
@@ -16,7 +15,7 @@ export default class PiclistApi {
const url = `http://${host || '127.0.0.1'}:${port || 36677}/delete`
try {
const response: AxiosResponse = await axios.post(url, {
const response: any = await window.node.axios.post(url, {
list: [fullResult]
})
if (response.status === 200 && response.data?.success) {

View File

@@ -1,6 +1,5 @@
import Qiniu from 'qiniu'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
import { IQiniuConfig, PartialKeys } from '#/types/types'
import { deleteFailedLog, deleteLog } from '~/utils/deleteLog'
interface IConfigMap {
fileName: string
@@ -8,15 +7,15 @@ interface IConfigMap {
}
export default class QiniuApi {
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const {
fileName,
config: { accessKey, secretKey, bucket, path }
} = configMap
const mac = new Qiniu.auth.digest.Mac(accessKey, secretKey)
const qiniuConfig = new Qiniu.conf.Config()
const mac = new window.node.qiniu.auth.digest.Mac(accessKey, secretKey)
const qiniuConfig = new window.node.qiniu.conf.Config()
try {
const bucketManager = new Qiniu.rs.BucketManager(mac, qiniuConfig)
const bucketManager = new window.node.qiniu.rs.BucketManager(mac, qiniuConfig)
const formattedPath = path?.replace(/^\/+|\/+$/, '') || ''
const key = path === '/' || !path ? fileName : `${formattedPath}/${fileName}`
const res = (await new Promise((resolve, reject) => {

View File

@@ -1,18 +1,13 @@
import { ipcRenderer } from 'electron'
import { removeFileFromSFTPInMain } from '~/utils/deleteFunc'
import { getRawData, triggerRPC } from '@/utils/common'
import { deleteFailedLog } from '#/utils/deleteLog'
import { getRawData } from '@/utils/common'
import { IRPCActionType } from '#/types/enum'
import { IStringKeyMap } from '#/types/types'
import { deleteFailedLog } from '#/utils/deleteLog'
export default class SftpPlistApi {
static async delete(configMap: IStringKeyMap): Promise<boolean> {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
const { fileName, config } = configMap
try {
return ipcRenderer
? (await triggerRPC(IRPCActionType.GALLERY_DELETE_SFTP_FILE, getRawData(config), fileName)) || false
: await removeFileFromSFTPInMain(getRawData(config), fileName)
return (await window.electron.triggerRPC(IRPCActionType.GALLERY_DELETE_SFTP_FILE, getRawData(config), fileName)) || false
} catch (error: any) {
deleteFailedLog(fileName, 'SFTP', error)
return false

View File

@@ -1,5 +1,4 @@
import axios, { AxiosResponse } from 'axios'
import { ISMMSConfig } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
@@ -10,7 +9,7 @@ interface IConfigMap {
export default class SmmsApi {
static readonly #baseUrl = 'https://smms.app/api/v2'
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const { hash, config } = configMap
if (!hash || !config || !config.token) {
deleteLog(hash, 'Smms', false, 'SmmsApi.delete: invalid params')
@@ -20,7 +19,7 @@ export default class SmmsApi {
const { token } = config
try {
const response: AxiosResponse = await axios.get(`${SmmsApi.#baseUrl}/delete/${hash}`, {
const response: any = await window.node.axios.get(`${SmmsApi.#baseUrl}/delete/${hash}`, {
headers: {
Authorization: token
},

View File

@@ -1,21 +1,19 @@
import COS from 'cos-nodejs-sdk-v5'
import { ITcYunConfig, PartialKeys } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
fileName: string
config: PartialKeys<ITcYunConfig, 'path'>
}
export default class TcyunApi {
static #createCOS(SecretId: string, SecretKey: string): COS {
return new COS({
static #createCOS (SecretId: string, SecretKey: string): any {
return new window.node.COS({
SecretId,
SecretKey
})
}
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const {
fileName,
config: { secretId, secretKey, bucket, area, path }

View File

@@ -1,5 +1,4 @@
import Upyun from 'upyun'
import { IUpYunConfig, PartialKeys } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
@@ -8,14 +7,14 @@ interface IConfigMap {
}
export default class UpyunApi {
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const {
fileName,
config: { bucket, operator, password, path }
} = configMap
try {
const service = new Upyun.Service(bucket, operator, password)
const client = new Upyun.Client(service)
const service = new window.node.Upyun.Service(bucket, operator, password)
const client = new window.node.Upyun.Client(service)
let key
if (path === '/' || !path) {
key = fileName

View File

@@ -1,7 +1,6 @@
import { AuthType, WebDAVClientOptions, createClient } from 'webdav'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
import { IWebdavPlistConfig, PartialKeys } from '#/types/types'
import { formatEndpoint } from '#/utils/common'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
fileName: string
@@ -9,20 +8,20 @@ interface IConfigMap {
}
export default class WebdavApi {
static async delete(configMap: IConfigMap): Promise<boolean> {
static async delete (configMap: IConfigMap): Promise<boolean> {
const {
fileName,
config: { host, username, password, path, sslEnabled, authType }
} = configMap
const endpoint = formatEndpoint(host, sslEnabled)
const options: WebDAVClientOptions = {
const options: any = {
username,
password
}
if (authType === 'digest') {
options.authType = AuthType.Digest
options.authType = window.node.webdav.AuthType.Digest
}
const ctx = createClient(endpoint, options)
const ctx = window.node.webdav.createClient(endpoint, options)
let key
if (path === '/' || !path) {
key = fileName