Feature(custom): add build in alist support and fix gallery bug

ISSUES CLOSED: #218
This commit is contained in:
Kuingsmile 2024-07-03 20:56:49 +08:00
parent 00393995b0
commit 875d034f4e
4 changed files with 81 additions and 2 deletions

View File

@ -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<IStringKeyMap>('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<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: 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
}
}
}

View File

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

View File

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

View File

@ -11,6 +11,7 @@ export const refreshDownloadFileTransferList = 'refreshDownloadFileTransferList'
export const picBedsCanbeDeleted = [
'aliyun',
'alist',
'alistplist',
'aws-s3',
'aws-s3-plist',
'dogecloud',