This commit is contained in:
GH Action - Upstream Sync
2024-04-10 00:27:12 +00:00
7 changed files with 83 additions and 18 deletions

View File

@@ -1,5 +1,14 @@
import { NextRequest, NextResponse } from "next/server";
import { STORAGE_KEY } from "../../../constant";
import { STORAGE_KEY, internalWhiteWebDavEndpoints } from "../../../constant";
import { getServerSideConfig } from "@/app/config/server";
const config = getServerSideConfig();
const mergedWhiteWebDavEndpoints = [
...internalWhiteWebDavEndpoints,
...config.whiteWebDevEndpoints,
].filter((domain) => Boolean(domain.trim()));
async function handle(
req: NextRequest,
{ params }: { params: { path: string[] } },
@@ -14,7 +23,9 @@ async function handle(
let endpoint = requestUrl.searchParams.get("endpoint");
// Validate the endpoint to prevent potential SSRF attacks
if (!endpoint || !endpoint.startsWith("/")) {
if (
!mergedWhiteWebDavEndpoints.some((white) => endpoint?.startsWith(white))
) {
return NextResponse.json(
{
error: true,
@@ -25,6 +36,11 @@ async function handle(
},
);
}
if (!endpoint?.endsWith("/")) {
endpoint += "/";
}
const endpointPath = params.path.join("/");
const targetPath = `${endpoint}/${endpointPath}`;
@@ -42,10 +58,7 @@ async function handle(
}
// for MKCOL request, only allow request ${folder}
if (
req.method === "MKCOL" &&
!targetPath.endsWith(folder)
) {
if (req.method === "MKCOL" && !targetPath.endsWith(folder)) {
return NextResponse.json(
{
error: true,
@@ -58,10 +71,7 @@ async function handle(
}
// for GET request, only allow request ending with fileName
if (
req.method === "GET" &&
!targetPath.endsWith(fileName)
) {
if (req.method === "GET" && !targetPath.endsWith(fileName)) {
return NextResponse.json(
{
error: true,
@@ -74,10 +84,7 @@ async function handle(
}
// for PUT request, only allow request ending with fileName
if (
req.method === "PUT" &&
!targetPath.endsWith(fileName)
) {
if (req.method === "PUT" && !targetPath.endsWith(fileName)) {
return NextResponse.json(
{
error: true,
@@ -101,7 +108,7 @@ async function handle(
authorization: req.headers.get("authorization") ?? "",
},
body: shouldNotHaveBody ? null : req.body,
redirect: 'manual',
redirect: "manual",
method,
// @ts-ignore
duplex: "half",
@@ -117,7 +124,7 @@ async function handle(
return fetchResult;
}
export const POST = handle;
export const PUT = handle;
export const GET = handle;
export const OPTIONS = handle;

View File

@@ -136,7 +136,6 @@ function escapeBrackets(text: string) {
function _MarkDownContent(props: { content: string }) {
const escapedContent = useMemo(() => {
console.log("================", props.content);
return escapeBrackets(escapeDollarNumber(props.content));
}, [props.content]);

View File

@@ -79,6 +79,10 @@ export const getServerSideConfig = () => {
`[Server Config] using ${randomIndex + 1} of ${apiKeys.length} api key`,
);
const whiteWebDevEndpoints = (process.env.WHITE_WEBDEV_ENDPOINTS ?? "").split(
",",
);
return {
baseUrl: process.env.BASE_URL,
apiKey,
@@ -112,5 +116,6 @@ export const getServerSideConfig = () => {
hideBalanceQuery: !process.env.ENABLE_BALANCE_QUERY,
disableFastLink: !!process.env.DISABLE_FAST_LINK,
customModels,
whiteWebDevEndpoints,
};
};

View File

@@ -118,7 +118,7 @@ You are ChatGPT, a large language model trained by {{ServiceProvider}}.
Knowledge cutoff: {{cutoff}}
Current model: {{model}}
Current time: {{time}}
Latex inline: \(x^2\)
Latex inline: \\(x^2\\)
Latex block: $$e=mc^2$$
`;
@@ -366,3 +366,5 @@ export const DEFAULT_MODELS = [
export const CHAT_PAGE_SIZE = 15;
export const MAX_RENDER_MSG_COUNT = 45;
export const internalWhiteWebDavEndpoints = ["https://dav.jianguoyun.com"];