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
85e94966
authored
May 26, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: kb delete and google auth
parent
dc1c1d13
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
12 deletions
+25
-12
src/hooks/useSendCode.ts
+1
-1
src/pages/api/plugins/kb/delete.ts
+20
-8
src/utils/plugin/google.ts
+4
-3
No files found.
src/hooks/useSendCode.ts
View file @
85e94966
...
@@ -54,7 +54,7 @@ export const useSendCode = () => {
...
@@ -54,7 +54,7 @@ export const useSendCode = () => {
}
}
setCodeSending
(
false
);
setCodeSending
(
false
);
},
},
[
toast
]
[
googleVerKey
,
toast
]
);
);
return
{
return
{
...
...
src/pages/api/plugins/kb/delete.ts
View file @
85e94966
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
KB
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
KB
,
Model
,
TrainingData
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
PgClient
}
from
'@/service/pg'
;
import
{
PgClient
}
from
'@/service/pg'
;
import
{
Types
}
from
'mongoose'
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
try
{
...
@@ -19,19 +20,30 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -19,19 +20,30 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
await
connectToDatabase
();
await
connectToDatabase
();
// delete mongo data
await
KB
.
findOneAndDelete
({
_id
:
id
,
userId
});
// delete all pg data
// delete all pg data
// 删除 pg 中所有该模型的数据
await
PgClient
.
delete
(
'modelData'
,
{
await
PgClient
.
delete
(
'modelData'
,
{
where
:
[[
'user_id'
,
userId
],
'AND'
,
[
'kb_id'
,
id
]]
where
:
[[
'user_id'
,
userId
],
'AND'
,
[
'kb_id'
,
id
]]
});
});
// delete training data
await
TrainingData
.
deleteMany
({
userId
,
kbId
:
id
});
// delete related model
// delete related model
await
Model
.
updateMany
(
{
userId
},
{
$pull
:
{
'chat.relatedKbs'
:
new
Types
.
ObjectId
(
id
)
}
}
);
// delete kb data
await
KB
.
findOneAndDelete
({
_id
:
id
,
userId
});
jsonRes
(
res
);
jsonRes
(
res
);
}
catch
(
err
)
{
}
catch
(
err
)
{
...
...
src/utils/plugin/google.ts
View file @
85e94966
...
@@ -2,7 +2,7 @@ import axios from 'axios';
...
@@ -2,7 +2,7 @@ import axios from 'axios';
import
{
Obj2Query
}
from
'../tools'
;
import
{
Obj2Query
}
from
'../tools'
;
export
const
getClientToken
=
(
googleVerKey
:
string
)
=>
{
export
const
getClientToken
=
(
googleVerKey
:
string
)
=>
{
if
(
!
grecaptcha
?.
ready
)
return
''
;
if
(
typeof
grecaptcha
===
'undefined'
||
!
grecaptcha
?.
ready
)
return
''
;
return
new
Promise
<
string
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
string
>
((
resolve
,
reject
)
=>
{
grecaptcha
.
ready
(
async
()
=>
{
grecaptcha
.
ready
(
async
()
=>
{
try
{
try
{
...
@@ -23,10 +23,11 @@ export const authGoogleToken = async (data: {
...
@@ -23,10 +23,11 @@ export const authGoogleToken = async (data: {
response
:
string
;
response
:
string
;
remoteip
?:
string
;
remoteip
?:
string
;
})
=>
{
})
=>
{
const
res
=
await
axios
.
post
<
{
score
?:
number
}
>
(
const
res
=
await
axios
.
post
<
{
score
?:
number
;
success
:
boolean
}
>
(
`https://www.recaptcha.net/recaptcha/api/siteverify?
${
Obj2Query
(
data
)}
`
`https://www.recaptcha.net/recaptcha/api/siteverify?
${
Obj2Query
(
data
)}
`
);
);
if
(
res
.
data
.
score
&&
res
.
data
.
score
>=
0.5
)
{
if
(
res
.
data
.
success
&&
res
.
data
.
score
&&
res
.
data
.
score
>=
0.7
)
{
return
Promise
.
resolve
(
''
);
return
Promise
.
resolve
(
''
);
}
}
return
Promise
.
reject
(
'非法环境'
);
return
Promise
.
reject
(
'非法环境'
);
...
...
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