mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-01 08:59:48 +08:00
🐛 Fix(custom): fix delete bug when using in render process
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
14
src/renderer/utils/deleteLog.ts
Normal file
14
src/renderer/utils/deleteLog.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { ILogType, IRPCActionType } from '#/types/enum'
|
||||
|
||||
export const deleteLog = (fileName?: string, type?: string, isSuccess = true, msg?: string) => {
|
||||
window.electron.sendRPC(
|
||||
IRPCActionType.GALLERY_LOG_DELETE_MSG,
|
||||
msg || `Delete ${fileName} on ${type} success`,
|
||||
isSuccess ? ILogType.success : ILogType.error
|
||||
)
|
||||
}
|
||||
|
||||
export const deleteFailedLog = (fileName: string, type: string, error: any) => {
|
||||
deleteLog(fileName, type, false)
|
||||
window.electron.sendRPC(IRPCActionType.GALLERY_LOG_DELETE_MSG, error, ILogType.error)
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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[]>([])
|
||||
|
||||
Reference in New Issue
Block a user