mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
fix: model auth
This commit is contained in:
parent
33154a9c19
commit
b7cd4dec89
|
|
@ -1,7 +1,8 @@
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const ChatSchema = new Schema({
|
|||
expiredTime: {
|
||||
// 过期时间
|
||||
type: Number,
|
||||
default: Date.now()
|
||||
default: () => new Date()
|
||||
},
|
||||
loadAmount: {
|
||||
// 剩余加载次数
|
||||
|
|
|
|||
Loading…
Reference in New Issue