mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-09 19:46:37 +08:00
feat: 接口迁移到node层
This commit is contained in:
parent
e10ab6a8e1
commit
052c68edc6
@ -34,8 +34,9 @@ import Locale from "../locales";
|
|||||||
|
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import { REPO_URL } from "../constant";
|
import { REPO_URL } from "../constant";
|
||||||
import { ControllerPool } from "../requests";
|
import { ControllerPool, validUser } from "../requests";
|
||||||
import { Prompt, usePromptStore } from "../store/prompt";
|
import { Prompt, usePromptStore } from "../store/prompt";
|
||||||
|
import VConsole from 'vconsole';
|
||||||
|
|
||||||
export function Loading(props: { noLogo?: boolean }) {
|
export function Loading(props: { noLogo?: boolean }) {
|
||||||
return (
|
return (
|
||||||
@ -608,26 +609,33 @@ export function Home() {
|
|||||||
// setting
|
// setting
|
||||||
const [openSettings, setOpenSettings] = useState(false);
|
const [openSettings, setOpenSettings] = useState(false);
|
||||||
const config = useChatStore((state) => state.config);
|
const config = useChatStore((state) => state.config);
|
||||||
const [isAllow, setIsAllow] = useState(true); // 白名单状态
|
const [isAllow, setIsAllow] = useState(false); // 白名单状态
|
||||||
const [isRequestErr, setIsRequestErr] = useState(false); // 接口报错状态
|
const [isRequestErr, setIsRequestErr] = useState(false); // 接口报错状态
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
new VConsole();
|
||||||
|
getBaseInfo()
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getBaseInfo = async () => {
|
||||||
|
setIsLoading(true)
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const signature = urlParams.get("signature");
|
const signature = urlParams.get("signature") || '';
|
||||||
// 是否在白名单
|
// 是否在白名单
|
||||||
fetch(`${process.env.API_URL}/api/check_user_white/?signature=${signature}`)
|
const response = await validUser(signature)
|
||||||
.then((response) => response.json())
|
const {data, error} = response
|
||||||
.then((data) => {
|
console.log({data,error});
|
||||||
const { code, msg } = data;
|
if (error) {
|
||||||
setIsAllow(code === 0);
|
|
||||||
})
|
|
||||||
// 接口错误处理
|
|
||||||
.catch((error) => {
|
|
||||||
setIsAllow(false);
|
setIsAllow(false);
|
||||||
setIsRequestErr(true);
|
setIsRequestErr(true);
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
} else {
|
||||||
}, []);
|
const { code, msg } = data;
|
||||||
|
setIsAllow(code === 0);
|
||||||
|
}
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
//const isWorkWechat = () => {
|
//const isWorkWechat = () => {
|
||||||
//获取user-agaent标识头
|
//获取user-agaent标识头
|
||||||
@ -669,10 +677,12 @@ export function Home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const goApply = () => {
|
const goApply = () => {
|
||||||
location.href = `${process.env.APPLY_URL}/#/process/create-ticket?processId=117`;
|
location.href = `${process.env.APPLY_URL}#/process/create-ticket?processId=117`;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
console.log('render', { isAllow, isRequestErr, isW:isWorkWechat()});
|
||||||
|
|
||||||
|
return !isLoading ? (
|
||||||
<div
|
<div
|
||||||
className={`${
|
className={`${
|
||||||
config.tightBorder && !isMobileScreen()
|
config.tightBorder && !isMobileScreen()
|
||||||
@ -784,5 +794,5 @@ export function Home() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
) : null
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,24 @@ function getHeaders() {
|
|||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function validUser(signature: String) {
|
||||||
|
return fetch(`${process.env.API_URL}check_user_white/?signature=${signature}`)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
error: null,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 接口错误处理
|
||||||
|
.catch((error) => {
|
||||||
|
return {
|
||||||
|
data: null,
|
||||||
|
error
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function requestOpenaiClient(path: string) {
|
export function requestOpenaiClient(path: string) {
|
||||||
return (body: any, method = "POST") =>
|
return (body: any, method = "POST") =>
|
||||||
fetch("/api/openai", {
|
fetch("/api/openai", {
|
||||||
|
15705
package-lock.json
generated
Normal file
15705
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -23,14 +23,15 @@
|
|||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-markdown": "^8.0.5",
|
"react-markdown": "^8.0.5",
|
||||||
"remark-breaks": "^3.0.2",
|
|
||||||
"rehype-katex": "^6.0.2",
|
"rehype-katex": "^6.0.2",
|
||||||
"rehype-prism-plus": "^1.5.1",
|
"rehype-prism-plus": "^1.5.1",
|
||||||
|
"remark-breaks": "^3.0.2",
|
||||||
"remark-gfm": "^3.0.1",
|
"remark-gfm": "^3.0.1",
|
||||||
"remark-math": "^5.1.1",
|
"remark-math": "^5.1.1",
|
||||||
"sass": "^1.59.2",
|
"sass": "^1.59.2",
|
||||||
"spark-md5": "^3.0.2",
|
"spark-md5": "^3.0.2",
|
||||||
"use-debounce": "^9.0.3",
|
"use-debounce": "^9.0.3",
|
||||||
|
"vconsole": "^3.15.0",
|
||||||
"zustand": "^4.3.6"
|
"zustand": "^4.3.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
Loading…
Reference in New Issue
Block a user