Feature: picture upload support webdav now

This commit is contained in:
萌萌哒赫萝
2023-02-22 23:52:38 +08:00
parent 399f4e4cca
commit 1dacd3c663
6 changed files with 39 additions and 8 deletions

View File

@@ -38,7 +38,8 @@ app.config.globalProperties.$builtInPicBed = [
'tcyun',
'upyun',
'aliyun',
'github'
'github',
'webdavplist'
]
app.config.unwrapInjectedRef = true

View File

@@ -6,6 +6,7 @@ import ImgurApi from './imgur'
import GithubApi from './github'
import UpyunApi from './upyun'
import AwsS3Api from './awss3'
import WebdavApi from './webdav'
const apiMap: IStringKeyMap = {
smms: SmmsApi,
@@ -15,7 +16,8 @@ const apiMap: IStringKeyMap = {
imgur: ImgurApi,
github: GithubApi,
upyun: UpyunApi,
'aws-s3': AwsS3Api
'aws-s3': AwsS3Api,
webdavplist: WebdavApi
}
export default class ALLApi {

View File

@@ -0,0 +1,28 @@
import { createClient } from 'webdav'
import { formatEndpoint } from '~/main/manage/utils/common'
export default class WebdavApi {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
const { fileName, config: { host, username, password, path, sslEnabled } } = configMap
const endpoint = formatEndpoint(host, sslEnabled)
const ctx = createClient(
endpoint,
{
username,
password
}
)
let key
if (path === '/' || !path) {
key = fileName
} else {
key = `${path.replace(/^\//, '').replace(/\/$/, '')}/${fileName}`
}
try {
await ctx.deleteFile(key)
return true
} catch (error) {
return false
}
}
}

View File

@@ -425,7 +425,7 @@ function remove (item: ImgInfo) {
}).then(async () => {
const file = await $$db.getById(item.id!)
await $$db.removeById(item.id!)
const picBedsCanbeDeleted = ['smms', 'github', 'imgur', 'tcyun', 'aliyun', 'qiniu', 'upyun', 'aws-s3']
const picBedsCanbeDeleted = ['smms', 'github', 'imgur', 'tcyun', 'aliyun', 'qiniu', 'upyun', 'aws-s3', 'webdavplist']
if (await getConfig('settings.deleteCloudFile')) {
if (item.type !== undefined && picBedsCanbeDeleted.includes(item.type)) {
setTimeout(() => {