(req: ApiRequestProps)
| 43 | import { parseApiInput } from '@fastgpt/service/common/zod/requestParseError'; |
| 44 | |
| 45 | async function handler(req: ApiRequestProps): Promise<CreateDatasetWithFilesResponse> { |
| 46 | const { datasetParams, files } = parseApiInput({ |
| 47 | req, |
| 48 | bodySchema: CreateDatasetWithFilesBodySchema |
| 49 | }).body; |
| 50 | const { |
| 51 | parentId, |
| 52 | name, |
| 53 | avatar, |
| 54 | vectorModel = getDefaultEmbeddingModel()?.model, |
| 55 | agentModel = getDefaultLLMModel()?.model, |
| 56 | vlmModel = getDefaultVLMModel()?.model |
| 57 | } = datasetParams; |
| 58 | |
| 59 | const { teamId, tmbId, userId } = parentId |
| 60 | ? await authDataset({ |
| 61 | req, |
| 62 | datasetId: parentId, |
| 63 | authToken: true, |
| 64 | authApiKey: true, |
| 65 | per: WritePermissionVal |
| 66 | }) |
| 67 | : await authUserPer({ |
| 68 | req, |
| 69 | authToken: true, |
| 70 | authApiKey: true, |
| 71 | per: TeamDatasetCreatePermissionVal |
| 72 | }); |
| 73 | |
| 74 | // check limit |
| 75 | await checkTeamDatasetLimit(teamId); |
| 76 | |
| 77 | try { |
| 78 | const result = await mongoSessionRun(async (session) => { |
| 79 | // 1. Create dataset |
| 80 | const [dataset] = await MongoDataset.create( |
| 81 | [ |
| 82 | { |
| 83 | ...parseParentIdInMongo(parentId), |
| 84 | name, |
| 85 | teamId, |
| 86 | tmbId, |
| 87 | vectorModel, |
| 88 | agentModel, |
| 89 | vlmModel, |
| 90 | avatar, |
| 91 | intro: '', |
| 92 | type: DatasetTypeEnum.dataset |
| 93 | } |
| 94 | ], |
| 95 | { session, ordered: true } |
| 96 | ); |
| 97 | |
| 98 | // 2. Create permission |
| 99 | await MongoResourcePermission.insertOne({ |
| 100 | teamId, |
| 101 | tmbId, |
| 102 | resourceId: dataset._id, |
nothing calls this directly
no test coverage detected