mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00

* mongo init * perf: mongo connect * perf: tts perf: whisper and tts peref: tts whisper permission log reabase (#488) * perf: modal * i18n * perf: schema lean * feat: vision model format * perf: tts loading * perf: static data * perf: tts * feat: image * perf: image * perf: upload image and title * perf: image size * doc * perf: color * doc * speaking can not select file * doc
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { CollectionWithDatasetType } from '@fastgpt/global/core/dataset/type';
|
|
import { MongoDatasetCollection } from './collection/schema';
|
|
import { MongoDataset } from './schema';
|
|
|
|
/* ============= dataset ========== */
|
|
/* find all datasetId by top datasetId */
|
|
export async function findDatasetIdTreeByTopDatasetId(
|
|
id: string,
|
|
result: string[] = []
|
|
): Promise<string[]> {
|
|
let allChildrenIds = [...result];
|
|
|
|
// find children
|
|
const children = await MongoDataset.find({ parentId: id });
|
|
|
|
for (const child of children) {
|
|
const grandChildrenIds = await findDatasetIdTreeByTopDatasetId(child._id, result);
|
|
allChildrenIds = allChildrenIds.concat(grandChildrenIds);
|
|
}
|
|
|
|
return [String(id), ...allChildrenIds];
|
|
}
|
|
|
|
export async function getCollectionWithDataset(collectionId: string) {
|
|
const data = (await MongoDatasetCollection.findById(collectionId)
|
|
.populate('datasetId')
|
|
.lean()) as CollectionWithDatasetType;
|
|
if (!data) {
|
|
return Promise.reject('Collection is not exist');
|
|
}
|
|
return data;
|
|
}
|