feat: 接口迁移到node层

This commit is contained in:
“张嘉宁” 2023-04-03 17:35:45 +08:00
parent e10ab6a8e1
commit 052c68edc6
5 changed files with 19229 additions and 3529 deletions

View File

@ -34,8 +34,9 @@ import Locale from "../locales";
import dynamic from "next/dynamic";
import { REPO_URL } from "../constant";
import { ControllerPool } from "../requests";
import { ControllerPool, validUser } from "../requests";
import { Prompt, usePromptStore } from "../store/prompt";
import VConsole from 'vconsole';
export function Loading(props: { noLogo?: boolean }) {
return (
@ -608,27 +609,34 @@ export function Home() {
// setting
const [openSettings, setOpenSettings] = useState(false);
const config = useChatStore((state) => state.config);
const [isAllow, setIsAllow] = useState(true); // 白名单状态
const [isAllow, setIsAllow] = useState(false); // 白名单状态
const [isRequestErr, setIsRequestErr] = useState(false); // 接口报错状态
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
const signature = urlParams.get("signature");
// 是否在白名单
fetch(`${process.env.API_URL}/api/check_user_white/?signature=${signature}`)
.then((response) => response.json())
.then((data) => {
const { code, msg } = data;
setIsAllow(code === 0);
})
// 接口错误处理
.catch((error) => {
setIsAllow(false);
setIsRequestErr(true);
console.error(error);
});
new VConsole();
getBaseInfo()
}, []);
const getBaseInfo = async () => {
setIsLoading(true)
const urlParams = new URLSearchParams(window.location.search);
const signature = urlParams.get("signature") || '';
// 是否在白名单
const response = await validUser(signature)
const {data, error} = response
console.log({data,error});
if (error) {
setIsAllow(false);
setIsRequestErr(true);
console.error(error);
} else {
const { code, msg } = data;
setIsAllow(code === 0);
}
setIsLoading(false)
}
//const isWorkWechat = () => {
//获取user-agaent标识头
// const ua = window.navigator.userAgent.toLowerCase();
@ -669,10 +677,12 @@ export function Home() {
}
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
className={`${
config.tightBorder && !isMobileScreen()
@ -784,5 +794,5 @@ export function Home() {
)
}
</div>
);
) : null
}

View File

@ -42,6 +42,24 @@ function getHeaders() {
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) {
return (body: any, method = "POST") =>
fetch("/api/openai", {

15705
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -23,14 +23,15 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^8.0.5",
"remark-breaks": "^3.0.2",
"rehype-katex": "^6.0.2",
"rehype-prism-plus": "^1.5.1",
"remark-breaks": "^3.0.2",
"remark-gfm": "^3.0.1",
"remark-math": "^5.1.1",
"sass": "^1.59.2",
"spark-md5": "^3.0.2",
"use-debounce": "^9.0.3",
"vconsole": "^3.15.0",
"zustand": "^4.3.6"
},
"devDependencies": {

6982
yarn.lock

File diff suppressed because it is too large Load Diff