mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 10:12:50 +08:00
fix: remove corsFetch
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { STORAGE_KEY } from "@/app/constant";
|
||||
import { SyncStore } from "@/app/store/sync";
|
||||
import { corsFetch } from "../cors";
|
||||
import { chunks } from "../format";
|
||||
|
||||
export type UpstashConfig = SyncStore["upstash"];
|
||||
@@ -18,10 +17,9 @@ export function createUpstashClient(store: SyncStore) {
|
||||
return {
|
||||
async check() {
|
||||
try {
|
||||
const res = await corsFetch(this.path(`get/${storeKey}`), {
|
||||
const res = await fetch(this.path(`get/${storeKey}`, proxyUrl), {
|
||||
method: "GET",
|
||||
headers: this.headers(),
|
||||
proxyUrl,
|
||||
});
|
||||
console.log("[Upstash] check", res.status, res.statusText);
|
||||
return [200].includes(res.status);
|
||||
@@ -32,10 +30,9 @@ export function createUpstashClient(store: SyncStore) {
|
||||
},
|
||||
|
||||
async redisGet(key: string) {
|
||||
const res = await corsFetch(this.path(`get/${key}`), {
|
||||
const res = await fetch(this.path(`get/${key}`, proxyUrl), {
|
||||
method: "GET",
|
||||
headers: this.headers(),
|
||||
proxyUrl,
|
||||
});
|
||||
|
||||
console.log("[Upstash] get key = ", key, res.status, res.statusText);
|
||||
@@ -45,11 +42,10 @@ export function createUpstashClient(store: SyncStore) {
|
||||
},
|
||||
|
||||
async redisSet(key: string, value: string) {
|
||||
const res = await corsFetch(this.path(`set/${key}`), {
|
||||
const res = await fetch(this.path(`set/${key}`, proxyUrl), {
|
||||
method: "POST",
|
||||
headers: this.headers(),
|
||||
body: value,
|
||||
proxyUrl,
|
||||
});
|
||||
|
||||
console.log("[Upstash] set key = ", key, res.status, res.statusText);
|
||||
@@ -84,7 +80,7 @@ export function createUpstashClient(store: SyncStore) {
|
||||
Authorization: `Bearer ${config.apiKey}`,
|
||||
};
|
||||
},
|
||||
path(path: string) {
|
||||
path(path: string, proxyUrl: string = "") {
|
||||
// let url = config.endpoint;
|
||||
|
||||
if (!path.endsWith("/")) {
|
||||
@@ -94,7 +90,11 @@ export function createUpstashClient(store: SyncStore) {
|
||||
path = path.slice(1);
|
||||
}
|
||||
|
||||
let url = new URL("/api/upstash/" + path);
|
||||
if (proxyUrl.length > 0 && !proxyUrl.endsWith("/")) {
|
||||
proxyUrl += "/";
|
||||
}
|
||||
|
||||
let url = new URL(proxyUrl + "/api/upstash/" + path);
|
||||
|
||||
// add query params
|
||||
url.searchParams.append("endpoint", config.endpoint);
|
||||
|
@@ -15,10 +15,9 @@ export function createWebDavClient(store: SyncStore) {
|
||||
return {
|
||||
async check() {
|
||||
try {
|
||||
const res = await corsFetch(this.path(folder), {
|
||||
const res = await fetch(this.path(folder, proxyUrl), {
|
||||
method: "MKCOL",
|
||||
headers: this.headers(),
|
||||
proxyUrl,
|
||||
});
|
||||
console.log("[WebDav] check", res.status, res.statusText);
|
||||
return [201, 200, 404, 301, 302, 307, 308].includes(res.status);
|
||||
@@ -30,10 +29,9 @@ export function createWebDavClient(store: SyncStore) {
|
||||
},
|
||||
|
||||
async get(key: string) {
|
||||
const res = await corsFetch(this.path(fileName), {
|
||||
const res = await fetch(this.path(fileName, proxyUrl), {
|
||||
method: "GET",
|
||||
headers: this.headers(),
|
||||
proxyUrl,
|
||||
});
|
||||
|
||||
console.log("[WebDav] get key = ", key, res.status, res.statusText);
|
||||
@@ -42,11 +40,10 @@ export function createWebDavClient(store: SyncStore) {
|
||||
},
|
||||
|
||||
async set(key: string, value: string) {
|
||||
const res = await corsFetch(this.path(fileName), {
|
||||
const res = await fetch(this.path(fileName, proxyUrl), {
|
||||
method: "PUT",
|
||||
headers: this.headers(),
|
||||
body: value,
|
||||
proxyUrl,
|
||||
});
|
||||
|
||||
console.log("[WebDav] set key = ", key, res.status, res.statusText);
|
||||
@@ -59,7 +56,7 @@ export function createWebDavClient(store: SyncStore) {
|
||||
authorization: `Basic ${auth}`,
|
||||
};
|
||||
},
|
||||
path(path: string) {
|
||||
path(path: string, proxyUrl: string = "") {
|
||||
if (!path.endsWith("/")) {
|
||||
path += "/";
|
||||
}
|
||||
@@ -67,7 +64,11 @@ export function createWebDavClient(store: SyncStore) {
|
||||
path = path.slice(1);
|
||||
}
|
||||
|
||||
let url = new URL("/api/webdav/" + path);
|
||||
if (proxyUrl.length > 0 && !proxyUrl.endsWith("/")) {
|
||||
proxyUrl += "/";
|
||||
}
|
||||
|
||||
let url = new URL(proxyUrl + "/api/webdav/" + path);
|
||||
|
||||
// add query params
|
||||
url.searchParams.append("endpoint", config.endpoint);
|
||||
|
Reference in New Issue
Block a user