Skip to content

Commit

Permalink
✨ Feature: picture upload support webdav now
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Feb 22, 2023
1 parent 399f4e4 commit 1dacd3c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"mime-types": "^2.1.35",
"mitt": "^3.0.0",
"nodejs-file-downloader": "^4.10.6",
"piclist": "^0.0.8",
"piclist": "^0.0.9",
"pinia": "^2.0.32",
"pinia-plugin-persistedstate": "^3.1.0",
"qiniu": "^7.8.0",
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ app.config.globalProperties.$builtInPicBed = [
'tcyun',
'upyun',
'aliyun',
'github'
'github',
'webdavplist'
]
app.config.unwrapInjectedRef = true

Expand Down
4 changes: 3 additions & 1 deletion src/renderer/apis/allApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions src/renderer/apis/webdav.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
}
2 changes: 1 addition & 1 deletion src/renderer/pages/Gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10919,10 +10919,10 @@ performance-now@^2.1.0:
resolved "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==

piclist@^0.0.8:
version "0.0.8"
resolved "https://registry.npmjs.org/piclist/-/piclist-0.0.8.tgz#99d78cb4f288915b8056849c6d4c718704b2df2f"
integrity sha512-aZVSWoP2A78ZMKoGd3HFQP/+EsCpbUcQ8xcaswu7UB4jSUdlkUWDp/Mp0VmvUcgPSlpFFJR7DEcDJ/Q6HMMcJg==
piclist@^0.0.9:
version "0.0.9"
resolved "https://registry.npmjs.org/piclist/-/piclist-0.0.9.tgz#1c610728480594fc7cfd04d3bde5b542ecc910ee"
integrity sha512-ZDNP1uQT3JACUG1s1RhRlB35DuZPFuDlDPrv8aBPdVlfAjO9nuY7ICEZ3qj8AHPQb7R98R8fSJZq8juYMqXPzw==
dependencies:
"@picgo/i18n" "^1.0.0"
"@picgo/store" "^2.0.4"
Expand Down

0 comments on commit 1dacd3c

Please sign in to comment.