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
b7cd4dec
authored
Apr 08, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: model auth
parent
33154a9c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
src/pages/api/chat/generate.ts
+12
-1
src/service/models/chat.ts
+1
-1
No files found.
src/pages/api/chat/generate.ts
View file @
b7cd4dec
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
Chat
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
Model
,
Chat
}
from
'@/service/mongo'
;
import
{
authToken
}
from
'@/service/utils/tools'
;
import
type
{
ModelSchema
}
from
'@/types/mongoSchema'
;
/* 获取我的模型 */
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
...
...
@@ -24,6 +25,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
await
connectToDatabase
();
// 校验是否为用户的模型
const
model
=
await
Model
.
findOne
<
ModelSchema
>
({
_id
:
modelId
,
userId
});
if
(
!
model
)
{
throw
new
Error
(
'无权使用该模型'
);
}
// 创建 chat 数据
const
response
=
await
Chat
.
create
({
userId
,
...
...
src/service/models/chat.ts
View file @
b7cd4dec
...
...
@@ -15,7 +15,7 @@ const ChatSchema = new Schema({
expiredTime
:
{
// 过期时间
type
:
Number
,
default
:
Date
.
now
()
default
:
()
=>
new
Date
()
},
loadAmount
:
{
// 剩余加载次数
...
...
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