forked from XiaoMo/ChatGPT-Next-Web
Merge pull request #2629 from Yidadaa/bugfix-0814
This commit is contained in:
commit
20882a7598
@ -13,6 +13,7 @@ import {
|
|||||||
fetchEventSource,
|
fetchEventSource,
|
||||||
} from "@fortaine/fetch-event-source";
|
} from "@fortaine/fetch-event-source";
|
||||||
import { prettyObject } from "@/app/utils/format";
|
import { prettyObject } from "@/app/utils/format";
|
||||||
|
import { getClientConfig } from "@/app/config/client";
|
||||||
|
|
||||||
export interface OpenAIListModelResponse {
|
export interface OpenAIListModelResponse {
|
||||||
object: string;
|
object: string;
|
||||||
@ -28,13 +29,16 @@ export class ChatGPTApi implements LLMApi {
|
|||||||
|
|
||||||
path(path: string): string {
|
path(path: string): string {
|
||||||
let openaiUrl = useAccessStore.getState().openaiUrl;
|
let openaiUrl = useAccessStore.getState().openaiUrl;
|
||||||
|
const apiPath = "/api/openai";
|
||||||
|
|
||||||
if (openaiUrl.length === 0) {
|
if (openaiUrl.length === 0) {
|
||||||
openaiUrl = DEFAULT_API_HOST;
|
const isApp = !!getClientConfig()?.isApp;
|
||||||
|
openaiUrl = isApp ? DEFAULT_API_HOST : apiPath;
|
||||||
}
|
}
|
||||||
if (openaiUrl.endsWith("/")) {
|
if (openaiUrl.endsWith("/")) {
|
||||||
openaiUrl = openaiUrl.slice(0, openaiUrl.length - 1);
|
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;
|
openaiUrl = "https://" + openaiUrl;
|
||||||
}
|
}
|
||||||
return [openaiUrl, path].join("/");
|
return [openaiUrl, path].join("/");
|
||||||
|
@ -940,7 +940,7 @@ function _Chat() {
|
|||||||
const prevPageMsgIndex = msgRenderIndex - CHAT_PAGE_SIZE;
|
const prevPageMsgIndex = msgRenderIndex - CHAT_PAGE_SIZE;
|
||||||
const nextPageMsgIndex = msgRenderIndex + CHAT_PAGE_SIZE;
|
const nextPageMsgIndex = msgRenderIndex + CHAT_PAGE_SIZE;
|
||||||
|
|
||||||
if (isTouchTopEdge) {
|
if (isTouchTopEdge && !isTouchBottomEdge) {
|
||||||
setMsgRenderIndex(prevPageMsgIndex);
|
setMsgRenderIndex(prevPageMsgIndex);
|
||||||
} else if (isTouchBottomEdge) {
|
} else if (isTouchBottomEdge) {
|
||||||
setMsgRenderIndex(nextPageMsgIndex);
|
setMsgRenderIndex(nextPageMsgIndex);
|
||||||
|
@ -15,7 +15,7 @@ import dynamic from "next/dynamic";
|
|||||||
import { Path, SlotID } from "../constant";
|
import { Path, SlotID } from "../constant";
|
||||||
import { ErrorBoundary } from "./error";
|
import { ErrorBoundary } from "./error";
|
||||||
|
|
||||||
import { getLang } from "../locales";
|
import { getISOLang, getLang } from "../locales";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HashRouter as Router,
|
HashRouter as Router,
|
||||||
@ -86,6 +86,17 @@ export function useSwitchTheme() {
|
|||||||
}, [config.theme]);
|
}, [config.theme]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useHtmlLang() {
|
||||||
|
useEffect(() => {
|
||||||
|
const lang = getISOLang();
|
||||||
|
const htmlLang = document.documentElement.lang;
|
||||||
|
|
||||||
|
if (lang !== htmlLang) {
|
||||||
|
document.documentElement.lang = lang;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
const useHasHydrated = () => {
|
const useHasHydrated = () => {
|
||||||
const [hasHydrated, setHasHydrated] = useState<boolean>(false);
|
const [hasHydrated, setHasHydrated] = useState<boolean>(false);
|
||||||
|
|
||||||
@ -168,6 +179,7 @@ export function useLoadData() {
|
|||||||
export function Home() {
|
export function Home() {
|
||||||
useSwitchTheme();
|
useSwitchTheme();
|
||||||
useLoadData();
|
useLoadData();
|
||||||
|
useHtmlLang();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("[Config] got config from build time", getClientConfig());
|
console.log("[Config] got config from build time", getClientConfig());
|
||||||
|
@ -3,7 +3,7 @@ import "./styles/globals.scss";
|
|||||||
import "./styles/markdown.scss";
|
import "./styles/markdown.scss";
|
||||||
import "./styles/highlight.scss";
|
import "./styles/highlight.scss";
|
||||||
import { getClientConfig } from "./config/client";
|
import { getClientConfig } from "./config/client";
|
||||||
import { type Metadata } from 'next';
|
import { type Metadata } from "next";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "ChatGPT Next Web",
|
title: "ChatGPT Next Web",
|
||||||
|
@ -116,3 +116,13 @@ export function changeLang(lang: Lang) {
|
|||||||
setItem(LANG_KEY, lang);
|
setItem(LANG_KEY, lang);
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getISOLang() {
|
||||||
|
const isoLangString: Record<string, string> = {
|
||||||
|
cn: "zh-Hans",
|
||||||
|
tw: "zh-Hant",
|
||||||
|
};
|
||||||
|
|
||||||
|
const lang = getLang();
|
||||||
|
return isoLangString[lang] ?? lang;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user