mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-20 10:45:52 +00:00
fix: model auth
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { jsonRes } from '@/service/response';
|
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 { authToken } from '@/service/utils/tools';
|
||||||
|
import type { ModelSchema } from '@/types/mongoSchema';
|
||||||
|
|
||||||
/* 获取我的模型 */
|
/* 获取我的模型 */
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
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();
|
await connectToDatabase();
|
||||||
|
|
||||||
|
// 校验是否为用户的模型
|
||||||
|
const model = await Model.findOne<ModelSchema>({
|
||||||
|
_id: modelId,
|
||||||
|
userId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!model) {
|
||||||
|
throw new Error('无权使用该模型');
|
||||||
|
}
|
||||||
|
|
||||||
// 创建 chat 数据
|
// 创建 chat 数据
|
||||||
const response = await Chat.create({
|
const response = await Chat.create({
|
||||||
userId,
|
userId,
|
||||||
|
@@ -15,7 +15,7 @@ const ChatSchema = new Schema({
|
|||||||
expiredTime: {
|
expiredTime: {
|
||||||
// 过期时间
|
// 过期时间
|
||||||
type: Number,
|
type: Number,
|
||||||
default: Date.now()
|
default: () => new Date()
|
||||||
},
|
},
|
||||||
loadAmount: {
|
loadAmount: {
|
||||||
// 剩余加载次数
|
// 剩余加载次数
|
||||||
|
Reference in New Issue
Block a user