🐛 Fix(custom): fix delete bug when using in render process

This commit is contained in:
Kuingsmile
2025-07-31 23:23:51 +08:00
parent b7d7badda9
commit 89976c73a9
36 changed files with 78 additions and 729 deletions

1
.gitignore vendored
View File

@@ -29,3 +29,4 @@ cloc.exe
desktop.ini
/dist
/out
/release

View File

@@ -7,6 +7,7 @@
"buildResources": "build"
},
"files": [
"out/**/*",
"dist/**/*",
"resources/**/*",
"package.json"

View File

@@ -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",

View File

@@ -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)
}
})

View File

@@ -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,

View File

@@ -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<IQiniuConfig, 'path'>
@@ -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) => {

View File

@@ -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
}
]

View File

@@ -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 }

View File

@@ -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
},

View File

@@ -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<boolean> {
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
}
}
}

View File

@@ -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<boolean> {
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
}
}
}

View File

@@ -1,31 +0,0 @@
import { IAliYunConfig, PartialKeys } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
fileName: string
config: PartialKeys<IAliYunConfig, 'path'>
}
export default class AliyunApi {
static #getKey (fileName: string, path?: string): string {
return path && path !== '/' ? `${path.replace(/^\/+|\/+$/, '')}/${fileName}` : fileName
}
static async delete (configMap: IConfigMap): Promise<boolean> {
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
}
}
}

View File

@@ -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<boolean> {
const api = apiMap[configMap.type]
return api ? await api.delete(configMap) : false
return (await window.electron.triggerRPC(IRPCActionType.DELETE_ALL_API, getRawData(configMap))) || false
}
}

View File

@@ -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<boolean> {
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
}
}
}

View File

@@ -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<boolean> {
try {
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,51 +0,0 @@
import { IGitHubConfig, PartialKeys } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
fileName: string
hash: string
config: PartialKeys<IGitHubConfig, 'path'>
}
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<boolean> {
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
}
}
}

View File

@@ -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<boolean> {
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
}
}
}

View File

@@ -1,44 +0,0 @@
import axios, { AxiosResponse } from 'axios'
import { IImgurConfig } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
config?: Partial<IImgurConfig>
hash?: string
}
export default class ImgurApi {
static #baseUrl = 'https://api.imgur.com/3'
static async delete (configMap: IConfigMap): Promise<boolean> {
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
}
}
}

View File

@@ -1,24 +0,0 @@
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
hash: string
}
export default class LocalApi {
static async delete (configMap: IConfigMap): Promise<boolean> {
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
}
}
}

View File

@@ -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<boolean> {
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
}
}
}

View File

@@ -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<boolean> {
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
}
}
}

View File

@@ -1,44 +0,0 @@
import { IQiniuConfig, PartialKeys } from '#/types/types'
import { deleteFailedLog, deleteLog } from '~/utils/deleteLog'
interface IConfigMap {
fileName: string
config: PartialKeys<IQiniuConfig, 'path'>
}
export default class QiniuApi {
static async delete (configMap: IConfigMap): Promise<boolean> {
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
}
}
}

View File

@@ -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<boolean> {
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
}
}
}

View File

@@ -1,43 +0,0 @@
import { ISMMSConfig } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
hash?: string
config?: Partial<ISMMSConfig>
}
export default class SmmsApi {
static readonly #baseUrl = 'https://smms.app/api/v2'
static async delete (configMap: IConfigMap): Promise<boolean> {
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
}
}
}

View File

@@ -1,45 +0,0 @@
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): any {
return new window.node.COS({
SecretId,
SecretKey
})
}
static async delete (configMap: IConfigMap): Promise<boolean> {
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
}
}
}

View File

@@ -1,36 +0,0 @@
import { IUpYunConfig, PartialKeys } from '#/types/types'
import { deleteFailedLog, deleteLog } from '#/utils/deleteLog'
interface IConfigMap {
fileName: string
config: PartialKeys<IUpYunConfig, 'path'>
}
export default class UpyunApi {
static async delete (configMap: IConfigMap): Promise<boolean> {
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
}
}
}

View File

@@ -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<IWebdavPlistConfig, 'path'>
}
export default class WebdavApi {
static async delete (configMap: IConfigMap): Promise<boolean> {
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
}
}
}

View File

@@ -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)

View File

@@ -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'))

View File

@@ -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)
}
}

View File

@@ -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
})

View File

@@ -3,12 +3,20 @@ import { RELEASE_URL, RELEASE_URL_BACKUP } from '#/utils/static'
export const getLatestVersion = async (): Promise<string> => {
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) {

View File

@@ -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<string>(window.electron.sendRpcSync(IRPCActionType.GET_PLATFORM))
const picBedGlobal = ref<IPicBedType[]>([])

View File

@@ -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',

View File

@@ -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