mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-10 22:28:13 -05:00
30 lines
744 B
TypeScript
30 lines
744 B
TypeScript
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) {
|
|
console.log(error)
|
|
return false
|
|
}
|
|
}
|
|
}
|