From 6cb296f952ec50b1ff56add63ee1989d96aae822 Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 9 Apr 2024 09:12:18 +0800 Subject: [PATCH 1/8] feat: remove debug code --- app/components/markdown.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index 2b036051a95..1afd7de3b45 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -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]); From d50812745211f6ef043a7fad8d50f3178e5a2290 Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 9 Apr 2024 10:45:09 +0800 Subject: [PATCH 2/8] feat: fix system prompt --- app/constant.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/constant.ts b/app/constant.ts index b5d57612ab6..7786d1b06c9 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -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$$ `; From 7fcfbc372921e85fb957dbe6cab35843d54a3872 Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 9 Apr 2024 16:49:51 +0800 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.template | 11 +++++++++++ README.md | 12 ++++++++++++ README_CN.md | 12 ++++++++++++ 3 files changed, 35 insertions(+) diff --git a/.env.template b/.env.template index d53c1be6caa..d5d0c4c2718 100644 --- a/.env.template +++ b/.env.template @@ -47,3 +47,14 @@ ENABLE_BALANCE_QUERY= # If you want to disable parse settings from url, set this value to 1. DISABLE_FAST_LINK= + +# anthropic claude Api Key.(optional) +ANTHROPIC_API_KEY= + +### anthropic claude Api version. (optional) +ANTHROPIC_API_VERSION= + + + +### anthropic claude Api url (optional) +ANTHROPIC_URL= \ No newline at end of file diff --git a/README.md b/README.md index 429a02d63e6..c756b7bb614 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,18 @@ Google Gemini Pro Api Key. Google Gemini Pro Api Url. +### `ANTHROPIC_API_KEY` (optional) + +anthropic claude Api Key. + +### `ANTHROPIC_API_VERSION` (optional) + +anthropic claude Api version. + +### `ANTHROPIC_URL` (optional) + +anthropic claude Api Url. + ### `HIDE_USER_API_KEY` (optional) > Default: Empty diff --git a/README_CN.md b/README_CN.md index 4acefefa518..0df271814d1 100644 --- a/README_CN.md +++ b/README_CN.md @@ -114,6 +114,18 @@ Google Gemini Pro 密钥. Google Gemini Pro Api Url. +### `ANTHROPIC_API_KEY` (optional) + +anthropic claude Api Key. + +### `ANTHROPIC_API_VERSION` (optional) + +anthropic claude Api version. + +### `ANTHROPIC_URL` (optional) + +anthropic claude Api Url. + ### `HIDE_USER_API_KEY` (可选) 如果你不想让用户自行填入 API Key,将此环境变量设置为 1 即可。 From 8b191bd2f733d8677c851d90a5003617bd1da937 Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 9 Apr 2024 18:05:56 +0800 Subject: [PATCH 4/8] feat: white webdav server domain --- .env.template | 5 ++- README.md | 7 +++++ README_CN.md | 7 +++++ app/api/webdav/[...path]/route.ts | 52 +++++++++++++++++++------------ app/config/server.ts | 5 +++ app/constant.ts | 2 ++ 6 files changed, 57 insertions(+), 21 deletions(-) diff --git a/.env.template b/.env.template index d5d0c4c2718..fae5d8f4cbc 100644 --- a/.env.template +++ b/.env.template @@ -57,4 +57,7 @@ ANTHROPIC_API_VERSION= ### anthropic claude Api url (optional) -ANTHROPIC_URL= \ No newline at end of file +ANTHROPIC_URL= + +### (optional) +WHITE_WEBDEV_DOMAINS= \ No newline at end of file diff --git a/README.md b/README.md index c756b7bb614..d821093f498 100644 --- a/README.md +++ b/README.md @@ -245,6 +245,13 @@ To control custom models, use `+` to add a custom model, use `-` to hide a model User `-all` to disable all default models, `+all` to enable all default models. +### `WHITE_WEBDEV_DOMAINS` (可选) + +如果你想增加允许访问的webdav服务地址,可以使用该选项,格式要求: +- 每一个地址必须是一个完整的 origin +> `https://xxxx` +- 多个地址以`,`相连 + ## Requirements NodeJS >= 18, Docker >= 20 diff --git a/README_CN.md b/README_CN.md index 0df271814d1..07f426ee83c 100644 --- a/README_CN.md +++ b/README_CN.md @@ -142,6 +142,13 @@ anthropic claude Api Url. 如果你想禁用从链接解析预制设置,将此环境变量设置为 1 即可。 +### `WHITE_WEBDEV_DOMAINS` (可选) + +如果你想增加允许访问的webdav服务地址,可以使用该选项,格式要求: +- 每一个地址必须是一个完整的 origin +> `https://xxxx` +- 多个地址以`,`相连 + ### `CUSTOM_MODELS` (可选) > 示例:`+qwen-7b-chat,+glm-6b,-gpt-3.5-turbo,gpt-4-1106-preview=gpt-4-turbo` 表示增加 `qwen-7b-chat` 和 `glm-6b` 到模型列表,而从列表中删除 `gpt-3.5-turbo`,并将 `gpt-4-1106-preview` 模型名字展示为 `gpt-4-turbo`。 diff --git a/app/api/webdav/[...path]/route.ts b/app/api/webdav/[...path]/route.ts index 56c2388aed0..58d591bfc94 100644 --- a/app/api/webdav/[...path]/route.ts +++ b/app/api/webdav/[...path]/route.ts @@ -1,5 +1,14 @@ import { NextRequest, NextResponse } from "next/server"; -import { STORAGE_KEY } from "../../../constant"; +import { STORAGE_KEY, internalWhiteWebDavDomains } from "../../../constant"; +import { getServerSideConfig } from "@/app/config/server"; + +const config = getServerSideConfig(); + +const mergedWhiteWebDavDomains = [ + ...internalWhiteWebDavDomains, + ...config.whiteWebDevDomains, +].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 ( + !mergedWhiteWebDavDomains.some((domain) => endpoint?.startsWith(domain)) + ) { 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", @@ -109,15 +116,20 @@ async function handle( const fetchResult = await fetch(targetUrl, fetchOptions); - console.log("[Any Proxy]", targetUrl, { - status: fetchResult.status, - statusText: fetchResult.statusText, - }); + console.log( + "[Any Proxy]", + targetUrl, + { + status: fetchResult.status, + statusText: fetchResult.statusText, + }, + fetchResult, + ); return fetchResult; } -export const POST = handle; +export const PUT = handle; export const GET = handle; export const OPTIONS = handle; diff --git a/app/config/server.ts b/app/config/server.ts index d18e4a1a694..596ef9cab52 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -79,6 +79,10 @@ export const getServerSideConfig = () => { `[Server Config] using ${randomIndex + 1} of ${apiKeys.length} api key`, ); + const whiteWebDevDomains = (process.env.WHITE_WEBDEV_DOMAINS ?? "").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, + whiteWebDevDomains, }; }; diff --git a/app/constant.ts b/app/constant.ts index 7786d1b06c9..48fca62c070 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -366,3 +366,5 @@ export const DEFAULT_MODELS = [ export const CHAT_PAGE_SIZE = 15; export const MAX_RENDER_MSG_COUNT = 45; + +export const internalWhiteWebDavDomains = ["https://dav.jianguoyun.com"]; From 4cb0655192281765fea2ef73e6bd620a961d1f70 Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 9 Apr 2024 18:17:00 +0800 Subject: [PATCH 5/8] feat: Optimize document --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d821093f498..19b399819b2 100644 --- a/README.md +++ b/README.md @@ -247,10 +247,10 @@ User `-all` to disable all default models, `+all` to enable all default models. ### `WHITE_WEBDEV_DOMAINS` (可选) -如果你想增加允许访问的webdav服务地址,可以使用该选项,格式要求: -- 每一个地址必须是一个完整的 origin +You can use this option if you want to increase the number of webdav service addresses you are allowed to access, as required by the format: +- Each address must be a complete origin > `https://xxxx` -- 多个地址以`,`相连 +- Multiple addresses are connected by ', ' ## Requirements From b175132854e5710d6635f8f58b9a690cd04a66e1 Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 9 Apr 2024 18:23:52 +0800 Subject: [PATCH 6/8] feat: Optimize var names --- .env.template | 2 +- README.md | 2 +- README_CN.md | 6 +++--- app/api/webdav/[...path]/route.ts | 10 +++++----- app/config/server.ts | 4 ++-- app/constant.ts | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.env.template b/.env.template index fae5d8f4cbc..b2a0438d9d1 100644 --- a/.env.template +++ b/.env.template @@ -60,4 +60,4 @@ ANTHROPIC_API_VERSION= ANTHROPIC_URL= ### (optional) -WHITE_WEBDEV_DOMAINS= \ No newline at end of file +WHITE_WEBDEV_ENDPOINTS= \ No newline at end of file diff --git a/README.md b/README.md index 19b399819b2..0715dafdf17 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ To control custom models, use `+` to add a custom model, use `-` to hide a model User `-all` to disable all default models, `+all` to enable all default models. -### `WHITE_WEBDEV_DOMAINS` (可选) +### `WHITE_WEBDEV_ENDPOINTS` (可选) You can use this option if you want to increase the number of webdav service addresses you are allowed to access, as required by the format: - Each address must be a complete origin diff --git a/README_CN.md b/README_CN.md index 07f426ee83c..10b5fd03596 100644 --- a/README_CN.md +++ b/README_CN.md @@ -142,11 +142,11 @@ anthropic claude Api Url. 如果你想禁用从链接解析预制设置,将此环境变量设置为 1 即可。 -### `WHITE_WEBDEV_DOMAINS` (可选) +### `WHITE_WEBDEV_ENDPOINTS` (可选) 如果你想增加允许访问的webdav服务地址,可以使用该选项,格式要求: -- 每一个地址必须是一个完整的 origin -> `https://xxxx` +- 每一个地址必须是一个完整的 endpoint +> `https://xxxx/xxx` - 多个地址以`,`相连 ### `CUSTOM_MODELS` (可选) diff --git a/app/api/webdav/[...path]/route.ts b/app/api/webdav/[...path]/route.ts index 58d591bfc94..27aaee690d5 100644 --- a/app/api/webdav/[...path]/route.ts +++ b/app/api/webdav/[...path]/route.ts @@ -1,12 +1,12 @@ import { NextRequest, NextResponse } from "next/server"; -import { STORAGE_KEY, internalWhiteWebDavDomains } from "../../../constant"; +import { STORAGE_KEY, internalWhiteWebDavEndpoints } from "../../../constant"; import { getServerSideConfig } from "@/app/config/server"; const config = getServerSideConfig(); -const mergedWhiteWebDavDomains = [ - ...internalWhiteWebDavDomains, - ...config.whiteWebDevDomains, +const mergedWhiteWebDavEndpoints = [ + ...internalWhiteWebDavEndpoints, + ...config.whiteWebDevEndpoints, ].filter((domain) => Boolean(domain.trim())); async function handle( @@ -24,7 +24,7 @@ async function handle( // Validate the endpoint to prevent potential SSRF attacks if ( - !mergedWhiteWebDavDomains.some((domain) => endpoint?.startsWith(domain)) + !mergedWhiteWebDavEndpoints.some((white) => endpoint?.startsWith(white)) ) { return NextResponse.json( { diff --git a/app/config/server.ts b/app/config/server.ts index 596ef9cab52..c27ef5e4440 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -79,7 +79,7 @@ export const getServerSideConfig = () => { `[Server Config] using ${randomIndex + 1} of ${apiKeys.length} api key`, ); - const whiteWebDevDomains = (process.env.WHITE_WEBDEV_DOMAINS ?? "").split( + const whiteWebDevEndpoints = (process.env.WHITE_WEBDEV_ENDPOINTS ?? "").split( ",", ); @@ -116,6 +116,6 @@ export const getServerSideConfig = () => { hideBalanceQuery: !process.env.ENABLE_BALANCE_QUERY, disableFastLink: !!process.env.DISABLE_FAST_LINK, customModels, - whiteWebDevDomains, + whiteWebDevEndpoints, }; }; diff --git a/app/constant.ts b/app/constant.ts index 48fca62c070..ce9b08d1429 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -367,4 +367,4 @@ export const DEFAULT_MODELS = [ export const CHAT_PAGE_SIZE = 15; export const MAX_RENDER_MSG_COUNT = 45; -export const internalWhiteWebDavDomains = ["https://dav.jianguoyun.com"]; +export const internalWhiteWebDavEndpoints = ["https://dav.jianguoyun.com"]; From df3313971dd3e66abcf7dafbabc48f1630add8d2 Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 9 Apr 2024 18:24:22 +0800 Subject: [PATCH 7/8] feat: Optimize code --- app/api/webdav/[...path]/route.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/api/webdav/[...path]/route.ts b/app/api/webdav/[...path]/route.ts index 27aaee690d5..f64a9ef1354 100644 --- a/app/api/webdav/[...path]/route.ts +++ b/app/api/webdav/[...path]/route.ts @@ -116,15 +116,10 @@ async function handle( const fetchResult = await fetch(targetUrl, fetchOptions); - console.log( - "[Any Proxy]", - targetUrl, - { - status: fetchResult.status, - statusText: fetchResult.statusText, - }, - fetchResult, - ); + console.log("[Any Proxy]", targetUrl, { + status: fetchResult.status, + statusText: fetchResult.statusText, + }); return fetchResult; } From 908ce3bbd988c45dea10b552ede34cd051c99de5 Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 9 Apr 2024 18:25:51 +0800 Subject: [PATCH 8/8] feat: Optimize document --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0715dafdf17..633124ec751 100644 --- a/README.md +++ b/README.md @@ -248,8 +248,8 @@ User `-all` to disable all default models, `+all` to enable all default models. ### `WHITE_WEBDEV_ENDPOINTS` (可选) You can use this option if you want to increase the number of webdav service addresses you are allowed to access, as required by the format: -- Each address must be a complete origin -> `https://xxxx` +- Each address must be a complete endpoint +> `https://xxxx/yyy` - Multiple addresses are connected by ', ' ## Requirements