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
42fec3a9
authored
Aug 28, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: git login
parent
64b9367c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
10 additions
and
130 deletions
+10
-130
client/data/config.json
+0
-1
client/src/api/user.ts
+1
-1
client/src/pages/api/user/account/gitLogin.ts
+0
-120
client/src/pages/login/provider.tsx
+9
-4
client/src/types/index.d.ts
+0
-1
docSite/content/docs/installation/reference/configuration.md
+0
-2
files/deploy/fastgpt/config.json
+0
-1
No files found.
client/data/config.json
View file @
42fec3a9
...
...
@@ -11,7 +11,6 @@
"scripts"
:
[]
},
"SystemParams"
:
{
"gitLoginSecret"
:
""
,
"vectorMaxProcess"
:
15
,
"qaMaxProcess"
:
15
,
"pgIvfflatProbe"
:
20
...
...
client/src/api/user.ts
View file @
42fec3a9
...
...
@@ -14,7 +14,7 @@ export const sendAuthCode = (data: {
export
const
getTokenLogin
=
()
=>
GET
<
UserType
>
(
'/user/account/tokenLogin'
);
export
const
gitLogin
=
(
params
:
{
code
:
string
;
inviterId
?:
string
})
=>
GET
<
ResLogin
>
(
'/user/account/gitLogin'
,
params
);
GET
<
ResLogin
>
(
'/
plusApi/
user/account/gitLogin'
,
params
);
export
const
postRegister
=
({
username
,
...
...
client/src/pages/api/user/account/gitLogin.ts
deleted
100644 → 0
View file @
64b9367c
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
User
}
from
'@/service/models/user'
;
import
{
generateToken
,
setCookie
}
from
'@/service/utils/tools'
;
import
axios
from
'axios'
;
import
{
parseQueryString
}
from
'@/utils/tools'
;
import
{
customAlphabet
}
from
'nanoid'
;
const
nanoid
=
customAlphabet
(
'abcdefghijklmnopqrstuvwxyz1234567890'
,
8
);
type
GithubAccessTokenType
=
{
access_token
:
string
;
expires_in
:
number
;
refresh_token
:
string
;
refresh_token_expires_in
:
number
;
token_type
:
'bearer'
;
scope
:
string
;
};
type
GithubUserType
=
{
login
:
string
;
email
:
string
;
avatar_url
:
string
;
};
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
const
{
code
,
inviterId
}
=
req
.
query
as
{
code
:
string
;
inviterId
?:
string
};
const
{
data
:
gitAccessToken
}
=
await
axios
.
post
<
string
>
(
`https://github.com/login/oauth/access_token?client_id=
${
global
.
feConfigs
.
gitLoginKey
}
&client_secret=
${
global
.
systemEnv
.
gitLoginSecret
}
&code=
${
code
}
`
);
const
jsonGitAccessToken
=
parseQueryString
(
gitAccessToken
)
as
GithubAccessTokenType
;
const
access_token
=
jsonGitAccessToken
?.
access_token
;
if
(
!
access_token
)
{
throw
new
Error
(
'access_token is null'
);
}
const
{
data
}
=
await
axios
.
get
<
GithubUserType
>
(
'https://api.github.com/user'
,
{
headers
:
{
Authorization
:
`Bearer
${
access_token
}
`
}
});
const
{
login
,
avatar_url
}
=
data
;
const
username
=
`git-
${
login
}
`
;
try
{
jsonRes
(
res
,
{
data
:
await
loginByUsername
({
username
,
res
})
});
}
catch
(
err
:
any
)
{
if
(
err
?.
code
===
500
)
{
jsonRes
(
res
,
{
data
:
await
registerUser
({
username
,
avatar
:
avatar_url
,
res
,
inviterId
})
});
return
;
}
throw
new
Error
(
err
);
}
}
catch
(
err
)
{
jsonRes
(
res
,
{
code
:
500
,
error
:
err
});
}
}
export
async
function
loginByUsername
({
username
,
res
}:
{
username
:
string
;
res
:
NextApiResponse
;
})
{
const
user
=
await
User
.
findOne
({
username
});
if
(
!
user
)
{
return
Promise
.
reject
({
code
:
500
});
}
const
token
=
generateToken
(
user
.
_id
);
setCookie
(
res
,
token
);
return
{
user
,
token
};
}
export
async
function
registerUser
({
username
,
avatar
,
inviterId
,
res
}:
{
username
:
string
;
avatar
?:
string
;
inviterId
?:
string
;
res
:
NextApiResponse
;
})
{
const
response
=
await
User
.
create
({
username
,
avatar
,
password
:
nanoid
(),
inviterId
:
inviterId
?
inviterId
:
undefined
});
// 根据 id 获取用户信息
const
user
=
await
User
.
findById
(
response
.
_id
);
if
(
!
user
)
{
return
Promise
.
reject
(
'获取用户信息异常'
);
}
const
token
=
generateToken
(
user
.
_id
);
setCookie
(
res
,
token
);
return
{
user
,
token
};
}
client/src/pages/login/provider.tsx
View file @
42fec3a9
import
React
,
{
useCallback
,
useEffect
}
from
'react'
;
import
React
,
{
useCallback
}
from
'react'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useGlobalStore
}
from
'@/store/global'
;
import
{
ResLogin
}
from
'@/api/response/user'
;
...
...
@@ -10,6 +10,7 @@ import { useToast } from '@/hooks/useToast';
import
Loading
from
'@/components/Loading'
;
import
{
serviceSideProps
}
from
'@/utils/i18n'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
{
getErrText
}
from
'@/utils/tools'
;
const
provider
=
({
code
}:
{
code
:
string
})
=>
{
const
{
loginStore
}
=
useGlobalStore
();
...
...
@@ -56,15 +57,19 @@ const provider = ({ code }: { code: string }) => {
status
:
'warning'
,
title
:
'登录异常'
});
return
router
.
replace
(
'/login'
);
return
setTimeout
(()
=>
{
router
.
replace
(
'/login'
);
},
1000
);
}
loginSuccess
(
res
);
}
catch
(
error
)
{
toast
({
status
:
'warning'
,
title
:
'登录异常'
title
:
getErrText
(
error
,
'登录异常'
)
});
router
.
replace
(
'/login'
);
setTimeout
(()
=>
{
router
.
replace
(
'/login'
);
},
1000
);
}
},
[
code
,
loginStore
,
loginSuccess
]);
...
...
client/src/types/index.d.ts
View file @
42fec3a9
...
...
@@ -29,7 +29,6 @@ export type FeConfigsType = {
};
export
type
SystemEnvType
=
{
pluginBaseUrl
?:
string
;
gitLoginSecret
?:
string
;
vectorMaxProcess
:
number
;
qaMaxProcess
:
number
;
pgIvfflatProbe
:
number
;
...
...
docSite/content/docs/installation/reference/configuration.md
View file @
42fec3a9
...
...
@@ -37,7 +37,6 @@ weight: 751
...
//
这个配置文件是系统级参数
"SystemParams"
:
{
"gitLoginSecret"
:
""
,
//
Git
登录凭证
"vectorMaxProcess"
:
15
,
//
向量生成最大进程,结合数据库性能和
key
来设置
"qaMaxProcess"
:
15
,
//
QA
生成最大进程,结合数据库性能和
key
来设置
"pgIvfflatProbe"
:
20
//
pg
vector
搜索探针。没有设置索引前可忽略,通常
50
w
组以上才需要设置。
...
...
@@ -61,7 +60,6 @@ weight: 751
"scripts"
:
[]
},
"SystemParams"
:
{
"gitLoginSecret"
:
""
,
"vectorMaxProcess"
:
15
,
"qaMaxProcess"
:
15
,
"pgIvfflatProbe"
:
20
...
...
files/deploy/fastgpt/config.json
View file @
42fec3a9
...
...
@@ -11,7 +11,6 @@
"scripts"
:
[]
},
"SystemParams"
:
{
"gitLoginSecret"
:
""
,
"vectorMaxProcess"
:
15
,
"qaMaxProcess"
:
15
,
"pgIvfflatProbe"
:
20
...
...
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