Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#2629 from Yidadaa/bugfix-0814
Browse files Browse the repository at this point in the history
  • Loading branch information
Yidadaa authored Aug 14, 2023
2 parents 9d3dff4 + db5c7ab commit 20882a7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
8 changes: 6 additions & 2 deletions app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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("/");
Expand Down
2 changes: 1 addition & 1 deletion app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion app/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<boolean>(false);

Expand Down Expand Up @@ -168,6 +179,7 @@ export function useLoadData() {
export function Home() {
useSwitchTheme();
useLoadData();
useHtmlLang();

useEffect(() => {
console.log("[Config] got config from build time", getClientConfig());
Expand Down
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions app/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,13 @@ export function changeLang(lang: Lang) {
setItem(LANG_KEY, lang);
location.reload();
}

export function getISOLang() {
const isoLangString: Record<string, string> = {
cn: "zh-Hans",
tw: "zh-Hant",
};

const lang = getLang();
return isoLangString[lang] ?? lang;
}

0 comments on commit 20882a7

Please sign in to comment.