fix: config

This commit is contained in:
archer
2023-08-05 11:51:40 +08:00
parent 761ae74b0a
commit 37a6293f5e
11 changed files with 39 additions and 67 deletions

View File

@@ -95,27 +95,7 @@ const appSchema = new mongoose.Schema({
updateTime: Date updateTime: Date
}); });
const SystemSchema = new mongoose.Schema({
vectorMaxProcess: {
type: Number,
default: 10
},
qaMaxProcess: {
type: Number,
default: 10
},
pgIvfflatProbe: {
type: Number,
default: 10
},
sensitiveCheck: {
type: Boolean,
default: false
}
});
export const App = mongoose.models['app'] || mongoose.model('app', appSchema); export const App = mongoose.models['app'] || mongoose.model('app', appSchema);
export const Kb = mongoose.models['kb'] || mongoose.model('kb', kbSchema); export const Kb = mongoose.models['kb'] || mongoose.model('kb', kbSchema);
export const User = mongoose.models['user'] || mongoose.model('user', UserSchema); export const User = mongoose.models['user'] || mongoose.model('user', UserSchema);
export const Pay = mongoose.models['pay'] || mongoose.model('pay', paySchema); export const Pay = mongoose.models['pay'] || mongoose.model('pay', paySchema);
export const System = mongoose.models['system'] || mongoose.model('system', SystemSchema);

2
client/.gitignore vendored
View File

@@ -29,4 +29,4 @@ platform.json
testApi/ testApi/
local/ local/
.husky/ .husky/
data/config.json.local data/*.local

View File

@@ -5,15 +5,14 @@
"show_appStore": false, "show_appStore": false,
"show_userDetail": false, "show_userDetail": false,
"show_git": true, "show_git": true,
"beianText": "",
"systemTitle": "FastAI", "systemTitle": "FastAI",
"authorText": "Made by FastAI Team." "authorText": "Made by FastAI Team."
}, },
"SystemParams": { "SystemParams": {
"beianText": "",
"vectorMaxProcess": 15, "vectorMaxProcess": 15,
"qaMaxProcess": 15, "qaMaxProcess": 15,
"pgIvfflatProbe": 20, "pgIvfflatProbe": 20
"sensitiveCheck": false
}, },
"ChatModels": [ "ChatModels": [
{ {
@@ -63,5 +62,6 @@
"name": "Embedding-2", "name": "Embedding-2",
"price": 0.2 "price": 0.2
} }
] ],
"plugins": {}
} }

View File

@@ -4,7 +4,7 @@ import { UserAuthTypeEnum } from '@/constants/common';
let timer: any; let timer: any;
import { useToast } from './useToast'; import { useToast } from './useToast';
import { getClientToken } from '@/utils/plugin/google'; import { getClientToken } from '@/utils/plugin/google';
import { googleClientVerKey } from '@/store/static'; import { feConfigs } from '@/store/static';
export const useSendCode = () => { export const useSendCode = () => {
const { toast } = useToast(); const { toast } = useToast();
@@ -27,7 +27,7 @@ export const useSendCode = () => {
await sendAuthCode({ await sendAuthCode({
username, username,
type, type,
googleToken: await getClientToken(googleClientVerKey) googleToken: await getClientToken(feConfigs.googleClientVerKey)
}); });
setCodeCountDown(60); setCodeCountDown(60);
timer = setInterval(() => { timer = setInterval(() => {

View File

@@ -37,15 +37,15 @@ function App({ Component, pageProps }: AppProps) {
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const [googleClientVerKey, setGoogleVerKey] = useState<string>(); const [googleClientVerKey, setGoogleVerKey] = useState<string>();
const [baiduTongji, setBaiduTongji] = useState<string>(); const [baiduTongjiUrl, setBaiduTongjiUrl] = useState<string>();
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const { const {
systemEnv: { googleClientVerKey, baiduTongji } feConfigs: { googleClientVerKey, baiduTongjiUrl }
} = await clientInitData(); } = await clientInitData();
setGoogleVerKey(googleClientVerKey); setGoogleVerKey(googleClientVerKey);
setBaiduTongji(baiduTongji); setBaiduTongjiUrl(baiduTongjiUrl);
})(); })();
}, []); }, []);
@@ -69,7 +69,7 @@ function App({ Component, pageProps }: AppProps) {
<Script src="/js/qrcode.min.js" strategy="lazyOnload"></Script> <Script src="/js/qrcode.min.js" strategy="lazyOnload"></Script>
<Script src="/js/pdf.js" strategy="lazyOnload"></Script> <Script src="/js/pdf.js" strategy="lazyOnload"></Script>
<Script src="/js/html2pdf.bundle.min.js" strategy="lazyOnload"></Script> <Script src="/js/html2pdf.bundle.min.js" strategy="lazyOnload"></Script>
{baiduTongji && <Script src={baiduTongji} strategy="lazyOnload"></Script>} {baiduTongjiUrl && <Script src={baiduTongjiUrl} strategy="lazyOnload"></Script>}
{googleClientVerKey && ( {googleClientVerKey && (
<> <>
<Script <Script

View File

@@ -28,10 +28,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
} }
export async function sensitiveCheck({ input }: Props) { export async function sensitiveCheck({ input }: Props) {
if (!global.systemEnv.sensitiveCheck) {
return Promise.resolve('');
}
const response = await axios({ const response = await axios({
...axiosConfig(), ...axiosConfig(),
method: 'POST', method: 'POST',

View File

@@ -1,4 +1,4 @@
import type { FeConfigsType, SystemEnvType } from '@/types'; import type { FeConfigsType } from '@/types';
import type { NextApiRequest, NextApiResponse } from 'next'; import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response'; import { jsonRes } from '@/service/response';
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
@@ -12,7 +12,6 @@ export type InitDateResponse = {
chatModels: ChatModelItemType[]; chatModels: ChatModelItemType[];
qaModels: QAModelItemType[]; qaModels: QAModelItemType[];
vectorModels: VectorModelItemType[]; vectorModels: VectorModelItemType[];
systemEnv: SystemEnvType;
feConfigs: FeConfigsType; feConfigs: FeConfigsType;
}; };
@@ -22,7 +21,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
} }
jsonRes<InitDateResponse>(res, { jsonRes<InitDateResponse>(res, {
data: { data: {
systemEnv: global.systemEnv,
feConfigs: global.feConfigs, feConfigs: global.feConfigs,
chatModels: global.chatModels, chatModels: global.chatModels,
qaModels: global.qaModels, qaModels: global.qaModels,
@@ -34,8 +32,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const defaultSystemEnv = { const defaultSystemEnv = {
vectorMaxProcess: 15, vectorMaxProcess: 15,
qaMaxProcess: 15, qaMaxProcess: 15,
pgIvfflatProbe: 20, pgIvfflatProbe: 20
sensitiveCheck: false
}; };
const defaultFeConfigs = { const defaultFeConfigs = {
show_emptyChat: true, show_emptyChat: true,
@@ -102,7 +99,7 @@ export async function getInitConfig() {
global.vectorModels = res.VectorModels || defaultVectorModels; global.vectorModels = res.VectorModels || defaultVectorModels;
} catch (error) { } catch (error) {
setDefaultData(); setDefaultData();
console.log('get init config error, set default'); console.log('get init config error, set default', error);
} }
} }

View File

@@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
import { Card, Box, Link, Flex, Image, Button } from '@chakra-ui/react'; import { Card, Box, Link, Flex, Image, Button } from '@chakra-ui/react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useGlobalStore } from '@/store/global'; import { useGlobalStore } from '@/store/global';
import { beianText } from '@/store/static';
import { feConfigs } from '@/store/static'; import { feConfigs } from '@/store/static';
import { serviceSideProps } from '@/utils/i18n'; import { serviceSideProps } from '@/utils/i18n';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
@@ -215,19 +214,17 @@ const Home = () => {
</Flex> </Flex>
</Flex> </Flex>
{feConfigs?.authorText && ( <Box w={'100%'} mt={'100vh'} px={[5, 10]} pb={[5, 10]}>
<Box w={'100%'} mt={'100vh'} px={[5, 10]} pb={[5, 10]}> <Card p={5} mt={4} textAlign={'center'}>
<Card p={5} mt={4} textAlign={'center'}> {feConfigs?.beianText && (
{beianText && ( <Link href="https://beian.miit.gov.cn/" target="_blank">
<Link href="https://beian.miit.gov.cn/" target="_blank"> {feConfigs.beianText}
{beianText} </Link>
</Link> )}
)}
<Box>{feConfigs?.authorText}</Box> {feConfigs?.authorText && <Box>{feConfigs?.authorText}</Box>}
</Card> </Card>
</Box> </Box>
)}
</Flex> </Flex>
); );
}; };

View File

@@ -22,8 +22,7 @@ export async function connectToDatabase(): Promise<void> {
global.systemEnv = { global.systemEnv = {
vectorMaxProcess: 10, vectorMaxProcess: 10,
qaMaxProcess: 10, qaMaxProcess: 10,
pgIvfflatProbe: 10, pgIvfflatProbe: 10
sensitiveCheck: false
}; };
global.sendInformQueue = []; global.sendInformQueue = [];
global.sendInformQueueLen = 0; global.sendInformQueueLen = 0;

View File

@@ -8,9 +8,6 @@ import { getInitData } from '@/api/system';
import { delay } from '@/utils/tools'; import { delay } from '@/utils/tools';
import { FeConfigsType } from '@/types'; import { FeConfigsType } from '@/types';
export let beianText: string | undefined;
export let googleClientVerKey: string | undefined;
export let baiduTongji: string | undefined;
export let chatModelList: ChatModelItemType[] = []; export let chatModelList: ChatModelItemType[] = [];
export let qaModelList: QAModelItemType[] = []; export let qaModelList: QAModelItemType[] = [];
export let vectorModelList: VectorModelItemType[] = []; export let vectorModelList: VectorModelItemType[] = [];
@@ -26,9 +23,6 @@ export const clientInitData = async (): Promise<InitDateResponse> => {
qaModelList = res.qaModels; qaModelList = res.qaModels;
vectorModelList = res.vectorModels; vectorModelList = res.vectorModels;
feConfigs = res.feConfigs; feConfigs = res.feConfigs;
beianText = res.systemEnv?.beianText;
googleClientVerKey = res.systemEnv?.googleClientVerKey;
baiduTongji = res.systemEnv?.baiduTongji;
return res; return res;
} catch (error) { } catch (error) {

View File

@@ -21,16 +21,23 @@ export type FeConfigsType = {
show_git?: boolean; show_git?: boolean;
systemTitle?: string; systemTitle?: string;
authorText?: string; authorText?: string;
};
export type SystemEnvType = {
beianText?: string; beianText?: string;
googleClientVerKey?: string; googleClientVerKey?: string;
baiduTongjiUrl?: string;
};
export type SystemEnvType = {
googleServiceVerKey?: string; googleServiceVerKey?: string;
baiduTongji?: string;
vectorMaxProcess: number; vectorMaxProcess: number;
qaMaxProcess: number; qaMaxProcess: number;
pgIvfflatProbe: number; pgIvfflatProbe: number;
sensitiveCheck: boolean; };
type PluginItemType = {
url: string;
auth: string;
};
export type PluginType = {
authCode?: PluginItemType;
moderationsCheck?: PluginItemType;
}; };
declare global { declare global {
@@ -42,11 +49,13 @@ declare global {
var OpenAiEncMap: Tiktoken; var OpenAiEncMap: Tiktoken;
var sendInformQueue: (() => Promise<void>)[]; var sendInformQueue: (() => Promise<void>)[];
var sendInformQueueLen: number; var sendInformQueueLen: number;
var feConfigs: FeConfigsType;
var systemEnv: SystemEnvType; var systemEnv: SystemEnvType;
var;
var chatModels: ChatModelItemType[]; var chatModels: ChatModelItemType[];
var qaModels: QAModelItemType[]; var qaModels: QAModelItemType[];
var vectorModels: VectorModelItemType[]; var vectorModels: VectorModelItemType[];
var feConfigs: FeConfigsType;
interface Window { interface Window {
['pdfjs-dist/build/pdf']: any; ['pdfjs-dist/build/pdf']: any;