From e1819f48eecbd52007f04f0892517d3108d647a0 Mon Sep 17 00:00:00 2001 From: heheer Date: Thu, 26 Jun 2025 10:15:51 +0800 Subject: [PATCH] fix bugs (#5087) * fix metadata and forbid filter * team plan init * sync collection tags * fix json import * fix code * fix --- .../core/dataset/collection/controller.ts | 16 ++- .../service/core/dataset/search/controller.ts | 17 +-- .../app/ImportAppConfigEditor.tsx | 124 ++++++++++-------- projects/app/src/pages/account/info/index.tsx | 20 +-- 4 files changed, 98 insertions(+), 79 deletions(-) diff --git a/packages/service/core/dataset/collection/controller.ts b/packages/service/core/dataset/collection/controller.ts index 9f2ec299f..1091b8f96 100644 --- a/packages/service/core/dataset/collection/controller.ts +++ b/packages/service/core/dataset/collection/controller.ts @@ -37,6 +37,7 @@ import { } from '@fastgpt/global/core/dataset/training/utils'; import { DatasetDataIndexTypeEnum } from '@fastgpt/global/core/dataset/data/constants'; import { clearCollectionImages, removeDatasetImageExpiredTime } from '../image/utils'; +import { MongoDatasetCollectionTags } from '../tag/schema'; export const createCollectionAndInsertData = async ({ dataset, @@ -279,7 +280,7 @@ export async function createOneCollection({ session, ...props }: CreateOneCollec teamId, parentId, datasetId, - tags, + tags: tagIdList, fileId, rawLink, @@ -288,7 +289,18 @@ export async function createOneCollection({ session, ...props }: CreateOneCollec apiFileId } = props; // Create collection tags - const collectionTags = await createOrGetCollectionTags({ tags, teamId, datasetId, session }); + const tags = await MongoDatasetCollectionTags.find({ + teamId, + datasetId, + _id: { $in: tagIdList } + }); + + const collectionTags = await createOrGetCollectionTags({ + tags: tags.map((item) => item.tag), + teamId, + datasetId, + session + }); // Create collection const [collection] = await MongoDatasetCollection.create( diff --git a/packages/service/core/dataset/search/controller.ts b/packages/service/core/dataset/search/controller.ts index 13170b830..87ae0747c 100644 --- a/packages/service/core/dataset/search/controller.ts +++ b/packages/service/core/dataset/search/controller.ts @@ -569,17 +569,18 @@ export async function searchDatasetData( ...(filterCollectionIdList ? { collectionId: { - $in: filterCollectionIdList.map((id) => new Types.ObjectId(id)) + $in: filterCollectionIdList + .filter((id) => !forbidCollectionIdList.includes(id)) + .map((id) => new Types.ObjectId(id)) } } - : {}), - ...(forbidCollectionIdList && forbidCollectionIdList.length > 0 - ? { - collectionId: { - $nin: forbidCollectionIdList.map((id) => new Types.ObjectId(id)) + : forbidCollectionIdList?.length + ? { + collectionId: { + $nin: forbidCollectionIdList.map((id) => new Types.ObjectId(id)) + } } - } - : {}) + : {}) } }, { diff --git a/projects/app/src/pageComponents/app/ImportAppConfigEditor.tsx b/projects/app/src/pageComponents/app/ImportAppConfigEditor.tsx index 2dbcdc4f7..e8ef6f116 100644 --- a/projects/app/src/pageComponents/app/ImportAppConfigEditor.tsx +++ b/projects/app/src/pageComponents/app/ImportAppConfigEditor.tsx @@ -43,8 +43,15 @@ const ImportAppConfigEditor = ({ value, onChange, rows = 16 }: Props) => { return; } if (e.target) { - const res = JSON.parse(e.target.result as string); - onChange(JSON.stringify(res, null, 2)); + try { + const res = JSON.parse(e.target.result as string); + onChange(JSON.stringify(res, null, 2)); + } catch (error) { + toast({ + title: t('app:invalid_json_format'), + status: 'error' + }); + } } }; reader.readAsText(file); @@ -63,70 +70,75 @@ const ImportAppConfigEditor = ({ value, onChange, rows = 16 }: Props) => { const handleDrop = useCallback( async (e: DragEvent) => { e.preventDefault(); + setIsDragging(false); const file = e.dataTransfer.files[0]; console.log(file); readJSONFile(file); - setIsDragging(false); }, [readJSONFile] ); return ( <> - - {isDragging ? ( - e.preventDefault()} - onDrop={handleDrop} - onDragLeave={handleDragLeave} - > - - - - {t('app:file_recover')} - - - - ) : ( - - - - {t('common:json_config')} - - - - e.preventDefault()} - onDrop={handleDrop} - onDragLeave={handleDragLeave} - > -