diff --git a/.gitignore b/.gitignore index 0ba49d53..fde7382f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ cloc.exe desktop.ini /dist /out +/release diff --git a/electron-builder.json b/electron-builder.json index 71c110d9..8cfbb6ab 100644 --- a/electron-builder.json +++ b/electron-builder.json @@ -7,6 +7,7 @@ "buildResources": "build" }, "files": [ + "out/**/*", "dist/**/*", "resources/**/*", "package.json" diff --git a/package.json b/package.json index eca5d295..d2a0d472 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "build:linux": "electron-vite build && electron-builder --linux", "bump": "bump-version", "cz": "git-cz", - "dev": "electron-vite dev", + "dev": "electron-vite dev --watch", "i18n": "node ./scripts/gen-i18n-types.js", "i18n:check": "node ./scripts/find-unused-i18n.js", "i18n:check:verbose": "node ./scripts/find-unused-i18n.js --verbose", diff --git a/src/main/apis/app/system/index.ts b/src/main/apis/app/system/index.ts index 3d8d823e..b8e5f874 100644 --- a/src/main/apis/app/system/index.ts +++ b/src/main/apis/app/system/index.ts @@ -29,6 +29,11 @@ import { isMacOSVersionGreaterThanOrEqualTo } from '~/utils/getMacOSVersion' import pasteTemplate from '~/utils/pasteTemplate' import { hideMiniWindow, openMainWindow, openMiniWindow } from '~/utils/windowHelper' +import menubarPng from '../../../../../resources/menubar.png?asset' +import menubarNewDarwinTemplate from '../../../../../resources/menubar-newdarwinTemplate.png?asset' +import menubarNodarwin from '../../../../../resources/menubar-nodarwin.png?asset' +import uploadPng from '../../../../../resources/upload.png?asset' +import uploadDarkPng from '../../../../../resources/upload-dark.png?asset' let contextMenu: Menu | null export function setDockMenu () { @@ -219,9 +224,9 @@ export function createContextMenu () { const getTrayIcon = () => { if (process.platform === 'darwin') { const isMacOSGreaterThan11 = isMacOSVersionGreaterThanOrEqualTo('11') - return isMacOSGreaterThan11 ? './resources/menubar-newdarwinTemplate.png' : './resources/menubar.png' + return isMacOSGreaterThan11 ? menubarNewDarwinTemplate : menubarPng } else { - return './resources/menubar-nodarwin.png' + return menubarNodarwin } } @@ -291,9 +296,9 @@ export function createTray (tooltip: string) { tray.on('drag-enter', () => { if (nativeTheme.shouldUseDarkColors) { - tray!.setImage('./resources/upload-dark.png') + tray!.setImage(uploadDarkPng) } else { - tray!.setImage('./resources/upload.png') + tray!.setImage(uploadPng) } }) diff --git a/src/main/apis/app/window/windowList.ts b/src/main/apis/app/window/windowList.ts index 87dd8d97..26f37645 100644 --- a/src/main/apis/app/window/windowList.ts +++ b/src/main/apis/app/window/windowList.ts @@ -12,6 +12,7 @@ import { IBrowserWindowOptions } from '#/types/types' import { configPaths } from '#/utils/configPaths' import { T } from '~/i18n' +import logo from '../../../../../resources/logo.png?asset' import { MANUAL_WINDOW_URL, MINI_WINDOW_URL, @@ -111,7 +112,7 @@ if (process.platform !== 'darwin') { settingWindowOptions.frame = false settingWindowOptions.backgroundColor = '#3f3c37' settingWindowOptions.transparent = false - settingWindowOptions.icon = '.resources/logo.png' + settingWindowOptions.icon = '../../../../../resources/logo.png' } const miniWindowOptions = { @@ -123,7 +124,7 @@ const miniWindowOptions = { skipTaskbar: true, resizable: false, transparent: process.platform !== 'linux', - icon: './resources/logo.png', + icon: logo, webPreferences: { sandbox: false, preload: preloadPath, @@ -172,7 +173,7 @@ const toolboxWindowOptions = { resizable: false, title: `PicList ${T('TOOLBOX')}`, vibrancy: 'ultra-dark', - icon: './resources/logo.png', + icon: logo, webPreferences: { sandbox: false, backgroundThrottling: false, diff --git a/src/main/apis/delete/qiniu.ts b/src/main/apis/delete/qiniu.ts index 2cbe910b..899dcdc0 100644 --- a/src/main/apis/delete/qiniu.ts +++ b/src/main/apis/delete/qiniu.ts @@ -1,6 +1,7 @@ +import qiniu from 'qiniu' + import { IQiniuConfig, PartialKeys } from '#/types/types' import { deleteFailedLog, deleteLog } from '~/utils/deleteLog' - interface IConfigMap { fileName: string config: PartialKeys @@ -12,10 +13,10 @@ export default class QiniuApi { fileName, config: { accessKey, secretKey, bucket, path } } = configMap - const mac = new window.node.qiniu.auth.digest.Mac(accessKey, secretKey) - const qiniuConfig = new window.node.qiniu.conf.Config() + const mac = new qiniu.auth.digest.Mac(accessKey, secretKey) + const qiniuConfig = new qiniu.conf.Config() try { - const bucketManager = new window.node.qiniu.rs.BucketManager(mac, qiniuConfig) + const bucketManager = new qiniu.rs.BucketManager(mac, qiniuConfig) const formattedPath = path?.replace(/^\/+|\/+$/, '') || '' const key = path === '/' || !path ? fileName : `${formattedPath}/${fileName}` const res = (await new Promise((resolve, reject) => { diff --git a/src/main/events/rpc/routes/picbed/delete.ts b/src/main/events/rpc/routes/picbed/delete.ts new file mode 100644 index 00000000..497626c1 --- /dev/null +++ b/src/main/events/rpc/routes/picbed/delete.ts @@ -0,0 +1,15 @@ +import ALLApi from 'apis/delete/allApi' + +import { IRPCActionType, IRPCType } from '#/types/enum' +import { IIPCEvent } from '#/types/rpc' +import { ImgInfo } from '#/types/types' + +export default [ + { + action: IRPCActionType.DELETE_ALL_API, + handler: async (_: IIPCEvent, args:[item: ImgInfo]) => { + return await ALLApi.delete(args[0]) + }, + type: IRPCType.INVOKE + } +] diff --git a/src/main/events/rpc/routes/picbed/index.ts b/src/main/events/rpc/routes/picbed/index.ts index a3586c58..07be42d8 100644 --- a/src/main/events/rpc/routes/picbed/index.ts +++ b/src/main/events/rpc/routes/picbed/index.ts @@ -4,6 +4,7 @@ import { IRPCActionType, IRPCType } from '#/types/enum' import { IIPCEvent } from '#/types/rpc' import { IStringKeyMap } from '#/types/types' import { RPCRouter } from '~/events/rpc/router' +import deleteRoutes from '~/events/rpc/routes/picbed/delete' import { deleteUploaderConfig, getUploaderConfigList, @@ -94,6 +95,8 @@ const picbedRoutes = [ } ] -picbedRouter.addBatch(picbedRoutes) +const picBedsRoutes = [...picbedRoutes, ...deleteRoutes] + +picbedRouter.addBatch(picBedsRoutes) export { picbedRouter } diff --git a/src/preload/index.ts b/src/preload/index.ts index dcdbeb27..f92927e7 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -1,17 +1,12 @@ -// TODO Octokit axios webdav +// TODO axios import crypto from 'node:crypto' -import https from 'node:https' import path from 'node:path' import { I18n, ObjectAdapter } from '@piclist/i18n' -import OSS from 'ali-oss' -import COS from 'cos-nodejs-sdk-v5' import { clipboard, contextBridge, ipcRenderer, webFrame } from 'electron' import fs from 'fs-extra' import yaml from 'js-yaml' import mime from 'mime-types' -import qiniu from 'qiniu' -import Upyun from 'upyun' import { isReactive, isRef, toRaw, unref } from 'vue' import { RPC_ACTIONS, RPC_ACTIONS_INVOKE } from '#/events/constants' @@ -93,20 +88,6 @@ try { randomBytes: crypto.randomBytes, createHash: crypto.createHash }, - https: { - Agent: https.Agent - }, - qiniu: { - auth: qiniu.auth, - rs: qiniu.rs, - conf: qiniu.conf - }, - COS, - OSS, - Upyun: { - Service: Upyun.Service, - Client: Upyun.Client - }, yaml: { load: yaml.load }, diff --git a/src/renderer/apis/alist.ts b/src/renderer/apis/alist.ts deleted file mode 100644 index 0b5f9068..00000000 --- a/src/renderer/apis/alist.ts +++ /dev/null @@ -1,47 +0,0 @@ -import axios from 'axios' - -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - fileName: string - config: { - version: string - url: string - uploadPath: string - token: string - } -} - -export default class AlistApi { - static async delete (configMap: IConfigMap): Promise { - const { fileName, config } = configMap - try { - const { version, url, uploadPath, token } = config - if (String(version) === '2') { - deleteLog(fileName, 'Alist', false, 'Alist version 2 is not supported, deletion is skipped') - return true - } - const result = await axios.request({ - method: 'post', - url: `${url}/api/fs/remove`, - headers: { - 'Content-Type': 'application/json', - Authorization: token - }, - data: { - dir: window.node.path.join('/', uploadPath, window.node.path.dirname(fileName)), - names: [window.node.path.basename(fileName)] - } - }) - if (result.data.code === 200) { - deleteLog(fileName, 'Alist') - return true - } - deleteLog(fileName, 'Alist', false) - return false - } catch (error: any) { - deleteFailedLog(fileName, 'Alist', error) - return false - } - } -} diff --git a/src/renderer/apis/alistplist.ts b/src/renderer/apis/alistplist.ts deleted file mode 100644 index 240e3d3a..00000000 --- a/src/renderer/apis/alistplist.ts +++ /dev/null @@ -1,62 +0,0 @@ -import axios from 'axios' - -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - fileName: string - config: { - url: string - username: string - password: string - uploadPath: string - token: string - } -} - -const getAListToken = async (url: string, username: string, password: string) => { - const res = await axios.post(`${url}/api/auth/login`, { - username, - password - }) - if (res.data.code === 200 && res.data.message === 'success') { - return res.data.data.token - } -} - -export default class AListplistApi { - static async delete (configMap: IConfigMap): Promise { - const { fileName, config } = configMap - try { - const { url, username, password, uploadPath } = config - let token = config.token - if (!token) { - token = await getAListToken(url, username, password) - } - if (!url || !(token || (username && password))) { - deleteFailedLog(fileName, 'Alist', 'No valid token or username/password provided') - return false - } - const result = await axios.request({ - method: 'post', - url: `${url}/api/fs/remove`, - headers: { - 'Content-Type': 'application/json', - Authorization: token - }, - data: { - dir: window.node.path.join('/', uploadPath, window.node.path.dirname(fileName)), - names: [window.node.path.basename(fileName)] - } - }) - if (result.data.code === 200) { - deleteLog(fileName, 'Alist') - return true - } - deleteLog(fileName, 'Alist', false) - return false - } catch (error: any) { - deleteFailedLog(fileName, 'Alist', error) - return false - } - } -} diff --git a/src/renderer/apis/aliyun.ts b/src/renderer/apis/aliyun.ts deleted file mode 100644 index d85b8f45..00000000 --- a/src/renderer/apis/aliyun.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { IAliYunConfig, PartialKeys } from '#/types/types' -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - fileName: string - config: PartialKeys -} - -export default class AliyunApi { - static #getKey (fileName: string, path?: string): string { - return path && path !== '/' ? `${path.replace(/^\/+|\/+$/, '')}/${fileName}` : fileName - } - - static async delete (configMap: IConfigMap): Promise { - const { fileName, config } = configMap - try { - 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) { - deleteLog(fileName, 'Aliyun') - return true - } - deleteLog(fileName, 'Aliyun', false) - return false - } catch (error: any) { - deleteFailedLog(fileName, 'Aliyun', error) - return false - } - } -} diff --git a/src/renderer/apis/allApi.ts b/src/renderer/apis/allApi.ts index 8140b5cb..1ee6df5d 100644 --- a/src/renderer/apis/allApi.ts +++ b/src/renderer/apis/allApi.ts @@ -1,46 +1,9 @@ -import AlistApi from '@/apis/alist' -import AlistplistApi from '@/apis/alistplist' -import AliyunApi from '@/apis/aliyun' -import AwsS3Api from '@/apis/awss3' -import DogeCloudApi from '@/apis/dogecloud' -import GithubApi from '@/apis/github' -import HuaweicloudApi from '@/apis/huaweiyun' -import ImgurApi from '@/apis/imgur' -import LocalApi from '@/apis/local' -import LskyplistApi from '@/apis/lskyplist' -import PiclistApi from '@/apis/piclist' -import QiniuApi from '@/apis/qiniu' -import SftpPlistApi from '@/apis/sftpplist' -import SmmsApi from '@/apis/smms' -import TcyunApi from '@/apis/tcyun' -import UpyunApi from '@/apis/upyun' -import WebdavApi from '@/apis/webdav' +import { getRawData } from '@/utils/common' +import { IRPCActionType } from '#/types/enum' import { IStringKeyMap } from '#/types/types' -const apiMap: IStringKeyMap = { - alist: AlistApi, - alistplist: AlistplistApi, - aliyun: AliyunApi, - 'aws-s3': AwsS3Api, - 'aws-s3-plist': AwsS3Api, - dogecloud: DogeCloudApi, - github: GithubApi, - 'huaweicloud-uploader': HuaweicloudApi, - imgur: ImgurApi, - local: LocalApi, - lskyplist: LskyplistApi, - piclist: PiclistApi, - qiniu: QiniuApi, - sftpplist: SftpPlistApi, - smms: SmmsApi, - tcyun: TcyunApi, - upyun: UpyunApi, - webdavplist: WebdavApi -} - export default class ALLApi { static async delete (configMap: IStringKeyMap): Promise { - const api = apiMap[configMap.type] - return api ? await api.delete(configMap) : false + return (await window.electron.triggerRPC(IRPCActionType.DELETE_ALL_API, getRawData(configMap))) || false } } diff --git a/src/renderer/apis/awss3.ts b/src/renderer/apis/awss3.ts deleted file mode 100644 index f367e73f..00000000 --- a/src/renderer/apis/awss3.ts +++ /dev/null @@ -1,15 +0,0 @@ -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 { - try { - 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 - } - } -} diff --git a/src/renderer/apis/dogecloud.ts b/src/renderer/apis/dogecloud.ts deleted file mode 100644 index 7c0bf73c..00000000 --- a/src/renderer/apis/dogecloud.ts +++ /dev/null @@ -1,15 +0,0 @@ -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 { - try { - return (await window.electron.triggerRPC(IRPCActionType.GALLERY_DELETE_DOGE_FILE, getRawData(configMap))) || false - } catch (error: any) { - deleteFailedLog(configMap.fileName, 'DogeCloud', error) - return false - } - } -} diff --git a/src/renderer/apis/github.ts b/src/renderer/apis/github.ts deleted file mode 100644 index 0c25b7ea..00000000 --- a/src/renderer/apis/github.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { IGitHubConfig, PartialKeys } from '#/types/types' -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - fileName: string - hash: string - config: PartialKeys -} - -export default class GithubApi { - static #createOctokit (token: string) { - return new window.node.Octokit({ - auth: token - }) - } - - 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 { - const { - fileName, - hash, - config: { repo, token, branch, path } - } = configMap - const [owner, repoName] = repo.split('/') - const octokit = GithubApi.#createOctokit(token) - const key = GithubApi.#createKey(path, fileName) - try { - const { status } = await octokit.rest.repos.deleteFile({ - owner, - repo: repoName, - path: key, - message: `delete ${fileName} by PicList`, - sha: hash, - branch - }) - if (status === 200) { - deleteLog(fileName, 'GitHub') - return true - } - deleteLog(fileName, 'GitHub', false) - return false - } catch (error: any) { - deleteFailedLog(fileName, 'GitHub', error) - return false - } - } -} diff --git a/src/renderer/apis/huaweiyun.ts b/src/renderer/apis/huaweiyun.ts deleted file mode 100644 index 1646fcfc..00000000 --- a/src/renderer/apis/huaweiyun.ts +++ /dev/null @@ -1,15 +0,0 @@ -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 { - try { - return (await window.electron.triggerRPC(IRPCActionType.GALLERY_DELETE_HUAWEI_OSS_FILE, getRawData(configMap))) || false - } catch (error: any) { - deleteFailedLog(configMap.fileName, 'HuaweiCloud', error) - return false - } - } -} diff --git a/src/renderer/apis/imgur.ts b/src/renderer/apis/imgur.ts deleted file mode 100644 index 61bdad97..00000000 --- a/src/renderer/apis/imgur.ts +++ /dev/null @@ -1,44 +0,0 @@ -import axios, { AxiosResponse } from 'axios' - -import { IImgurConfig } from '#/types/types' -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - config?: Partial - hash?: string -} - -export default class ImgurApi { - static #baseUrl = 'https://api.imgur.com/3' - - static async delete (configMap: IConfigMap): Promise { - const { config: { clientId = '', username = '', accessToken = '' } = {}, hash = '' } = configMap - let Authorization: string, apiUrl: string - - if (username && accessToken) { - Authorization = `Bearer ${accessToken}` - apiUrl = `${ImgurApi.#baseUrl}/account/${username}/image/${hash}` - } else if (clientId) { - Authorization = `Client-ID ${clientId}` - apiUrl = `${ImgurApi.#baseUrl}/image/${hash}` - } else { - deleteLog(hash, 'Imgur', false, 'No credentials found') - return false - } - try { - const response: AxiosResponse = await axios.delete(apiUrl, { - headers: { Authorization }, - timeout: 30000 - }) - if (response.status === 200) { - deleteLog(hash, 'Imgur') - return true - } - deleteLog(hash, 'Imgur', false) - return false - } catch (error: any) { - deleteFailedLog(hash, 'Imgur', error) - return false - } - } -} diff --git a/src/renderer/apis/local.ts b/src/renderer/apis/local.ts deleted file mode 100644 index 426fc06a..00000000 --- a/src/renderer/apis/local.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - hash: string -} - -export default class LocalApi { - static async delete (configMap: IConfigMap): Promise { - const { hash } = configMap - if (!hash) { - deleteLog(hash, 'Local', false, 'Local.delete: invalid params') - return false - } - - try { - await window.node.fs.remove(hash) - deleteLog(hash, 'Local') - return true - } catch (error: any) { - deleteFailedLog(hash, 'Local', error) - return false - } - } -} diff --git a/src/renderer/apis/lskyplist.ts b/src/renderer/apis/lskyplist.ts deleted file mode 100644 index f37fdd7e..00000000 --- a/src/renderer/apis/lskyplist.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { IStringKeyMap } from '#/types/types' -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -export default class LskyplistApi { - static async delete (configMap: IStringKeyMap): Promise { - const { hash, config } = configMap - if (!hash || !config || !config.token) { - deleteLog(hash, 'Lskyplist', false, 'LskyplistApi.delete: invalid params') - return false - } - - const { host, token, version } = config - if (version !== 'V2') { - deleteLog(hash, 'Lskyplist', false, 'LskyplistApi.delete: invalid version') - return false - } - - const v2Headers = { - Accept: 'application/json', - Authorization: token || undefined - } - - const requestAgent = new window.node.https.Agent({ - rejectUnauthorized: false - }) - try { - const response: any = await window.node.axios.delete(`${host}/api/v1/images/${hash}`, { - headers: v2Headers, - timeout: 30000, - httpsAgent: requestAgent - }) - if (response.status === 200 && response.data.status === true) { - deleteLog(hash, 'Lskyplist') - return true - } - deleteLog(hash, 'Lskyplist', false) - return false - } catch (error: any) { - deleteFailedLog(hash, 'Lskyplist', error) - return false - } - } -} diff --git a/src/renderer/apis/piclist.ts b/src/renderer/apis/piclist.ts deleted file mode 100644 index 2130378e..00000000 --- a/src/renderer/apis/piclist.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { IStringKeyMap } from '#/types/types' -import { deleteFailedLog, deleteLog } from '~/utils/deleteLog' - -export default class PiclistApi { - static async delete (configMap: IStringKeyMap): Promise { - const { config, fullResult } = configMap - const { host, port } = config - if (!fullResult) return true - - if (!host) { - deleteLog(fullResult, 'Piclist', false, 'PiclistApi.delete: invalid params') - return false - } - - const url = `http://${host || '127.0.0.1'}:${port || 36677}/delete` - - try { - const response: any = await window.node.axios.post(url, { - list: [fullResult] - }) - if (response.status === 200 && response.data?.success) { - deleteLog(fullResult, 'Piclist') - return true - } - deleteLog(fullResult, 'Piclist', false) - return false - } catch (error: any) { - deleteFailedLog(fullResult, 'Piclist', error) - return false - } - } -} diff --git a/src/renderer/apis/qiniu.ts b/src/renderer/apis/qiniu.ts deleted file mode 100644 index 2cbe910b..00000000 --- a/src/renderer/apis/qiniu.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { IQiniuConfig, PartialKeys } from '#/types/types' -import { deleteFailedLog, deleteLog } from '~/utils/deleteLog' - -interface IConfigMap { - fileName: string - config: PartialKeys -} - -export default class QiniuApi { - static async delete (configMap: IConfigMap): Promise { - const { - fileName, - config: { accessKey, secretKey, bucket, path } - } = configMap - const mac = new window.node.qiniu.auth.digest.Mac(accessKey, secretKey) - const qiniuConfig = new window.node.qiniu.conf.Config() - try { - 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) => { - bucketManager.delete(bucket, key, (err, respBody, respInfo) => { - if (err) { - reject(err) - } else { - resolve({ - respBody, - respInfo - }) - } - }) - })) as any - if (res?.respInfo?.statusCode === 200) { - deleteLog(fileName, 'Qiniu') - return true - } - deleteLog(fileName, 'Qiniu', false) - return false - } catch (error: any) { - deleteFailedLog(fileName, 'Qiniu', error) - return false - } - } -} diff --git a/src/renderer/apis/sftpplist.ts b/src/renderer/apis/sftpplist.ts deleted file mode 100644 index a8f13eca..00000000 --- a/src/renderer/apis/sftpplist.ts +++ /dev/null @@ -1,16 +0,0 @@ -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 { - const { fileName, config } = configMap - try { - return (await window.electron.triggerRPC(IRPCActionType.GALLERY_DELETE_SFTP_FILE, getRawData(config), fileName)) || false - } catch (error: any) { - deleteFailedLog(fileName, 'SFTP', error) - return false - } - } -} diff --git a/src/renderer/apis/smms.ts b/src/renderer/apis/smms.ts deleted file mode 100644 index ffd883e8..00000000 --- a/src/renderer/apis/smms.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { ISMMSConfig } from '#/types/types' -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - hash?: string - config?: Partial -} - -export default class SmmsApi { - static readonly #baseUrl = 'https://smms.app/api/v2' - - static async delete (configMap: IConfigMap): Promise { - const { hash, config } = configMap - if (!hash || !config || !config.token) { - deleteLog(hash, 'Smms', false, 'SmmsApi.delete: invalid params') - return false - } - - const { token } = config - - try { - const response: any = await window.node.axios.get(`${SmmsApi.#baseUrl}/delete/${hash}`, { - headers: { - Authorization: token - }, - params: { - hash, - format: 'json' - }, - timeout: 30000 - }) - if (response.status === 200) { - deleteLog(hash, 'Smms') - return true - } - deleteLog(hash, 'Smms', false) - return false - } catch (error: any) { - deleteFailedLog(hash, 'Smms', error) - return false - } - } -} diff --git a/src/renderer/apis/tcyun.ts b/src/renderer/apis/tcyun.ts deleted file mode 100644 index c1b241fe..00000000 --- a/src/renderer/apis/tcyun.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { ITcYunConfig, PartialKeys } from '#/types/types' -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - fileName: string - config: PartialKeys -} -export default class TcyunApi { - static #createCOS (SecretId: string, SecretKey: string): any { - return new window.node.COS({ - SecretId, - SecretKey - }) - } - - static async delete (configMap: IConfigMap): Promise { - const { - fileName, - config: { secretId, secretKey, bucket, area, path } - } = configMap - try { - const cos = TcyunApi.#createCOS(secretId, secretKey) - let key - if (path === '/' || !path) { - key = `/${fileName}` - } else { - key = `/${path.replace(/^\/+|\/+$/, '')}/${fileName}` - } - const result = await cos.deleteObject({ - Bucket: bucket, - Region: area, - Key: key - }) - if (result.statusCode === 204) { - deleteLog(fileName, 'Tcyun') - return true - } - deleteLog(fileName, 'Tcyun', false) - return false - } catch (error: any) { - deleteFailedLog(fileName, 'Tcyun', error) - return false - } - } -} diff --git a/src/renderer/apis/upyun.ts b/src/renderer/apis/upyun.ts deleted file mode 100644 index 4666cf84..00000000 --- a/src/renderer/apis/upyun.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { IUpYunConfig, PartialKeys } from '#/types/types' -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - fileName: string - config: PartialKeys -} - -export default class UpyunApi { - static async delete (configMap: IConfigMap): Promise { - const { - fileName, - config: { bucket, operator, password, path } - } = configMap - try { - 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 - } else { - key = `${path.replace(/^\/+|\/+$/, '')}/${fileName}` - } - const result = await client.deleteFile(key) - if (result) { - deleteLog(fileName, 'Upyun') - return true - } - deleteLog(fileName, 'Upyun', false) - return false - } catch (error: any) { - deleteFailedLog(fileName, 'Upyun', error) - return false - } - } -} diff --git a/src/renderer/apis/webdav.ts b/src/renderer/apis/webdav.ts deleted file mode 100644 index afae0480..00000000 --- a/src/renderer/apis/webdav.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { IWebdavPlistConfig, PartialKeys } from '#/types/types' -import { formatEndpoint } from '#/utils/common' -import { deleteFailedLog, deleteLog } from '#/utils/deleteLog' - -interface IConfigMap { - fileName: string - config: PartialKeys -} - -export default class WebdavApi { - static async delete (configMap: IConfigMap): Promise { - const { - fileName, - config: { host, username, password, path, sslEnabled, authType } - } = configMap - const endpoint = formatEndpoint(host, sslEnabled) - const options: any = { - username, - password - } - if (authType === 'digest') { - options.authType = window.node.webdav.AuthType.Digest - } - const ctx = window.node.webdav.createClient(endpoint, options) - let key - if (path === '/' || !path) { - key = fileName - } else { - key = `${path.replace(/^\/+|\/+$/, '')}/${fileName}` - } - try { - await ctx.deleteFile(key) - deleteLog(fileName, 'WebDAV') - return true - } catch (error: any) { - deleteFailedLog(fileName, 'WebDAV', error) - return false - } - } -} diff --git a/src/renderer/main.ts b/src/renderer/main.ts index 0df2283e..44a5ddae 100644 --- a/src/renderer/main.ts +++ b/src/renderer/main.ts @@ -33,8 +33,8 @@ app.config.globalProperties.sendToMain = window.electron.sendToMain const pinia = createPinia() pinia.use(piniaPluginPersistedstate) app.use(VueLazyLoad, { - loading: 'file://loading.jpg', - error: 'file://unknown-file-type.svg', + loading: '/loading.jpg', + error: '/unknown-file-type.svg', delay: 500 }) app.use(ElementUI) diff --git a/src/renderer/manage/pages/BucketPage.vue b/src/renderer/manage/pages/BucketPage.vue index 750d50c3..ed7d6503 100644 --- a/src/renderer/manage/pages/BucketPage.vue +++ b/src/renderer/manage/pages/BucketPage.vue @@ -2122,8 +2122,8 @@ async function handleClickFile (item: any) { type: 'success' }) const fileUrl = item.url - const res = await window.node.axios.get(fileUrl, options) - const content = res.data + const res = await fetch(fileUrl, options) + const content = await res.text() markDownContent.value = await marked.parse(content) isShowMarkDownDialog.value = true } catch (error) { @@ -2140,8 +2140,8 @@ async function handleClickFile (item: any) { type: 'success' }) const fileUrl = item.url - const res = await window.node.axios.get(fileUrl, options) - textfileContent.value = res.data + const res = await fetch(fileUrl, options) + textfileContent.value = await res.text() isShowTextFileDialog.value = true } catch (error) { ElMessage.error($T('MANAGE_BUCKET_END_LOADING_MESSAGE_FAIL')) diff --git a/src/renderer/manage/utils/digestAuth.ts b/src/renderer/manage/utils/digestAuth.ts index e868d403..a4d78d95 100644 --- a/src/renderer/manage/utils/digestAuth.ts +++ b/src/renderer/manage/utils/digestAuth.ts @@ -68,10 +68,11 @@ export function digestAuthHeader ( export async function getAuthHeader (method: string, host: string, uri: string, username: string, password: string) { try { - await window.node.axios.get(`${host}${uri}`) - } catch (error: any) { - if (error.response.status === 401 && error.response.headers['www-authenticate']) { - return digestAuthHeader(method, uri, error.response.headers['www-authenticate'], username, password) + const response = await fetch(`${host}${uri}`) + if (response.status === 401 && response.headers.get('www-authenticate')) { + return digestAuthHeader(method, uri, response.headers.get('www-authenticate')!, username, password) } + } catch (error: any) { + console.error('Network error:', error) } } diff --git a/src/renderer/pages/Plugin.vue b/src/renderer/pages/Plugin.vue index ee77b3d1..1eb1f71f 100644 --- a/src/renderer/pages/Plugin.vue +++ b/src/renderer/pages/Plugin.vue @@ -248,7 +248,7 @@ import { PICGO_TOGGLE_PLUGIN } from '#/events/constants' import { IRPCActionType } from '#/types/enum' -import { INPMSearchResult, INPMSearchResultObject, IPicGoPlugin } from '#/types/types' +import { INPMSearchResultObject, IPicGoPlugin } from '#/types/types' import { handleStreamlinePluginName } from '#/utils/common' import { configPaths } from '#/utils/configPaths' @@ -299,8 +299,9 @@ watch(dialogVisible, (val: boolean) => { async function getLatestVersionOfPlugIn (pluginName: string) { try { - const res = await window.node.axios.get(`https://registry.npmjs.com/${pluginName}`) - latestVersionMap[pluginName] = res.data['dist-tags'].latest + const res = await fetch(`https://registry.npmjs.com/${pluginName}`) + const data = await res.json() + latestVersionMap[pluginName] = data['dist-tags'].latest } catch (err) { console.error(err) } @@ -510,10 +511,10 @@ async function handleConfirmConfig () { } function _getSearchResult (val: string) { - window.node.axios - .get(`https://registry.npmjs.com/-/v1/search?text=${val}`) - .then((res: INPMSearchResult) => { - pluginList.value = res.data.objects + fetch(`https://registry.npmjs.com/-/v1/search?text=${val}`) + .then(async (res: Response) => { + const data = await res.json() + pluginList.value = data.objects .filter((item: INPMSearchResultObject) => { return item.package.name.includes('picgo-plugin-') }) @@ -522,7 +523,7 @@ function _getSearchResult (val: string) { }) loading.value = false }) - .catch(err => { + .catch((err: any) => { console.log(err) loading.value = false }) diff --git a/src/universal/utils/deleteLog.ts b/src/renderer/utils/deleteLog.ts similarity index 100% rename from src/universal/utils/deleteLog.ts rename to src/renderer/utils/deleteLog.ts diff --git a/src/renderer/utils/getLatestVersion.ts b/src/renderer/utils/getLatestVersion.ts index d6ec3ec1..35ed01d2 100644 --- a/src/renderer/utils/getLatestVersion.ts +++ b/src/renderer/utils/getLatestVersion.ts @@ -3,12 +3,20 @@ import { RELEASE_URL, RELEASE_URL_BACKUP } from '#/utils/static' export const getLatestVersion = async (): Promise => { try { - const { data: normalList } = await window.node.axios.get(RELEASE_URL) + const response = await fetch(RELEASE_URL) + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + const normalList = await response.json() return normalList[0].name } catch (err) { console.error('Error fetching latest version: ', err) try { - const { data } = await window.node.axios.get(`${RELEASE_URL_BACKUP}/latest.yml`) + const response = await fetch(`${RELEASE_URL_BACKUP}/latest.yml`) + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + const data = await response.text() const r = window.node.yaml.load(data) as IStringKeyMap return r.version } catch (err) { diff --git a/src/renderer/utils/global.ts b/src/renderer/utils/global.ts index 2fa13ab5..70a42077 100644 --- a/src/renderer/utils/global.ts +++ b/src/renderer/utils/global.ts @@ -3,7 +3,7 @@ import { ref } from 'vue' import { IRPCActionType } from '#/types/enum' import { IPicBedType } from '#/types/types' -console.log('global.ts loaded', window.node.https) +console.log('global.ts loaded', window.node.crypto.randomBytes(16).toString('hex')) const osGlobal = ref(window.electron.sendRpcSync(IRPCActionType.GET_PLATFORM)) const picBedGlobal = ref([]) diff --git a/src/universal/types/enum.ts b/src/universal/types/enum.ts index 9646a493..c6d5aa2e 100644 --- a/src/universal/types/enum.ts +++ b/src/universal/types/enum.ts @@ -106,6 +106,7 @@ export enum IRPCActionType { UPLOADER_SELECT = 'UPLOADER_SELECT', UPLOADER_UPDATE_CONFIG = 'UPLOADER_UPDATE_CONFIG', UPLOADER_RESET_CONFIG = 'UPLOADER_RESET_CONFIG', + DELETE_ALL_API = 'DELETE_ALL_API', // toolbox rpc TOOLBOX_CHECK = 'TOOLBOX_CHECK', diff --git a/src/universal/types/shims-tsx.d.ts b/src/universal/types/shims-tsx.d.ts index ce00eed7..038bac25 100644 --- a/src/universal/types/shims-tsx.d.ts +++ b/src/universal/types/shims-tsx.d.ts @@ -1,19 +1,11 @@ import crypto from 'node:crypto' -import https from 'node:https' import path from 'node:path' -import { Octokit } from '@octokit/rest' -import OSS from 'ali-oss' -import axios from 'axios' -import COS from 'cos-nodejs-sdk-v5' import { clipboard } from 'electron' import fs from 'fs-extra' import yaml from 'js-yaml' import mime from 'mime-types' -import qiniu from 'qiniu' -import Upyun from 'upyun' import { VNode } from 'vue' -import { AuthType, createClient } from 'webdav' import { IpcRendererListener } from '#/types/electron' import { IRPCActionType } from '#/types/enum' @@ -62,36 +54,14 @@ declare global { readFile: typeof fs.readFile statSync: typeof fs.statSync } - https: { - Agent: typeof https.Agent - } - qiniu: { - auth: typeof qiniu.auth - rs: typeof qiniu.rs - conf: typeof qiniu.conf - } - COS: typeof COS - OSS: typeof OSS - Upyun: { - Service: typeof Upyun.Service - Client: typeof Upyun.Client - } - Octokit: typeof Octokit - axios: { - get: typeof axios.get - delete: typeof axios.delete - post: typeof axios.post - } + yaml: { load: typeof yaml.load } mime: { lookup: typeof mime.lookup } - webdav: { - createClient: typeof createClient - AuthType: typeof AuthType - } + } i18n: { setLocales: (lang: string, locales: ILocales) => void