From ae8226907ff03100cafd45ba5d648d2a62f77fef Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Mon, 14 Aug 2023 21:36:29 +0800 Subject: [PATCH 1/3] feat: close #2621 use better default api url --- app/client/platforms/openai.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 9dc92e9aede..fd4eb59ce77 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -13,6 +13,7 @@ import { fetchEventSource, } from "@fortaine/fetch-event-source"; import { prettyObject } from "@/app/utils/format"; +import { getClientConfig } from "@/app/config/client"; export interface OpenAIListModelResponse { object: string; @@ -28,13 +29,16 @@ export class ChatGPTApi implements LLMApi { path(path: string): string { let openaiUrl = useAccessStore.getState().openaiUrl; + const apiPath = "/api/openai"; + if (openaiUrl.length === 0) { - openaiUrl = DEFAULT_API_HOST; + const isApp = !!getClientConfig()?.isApp; + openaiUrl = isApp ? DEFAULT_API_HOST : apiPath; } if (openaiUrl.endsWith("/")) { openaiUrl = openaiUrl.slice(0, openaiUrl.length - 1); } - if (!openaiUrl.startsWith("http") && !openaiUrl.startsWith("/api/openai")) { + if (!openaiUrl.startsWith("http") && !openaiUrl.startsWith(apiPath)) { openaiUrl = "https://" + openaiUrl; } return [openaiUrl, path].join("/"); From e8e01aa60d559fb7654b0f5e9521aa637e3d0b22 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Mon, 14 Aug 2023 21:55:18 +0800 Subject: [PATCH 2/3] feat: close #2618 use correct html lang attr --- app/components/home.tsx | 14 +++++++++++++- app/layout.tsx | 2 +- app/locales/index.ts | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/components/home.tsx b/app/components/home.tsx index c6829c2dc18..745298d560e 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -15,7 +15,7 @@ import dynamic from "next/dynamic"; import { Path, SlotID } from "../constant"; import { ErrorBoundary } from "./error"; -import { getLang } from "../locales"; +import { getISOLang, getLang } from "../locales"; import { HashRouter as Router, @@ -86,6 +86,17 @@ export function useSwitchTheme() { }, [config.theme]); } +function useHtmlLang() { + useEffect(() => { + const lang = getISOLang(); + const htmlLang = document.documentElement.lang; + + if (lang !== htmlLang) { + document.documentElement.lang = lang; + } + }, []); +} + const useHasHydrated = () => { const [hasHydrated, setHasHydrated] = useState(false); @@ -168,6 +179,7 @@ export function useLoadData() { export function Home() { useSwitchTheme(); useLoadData(); + useHtmlLang(); useEffect(() => { console.log("[Config] got config from build time", getClientConfig()); diff --git a/app/layout.tsx b/app/layout.tsx index 883a268d368..5e0762653a8 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -3,7 +3,7 @@ import "./styles/globals.scss"; import "./styles/markdown.scss"; import "./styles/highlight.scss"; import { getClientConfig } from "./config/client"; -import { type Metadata } from 'next'; +import { type Metadata } from "next"; export const metadata: Metadata = { title: "ChatGPT Next Web", diff --git a/app/locales/index.ts b/app/locales/index.ts index 7ece458383a..528600bec81 100644 --- a/app/locales/index.ts +++ b/app/locales/index.ts @@ -116,3 +116,13 @@ export function changeLang(lang: Lang) { setItem(LANG_KEY, lang); location.reload(); } + +export function getISOLang() { + const isoLangString: Record = { + cn: "zh-Hans", + tw: "zh-Hant", + }; + + const lang = getLang(); + return isoLangString[lang] ?? lang; +} From db5c7aba788c5f0a1a347f7d68baa5f0b1c5f516 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Mon, 14 Aug 2023 22:11:38 +0800 Subject: [PATCH 3/3] fix: #2615 scrollbar jitter under certain message counts --- app/components/chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index a99f72f1527..f661d0a47b7 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -940,7 +940,7 @@ function _Chat() { const prevPageMsgIndex = msgRenderIndex - CHAT_PAGE_SIZE; const nextPageMsgIndex = msgRenderIndex + CHAT_PAGE_SIZE; - if (isTouchTopEdge) { + if (isTouchTopEdge && !isTouchBottomEdge) { setMsgRenderIndex(prevPageMsgIndex); } else if (isTouchBottomEdge) { setMsgRenderIndex(nextPageMsgIndex);