4.8.10 test (#2401)
* perf: i18n * perf: i18n and img tip * perf: readme * perf: hide tool ai response * fix: copy app * fix: parse image url regx * perf: folder collection forbid update
This commit is contained in:
@@ -39,6 +39,7 @@ async function handler(
|
||||
type: app.type,
|
||||
modules: app.modules,
|
||||
edges: app.edges,
|
||||
chatConfig: app.chatConfig,
|
||||
teamId: app.teamId,
|
||||
tmbId,
|
||||
pluginData: app.pluginData
|
||||
|
||||
@@ -5,6 +5,10 @@ import { NextAPI } from '@/service/middleware/entry';
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { CommonErrEnum } from '@fastgpt/global/common/error/code/common';
|
||||
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
import { DatasetCollectionTypeEnum } from '@fastgpt/global/core/dataset/constants';
|
||||
import { ClientSession } from '@fastgpt/service/common/mongo';
|
||||
import { CollectionWithDatasetType } from '@fastgpt/global/core/dataset/type';
|
||||
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
|
||||
|
||||
export type UpdateDatasetCollectionParams = {
|
||||
id: string;
|
||||
@@ -14,6 +18,52 @@ export type UpdateDatasetCollectionParams = {
|
||||
forbid?: boolean;
|
||||
};
|
||||
|
||||
// Set folder collection children forbid status
|
||||
const updateFolderChildrenForbid = async ({
|
||||
collection,
|
||||
forbid,
|
||||
session
|
||||
}: {
|
||||
collection: CollectionWithDatasetType;
|
||||
forbid: boolean;
|
||||
session: ClientSession;
|
||||
}) => {
|
||||
// 从 collection 作为 parent 进行递归查找,找到它所有 forbid 与它相同的 child
|
||||
const find = async (parentId: string): Promise<string[]> => {
|
||||
const children = await MongoDatasetCollection.find(
|
||||
{
|
||||
teamId: collection.teamId,
|
||||
datasetId: collection.datasetId,
|
||||
parentId
|
||||
},
|
||||
'_id',
|
||||
{ session }
|
||||
);
|
||||
|
||||
const idList = children.map((item) => String(item._id));
|
||||
|
||||
const IdChildren = (await Promise.all(idList.map(find))).flat();
|
||||
|
||||
return [...idList, ...IdChildren];
|
||||
};
|
||||
|
||||
const allChildrenIdList = await find(collection._id);
|
||||
|
||||
await MongoDatasetCollection.updateMany(
|
||||
{
|
||||
_id: { $in: allChildrenIdList }
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
forbid
|
||||
}
|
||||
},
|
||||
{
|
||||
session
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
async function handler(req: ApiRequestProps<UpdateDatasetCollectionParams>) {
|
||||
const { id, parentId, name, tags, forbid } = req.body;
|
||||
|
||||
@@ -22,7 +72,7 @@ async function handler(req: ApiRequestProps<UpdateDatasetCollectionParams>) {
|
||||
}
|
||||
|
||||
// 凭证校验
|
||||
await authDatasetCollection({
|
||||
const { collection } = await authDatasetCollection({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true,
|
||||
@@ -30,15 +80,32 @@ async function handler(req: ApiRequestProps<UpdateDatasetCollectionParams>) {
|
||||
per: WritePermissionVal
|
||||
});
|
||||
|
||||
const updateFields: Record<string, any> = {
|
||||
...(parentId !== undefined && { parentId: parentId || null }),
|
||||
...(name && { name, updateTime: getCollectionUpdateTime({ name }) }),
|
||||
...(tags && { tags }),
|
||||
...(forbid !== undefined && { forbid })
|
||||
};
|
||||
await mongoSessionRun(async (session) => {
|
||||
await MongoDatasetCollection.updateOne(
|
||||
{
|
||||
_id: id
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
...(parentId !== undefined && { parentId: parentId || null }),
|
||||
...(name && { name, updateTime: getCollectionUpdateTime({ name }) }),
|
||||
...(tags && { tags }),
|
||||
...(forbid !== undefined && { forbid })
|
||||
}
|
||||
},
|
||||
{
|
||||
session
|
||||
}
|
||||
);
|
||||
|
||||
await MongoDatasetCollection.findByIdAndUpdate(id, {
|
||||
$set: updateFields
|
||||
// Folder update forbid
|
||||
if (collection.type === DatasetCollectionTypeEnum.folder && forbid !== undefined) {
|
||||
await updateFolderChildrenForbid({
|
||||
collection,
|
||||
forbid,
|
||||
session
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user