This commit is contained in:
Hk-Gosuto 2025-02-11 15:05:05 +08:00
parent 318801be1d
commit e1839ff278

View File

@ -14,8 +14,8 @@ export function createWebDavClient(store: SyncStore) {
return { return {
async check() { async check() {
try { try {
const res = await fetch(this.path(folder, proxyUrl), { const res = await fetch(this.path(folder, proxyUrl, "MKCOL"), {
method: "MKCOL", method: "GET",
headers: this.headers(), headers: this.headers(),
}); });
const success = [201, 200, 404, 405, 301, 302, 307, 308].includes( const success = [201, 200, 404, 405, 301, 302, 307, 308].includes(
@ -42,6 +42,10 @@ export function createWebDavClient(store: SyncStore) {
console.log("[WebDav] get key = ", key, res.status, res.statusText); console.log("[WebDav] get key = ", key, res.status, res.statusText);
if (404 == res.status) {
return "";
}
return await res.text(); return await res.text();
}, },
@ -62,7 +66,7 @@ export function createWebDavClient(store: SyncStore) {
authorization: `Basic ${auth}`, authorization: `Basic ${auth}`,
}; };
}, },
path(path: string, proxyUrl: string = "") { path(path: string, proxyUrl: string = "", proxyMethod: string = "") {
if (path.startsWith("/")) { if (path.startsWith("/")) {
path = path.slice(1); path = path.slice(1);
} }
@ -78,9 +82,13 @@ export function createWebDavClient(store: SyncStore) {
let u = new URL(proxyUrl + pathPrefix + path); let u = new URL(proxyUrl + pathPrefix + path);
// add query params // add query params
u.searchParams.append("endpoint", config.endpoint); u.searchParams.append("endpoint", config.endpoint);
proxyMethod && u.searchParams.append("proxy_method", proxyMethod);
url = u.toString(); url = u.toString();
} catch (e) { } catch (e) {
url = pathPrefix + path + "?endpoint=" + config.endpoint; url = pathPrefix + path + "?endpoint=" + config.endpoint;
if (proxyMethod) {
url += "&proxy_method=" + proxyMethod;
}
} }
return url; return url;