Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
97c7984d
authored
Jul 27, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: init db and config
parent
aa7fb6a6
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
74 additions
and
18 deletions
+74
-18
client/.gitignore
+2
-0
client/src/api/user.ts
+2
-2
client/src/hooks/useConfirm.tsx
+6
-1
client/src/pages/api/system/getInitData.ts
+2
-1
client/src/pages/login/components/LoginForm.tsx
+3
-12
client/src/pages/login/components/RegisterForm.tsx
+1
-1
client/src/service/mongo.ts
+58
-1
No files found.
client/.gitignore
View file @
97c7984d
...
@@ -29,3 +29,4 @@ platform.json
...
@@ -29,3 +29,4 @@ platform.json
testApi/
testApi/
local/
local/
.husky/
.husky/
data/config.json.local
\ No newline at end of file
client/src/api/user.ts
View file @
97c7984d
import
{
GET
,
POST
,
PUT
}
from
'./request'
;
import
{
GET
,
POST
,
PUT
}
from
'./request'
;
import
{
createHashPassword
,
Obj2Query
}
from
'@/utils/tools'
;
import
{
createHashPassword
}
from
'@/utils/tools'
;
import
{
ResLogin
,
PromotionRecordType
}
from
'./response/user'
;
import
{
ResLogin
}
from
'./response/user'
;
import
{
UserAuthTypeEnum
}
from
'@/constants/common'
;
import
{
UserAuthTypeEnum
}
from
'@/constants/common'
;
import
{
UserBillType
,
UserType
,
UserUpdateParams
}
from
'@/types/user'
;
import
{
UserBillType
,
UserType
,
UserUpdateParams
}
from
'@/types/user'
;
import
type
{
PagingData
,
RequestPaging
}
from
'@/types'
;
import
type
{
PagingData
,
RequestPaging
}
from
'@/types'
;
...
...
client/src/hooks/useConfirm.tsx
View file @
97c7984d
...
@@ -32,7 +32,12 @@ export const useConfirm = (props: { title?: string; content: string }) => {
...
@@ -32,7 +32,12 @@ export const useConfirm = (props: { title?: string; content: string }) => {
),
),
ConfirmModal
:
useCallback
(
ConfirmModal
:
useCallback
(
()
=>
(
()
=>
(
<
AlertDialog
isOpen=
{
isOpen
}
leastDestructiveRef=
{
cancelRef
}
onClose=
{
onClose
}
>
<
AlertDialog
isOpen=
{
isOpen
}
leastDestructiveRef=
{
cancelRef
}
autoFocus=
{
false
}
onClose=
{
onClose
}
>
<
AlertDialogOverlay
>
<
AlertDialogOverlay
>
<
AlertDialogContent
maxW=
{
'min(90vw,400px)'
}
>
<
AlertDialogContent
maxW=
{
'min(90vw,400px)'
}
>
<
AlertDialogHeader
fontSize=
"lg"
fontWeight=
"bold"
>
<
AlertDialogHeader
fontSize=
"lg"
fontWeight=
"bold"
>
...
...
client/src/pages/api/system/getInitData.ts
View file @
97c7984d
...
@@ -90,7 +90,8 @@ const defaultVectorModels = [
...
@@ -90,7 +90,8 @@ const defaultVectorModels = [
export
async
function
getInitConfig
()
{
export
async
function
getInitConfig
()
{
try
{
try
{
const
res
=
JSON
.
parse
(
readFileSync
(
'data/config.json'
,
'utf-8'
));
const
filename
=
process
.
env
.
NODE_ENV
===
'development'
?
'config.json.local'
:
'config.json'
;
const
res
=
JSON
.
parse
(
readFileSync
(
`data/
${
filename
}
`
,
'utf-8'
));
console
.
log
(
res
);
console
.
log
(
res
);
global
.
systemEnv
=
res
.
SystemParams
||
defaultSystemEnv
;
global
.
systemEnv
=
res
.
SystemParams
||
defaultSystemEnv
;
...
...
client/src/pages/login/components/LoginForm.tsx
View file @
97c7984d
...
@@ -60,15 +60,10 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -60,15 +60,10 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
<
form
onSubmit=
{
handleSubmit
(
onclickLogin
)
}
>
<
form
onSubmit=
{
handleSubmit
(
onclickLogin
)
}
>
<
FormControl
mt=
{
8
}
isInvalid=
{
!!
errors
.
username
}
>
<
FormControl
mt=
{
8
}
isInvalid=
{
!!
errors
.
username
}
>
<
Input
<
Input
placeholder=
"邮箱/手机号"
placeholder=
"邮箱/手机号
/用户名
"
size=
{
[
'md'
,
'lg'
]
}
size=
{
[
'md'
,
'lg'
]
}
{
...
register
('
username
',
{
{
...
register
('
username
',
{
required
:
'邮箱/手机号不能为空',
required
:
'邮箱/手机号/用户名不能为空'
pattern
:
{
value
:
/(^1[3456789]\
d
{9}
$
)|(^[
A
-
Za
-
z0
-9]+([
_
\
.
][
A
-
Za
-
z0
-9]+)*@([
A
-
Za
-
z0
-9\-]+\
.
)+[
A
-
Za
-
z
]{2,6}
$
)/,
message
:
'邮箱/手机号格式错误'
}
})}
})}
></
Input
>
></
Input
>
<
FormErrorMessage
position=
{
'absolute'
}
fontSize=
"xs"
>
<
FormErrorMessage
position=
{
'absolute'
}
fontSize=
"xs"
>
...
@@ -82,13 +77,9 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -82,13 +77,9 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
placeholder=
"密码"
placeholder=
"密码"
{
...
register
('
password
',
{
{
...
register
('
password
',
{
required
:
'密码不能为空',
required
:
'密码不能为空',
minLength
:
{
value
:
4,
message
:
'密码最少4位最多12位'
},
maxLength
:
{
maxLength
:
{
value
:
12,
value
:
12,
message
:
'密码最
少4位最
多12位'
message
:
'密码最多12位'
}
}
})}
})}
></
Input
>
></
Input
>
...
...
client/src/pages/login/components/RegisterForm.tsx
View file @
97c7984d
...
@@ -65,7 +65,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -65,7 +65,7 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
title
:
`注册成功`
,
title
:
`注册成功`
,
status
:
'success'
status
:
'success'
});
});
// aut
register a model
// aut
o register template app
appTemplates
.
forEach
((
template
)
=>
{
appTemplates
.
forEach
((
template
)
=>
{
postCreateApp
({
postCreateApp
({
avatar
:
template
.
avatar
,
avatar
:
template
.
avatar
,
...
...
client/src/service/mongo.ts
View file @
97c7984d
...
@@ -2,9 +2,13 @@ import mongoose from 'mongoose';
...
@@ -2,9 +2,13 @@ import mongoose from 'mongoose';
import
tunnel
from
'tunnel'
;
import
tunnel
from
'tunnel'
;
import
{
startQueue
}
from
'./utils/tools'
;
import
{
startQueue
}
from
'./utils/tools'
;
import
{
getInitConfig
}
from
'@/pages/api/system/getInitData'
;
import
{
getInitConfig
}
from
'@/pages/api/system/getInitData'
;
import
{
User
}
from
'./models/user'
;
import
{
PRICE_SCALE
}
from
'@/constants/common'
;
import
{
connectPg
,
PgClient
}
from
'./pg'
;
import
{
createHashPassword
}
from
'@/utils/tools'
;
/**
/**
*
连接 MongoDB 数据库
*
connect MongoDB and init data
*/
*/
export
async
function
connectToDatabase
():
Promise
<
void
>
{
export
async
function
connectToDatabase
():
Promise
<
void
>
{
if
(
global
.
mongodb
)
{
if
(
global
.
mongodb
)
{
...
@@ -45,6 +49,9 @@ export async function connectToDatabase(): Promise<void> {
...
@@ -45,6 +49,9 @@ export async function connectToDatabase(): Promise<void> {
maxPoolSize
:
Number
(
process
.
env
.
DB_MAX_LINK
||
5
),
maxPoolSize
:
Number
(
process
.
env
.
DB_MAX_LINK
||
5
),
minPoolSize
:
2
minPoolSize
:
2
});
});
initRootUser
();
initPg
();
console
.
log
(
'mongo connected'
);
console
.
log
(
'mongo connected'
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'error->'
,
'mongo connect error'
);
console
.
log
(
'error->'
,
'mongo connect error'
);
...
@@ -55,6 +62,56 @@ export async function connectToDatabase(): Promise<void> {
...
@@ -55,6 +62,56 @@ export async function connectToDatabase(): Promise<void> {
startQueue
();
startQueue
();
}
}
async
function
initRootUser
()
{
try
{
const
rootUser
=
await
User
.
findOne
({
username
:
'root'
});
if
(
rootUser
)
{
console
.
log
(
'root user already exists'
);
return
;
}
const
psw
=
process
.
env
.
DEFAULT_ROOT_PSW
||
'123456'
;
await
User
.
create
({
username
:
'root'
,
password
:
createHashPassword
(
psw
),
balance
:
100
*
PRICE_SCALE
});
console
.
log
(
`create root user success`
,
{
username
:
'root'
,
password
:
psw
});
}
catch
(
error
)
{
console
.
log
(
'init root user error'
,
error
);
initRootUser
();
}
}
async
function
initPg
()
{
try
{
await
connectPg
();
await
PgClient
.
query
(
`
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS modelData (
id BIGSERIAL PRIMARY KEY,
vector VECTOR(1536) NOT NULL,
user_id VARCHAR(50) NOT NULL,
kb_id VARCHAR(50) NOT NULL,
source VARCHAR(100),
q TEXT NOT NULL,
a TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS modelData_userId_index ON modelData USING HASH (user_id);
CREATE INDEX IF NOT EXISTS modelData_kbId_index ON modelData USING HASH (kb_id);
CREATE INDEX IF NOT EXISTS idx_model_data_md5_q_a_user_id_kb_id ON modelData (md5(q), md5(a), user_id, kb_id);
`
);
console
.
log
(
'init pg successful'
);
}
catch
(
error
)
{
console
.
log
(
'init pg error'
,
error
);
initPg
();
}
}
export
*
from
'./models/authCode'
;
export
*
from
'./models/authCode'
;
export
*
from
'./models/chat'
;
export
*
from
'./models/chat'
;
export
*
from
'./models/app'
;
export
*
from
'./models/app'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment