mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-02-11 17:40:35 +08:00
Merge pull request #4507 from ChatGPTNextWeb/chore-fix
feat: fix codes of joining webdav url in client & webdav proxy
This commit is contained in:
commit
af3ebacee6
@ -42,7 +42,7 @@ async function handle(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const endpointPath = params.path.join("/");
|
const endpointPath = params.path.join("/");
|
||||||
const targetPath = `${endpoint}/${endpointPath}`;
|
const targetPath = `${endpoint}${endpointPath}`;
|
||||||
|
|
||||||
// only allow MKCOL, GET, PUT
|
// only allow MKCOL, GET, PUT
|
||||||
if (req.method !== "MKCOL" && req.method !== "GET" && req.method !== "PUT") {
|
if (req.method !== "MKCOL" && req.method !== "GET" && req.method !== "PUT") {
|
||||||
@ -96,7 +96,7 @@ async function handle(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetUrl = `${endpoint}/${endpointPath}`;
|
const targetUrl = targetPath;
|
||||||
|
|
||||||
const method = req.method;
|
const method = req.method;
|
||||||
const shouldNotHaveBody = ["get", "head"].includes(
|
const shouldNotHaveBody = ["get", "head"].includes(
|
||||||
@ -114,12 +114,23 @@ async function handle(
|
|||||||
duplex: "half",
|
duplex: "half",
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchResult = await fetch(targetUrl, fetchOptions);
|
let fetchResult;
|
||||||
|
|
||||||
console.log("[Any Proxy]", targetUrl, {
|
try {
|
||||||
status: fetchResult.status,
|
fetchResult = await fetch(targetUrl, fetchOptions);
|
||||||
statusText: fetchResult.statusText,
|
} finally {
|
||||||
});
|
console.log(
|
||||||
|
"[Any Proxy]",
|
||||||
|
targetUrl,
|
||||||
|
{
|
||||||
|
method: req.method,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: fetchResult?.status,
|
||||||
|
statusText: fetchResult?.statusText,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return fetchResult;
|
return fetchResult;
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ export const useSyncStore = createPersistStore(
|
|||||||
setLocalAppState(localState);
|
setLocalAppState(localState);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("[Sync] failed to get remote state", e);
|
console.log("[Sync] failed to get remote state", e);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
await client.set(config.username, JSON.stringify(localState));
|
await client.set(config.username, JSON.stringify(localState));
|
||||||
|
@ -63,9 +63,9 @@ export function createWebDavClient(store: SyncStore) {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
path(path: string, proxyUrl: string = "") {
|
path(path: string, proxyUrl: string = "") {
|
||||||
if (!path.endsWith("/")) {
|
// if (!path.endsWith("/")) {
|
||||||
path += "/";
|
// path += "/";
|
||||||
}
|
// }
|
||||||
if (path.startsWith("/")) {
|
if (path.startsWith("/")) {
|
||||||
path = path.slice(1);
|
path = path.slice(1);
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ export function createWebDavClient(store: SyncStore) {
|
|||||||
|
|
||||||
let url;
|
let url;
|
||||||
if (proxyUrl.length > 0 || proxyUrl === "/") {
|
if (proxyUrl.length > 0 || proxyUrl === "/") {
|
||||||
let u = new URL(proxyUrl + "/api/webdav/" + path);
|
let u = new URL(proxyUrl + "api/webdav/" + path);
|
||||||
// add query params
|
// add query params
|
||||||
u.searchParams.append("endpoint", config.endpoint);
|
u.searchParams.append("endpoint", config.endpoint);
|
||||||
url = u.toString();
|
url = u.toString();
|
||||||
|
Loading…
Reference in New Issue
Block a user