mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-09 11:36:38 +08:00
refactor: Remove the code in the client that disables the fetch cache by passing a request header, and replace it with server-side enforced fetch cache disabling.
* fix last commit updateUsage should pass force argument not true.
This commit is contained in:
parent
d2ee1bd212
commit
43b8b38167
@ -8,8 +8,6 @@ const BASE_URL = process.env.BASE_URL ?? OPENAI_URL;
|
|||||||
export async function requestOpenai(req: NextRequest) {
|
export async function requestOpenai(req: NextRequest) {
|
||||||
const apiKey = req.headers.get("token");
|
const apiKey = req.headers.get("token");
|
||||||
const openaiPath = req.headers.get("path");
|
const openaiPath = req.headers.get("path");
|
||||||
const fetchCache =
|
|
||||||
req.headers.get("fetch-cache") == "enable" ? "default" : "no-store";
|
|
||||||
|
|
||||||
let baseUrl = BASE_URL;
|
let baseUrl = BASE_URL;
|
||||||
|
|
||||||
@ -25,7 +23,7 @@ export async function requestOpenai(req: NextRequest) {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${apiKey}`,
|
Authorization: `Bearer ${apiKey}`,
|
||||||
},
|
},
|
||||||
cache: fetchCache,
|
cache: "no-store",
|
||||||
method: req.method,
|
method: req.method,
|
||||||
body: req.body,
|
body: req.body,
|
||||||
});
|
});
|
||||||
|
@ -207,7 +207,7 @@ export function Settings(props: { closeSettings: () => void }) {
|
|||||||
const [loadingUsage, setLoadingUsage] = useState(false);
|
const [loadingUsage, setLoadingUsage] = useState(false);
|
||||||
function checkUsage(force: boolean = false) {
|
function checkUsage(force: boolean = false) {
|
||||||
setLoadingUsage(true);
|
setLoadingUsage(true);
|
||||||
updateStore.updateUsage(true).finally(() => {
|
updateStore.updateUsage(force).finally(() => {
|
||||||
setLoadingUsage(false);
|
setLoadingUsage(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -49,17 +49,15 @@ function getHeaders() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function requestOpenaiClient(path: string) {
|
export function requestOpenaiClient(path: string) {
|
||||||
return (body: any, method: string = "POST", fetchCache: boolean = true) =>
|
return (body: any, method: string = "POST") =>
|
||||||
fetch("/api/openai?_vercel_no_cache=1", {
|
fetch("/api/openai?_vercel_no_cache=1", {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
path,
|
path,
|
||||||
...getHeaders(),
|
...getHeaders(),
|
||||||
"fetch-cache": fetchCache ? "enable" : "disable",
|
|
||||||
},
|
},
|
||||||
body: body && JSON.stringify(body),
|
body: body && JSON.stringify(body),
|
||||||
cache: fetchCache ? "default" : "no-store", //https://beta.nextjs.org/docs/data-fetching/fetching#dynamic-data-fetching
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,12 +90,8 @@ export async function requestUsage() {
|
|||||||
const [used, subs] = await Promise.all([
|
const [used, subs] = await Promise.all([
|
||||||
requestOpenaiClient(
|
requestOpenaiClient(
|
||||||
`dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}`,
|
`dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}`,
|
||||||
)(null, "GET", useFetchCache),
|
)(null, "GET"),
|
||||||
requestOpenaiClient("dashboard/billing/subscription")(
|
requestOpenaiClient("dashboard/billing/subscription")(null, "GET"),
|
||||||
null,
|
|
||||||
"GET",
|
|
||||||
useFetchCache,
|
|
||||||
),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const response = (await used.json()) as {
|
const response = (await used.json()) as {
|
||||||
|
Loading…
Reference in New Issue
Block a user