From 875d034f4efc5e49b86848d7de610ca770290817 Mon Sep 17 00:00:00 2001 From: Kuingsmile Date: Wed, 3 Jul 2024 20:56:49 +0800 Subject: [PATCH] :sparkles: Feature(custom): add build in alist support and fix gallery bug ISSUES CLOSED: #218 --- src/renderer/apis/alistplist.ts | 75 +++++++++++++++++++++++++++++++++ src/renderer/apis/allApi.ts | 2 + src/renderer/pages/Gallery.vue | 5 ++- src/universal/utils/static.ts | 1 + 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/renderer/apis/alistplist.ts diff --git a/src/renderer/apis/alistplist.ts b/src/renderer/apis/alistplist.ts new file mode 100644 index 0000000..7494580 --- /dev/null +++ b/src/renderer/apis/alistplist.ts @@ -0,0 +1,75 @@ +import axios from 'axios' +import path from 'path' + +import { getConfig, saveConfig } from '@/utils/dataSender' +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 tokenStore = await getConfig('picgo-plugin-buildin-alistplist') + if (tokenStore && tokenStore.refreshedAt && Date.now() - tokenStore.refreshedAt < 3600000 && tokenStore.token) { + return tokenStore.token + } + const res = await axios.post(`${url}/api/auth/login`, { + username, + password + }) + if (res.data.code === 200 && res.data.message === 'success') { + const token = res.data.data.token + saveConfig({ + 'picgo-plugin-buildin-alistplist': { + token, + refreshedAt: Date.now() + } + }) + return 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: path.join('/', uploadPath, path.dirname(fileName)), + names: [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/allApi.ts b/src/renderer/apis/allApi.ts index bb3991e..801fb0c 100644 --- a/src/renderer/apis/allApi.ts +++ b/src/renderer/apis/allApi.ts @@ -1,4 +1,5 @@ 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' @@ -17,6 +18,7 @@ import WebdavApi from '@/apis/webdav' const apiMap: IStringKeyMap = { alist: AlistApi, + alistplist: AlistplistApi, aliyun: AliyunApi, 'aws-s3': AwsS3Api, 'aws-s3-plist': AwsS3Api, diff --git a/src/renderer/pages/Gallery.vue b/src/renderer/pages/Gallery.vue index 1c3e3de..705730f 100644 --- a/src/renderer/pages/Gallery.vue +++ b/src/renderer/pages/Gallery.vue @@ -431,6 +431,7 @@ function handleDetectShiftKey(event: KeyboardEvent) { const filterList = computed(() => { return getGallery() }) +console.log(filterList) const isAllSelected = computed(() => { const values = Object.values(choosedList) @@ -474,7 +475,7 @@ function getGallery(): IGalleryItem[] { .map(item => { return { ...item, - src: item.imgUrl || '', + src: item.galleryPath || item.imgUrl || '', key: item.id || `${Date.now()}`, intro: item.fileName || '' } @@ -483,7 +484,7 @@ function getGallery(): IGalleryItem[] { return images.value.map(item => { return { ...item, - src: item.imgUrl || '', + src: item.galleryPath || item.imgUrl || '', key: item.id || `${Date.now()}`, intro: item.fileName || '' } diff --git a/src/universal/utils/static.ts b/src/universal/utils/static.ts index 362e189..2a6958b 100644 --- a/src/universal/utils/static.ts +++ b/src/universal/utils/static.ts @@ -11,6 +11,7 @@ export const refreshDownloadFileTransferList = 'refreshDownloadFileTransferList' export const picBedsCanbeDeleted = [ 'aliyun', 'alist', + 'alistplist', 'aws-s3', 'aws-s3-plist', 'dogecloud',