feat: modeldata接口。fix: 部分权限校验bug
This commit is contained in:
36
src/service/models/modelData.ts
Normal file
36
src/service/models/modelData.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/* 模型的知识库 */
|
||||
import { Schema, model, models, Model as MongoModel } from 'mongoose';
|
||||
import { ModelDataSchema as ModelDataType } from '@/types/mongoSchema';
|
||||
|
||||
const ModelDataSchema = new Schema({
|
||||
modelId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'model',
|
||||
required: true
|
||||
},
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: true
|
||||
},
|
||||
q: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
a: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
status: {
|
||||
type: Number,
|
||||
enum: [0, 1, 2],
|
||||
default: 1
|
||||
},
|
||||
createTime: {
|
||||
type: Date,
|
||||
default: () => new Date()
|
||||
}
|
||||
});
|
||||
|
||||
export const ModelData: MongoModel<ModelDataType> =
|
||||
models['modelData'] || model('modelData', ModelDataSchema);
|
||||
@@ -33,6 +33,7 @@ export async function connectToDatabase(): Promise<void> {
|
||||
export * from './models/authCode';
|
||||
export * from './models/chat';
|
||||
export * from './models/model';
|
||||
export * from './models/modelData';
|
||||
export * from './models/user';
|
||||
export * from './models/training';
|
||||
export * from './models/bill';
|
||||
|
||||
@@ -34,7 +34,10 @@ export const authChat = async (chatId: string, authorization?: string) => {
|
||||
|
||||
// 凭证校验
|
||||
if (!chat.isShare) {
|
||||
await authToken(authorization);
|
||||
const userId = await authToken(authorization);
|
||||
if (userId !== String(chat.userId._id)) {
|
||||
return Promise.reject('无权使用该对话');
|
||||
}
|
||||
} else if (chat.loadAmount === 0 || chat.expiredTime <= Date.now()) {
|
||||
return Promise.reject('聊天框已过期');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user