-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dataset data list api adapt (#2878)
* fix: dataset data list api adapt * update doc version * perf: fedomain env * add fedomain env
- Loading branch information
Showing
10 changed files
with
99 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { authDatasetCollection } from '@fastgpt/service/support/permission/dataset/auth'; | ||
import { MongoDatasetData } from '@fastgpt/service/core/dataset/data/schema'; | ||
import { replaceRegChars } from '@fastgpt/global/common/string/tools'; | ||
import { NextAPI } from '@/service/middleware/entry'; | ||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant'; | ||
import { ApiRequestProps } from '@fastgpt/service/type/next'; | ||
import { DatasetDataListItemType } from '@/global/core/dataset/type'; | ||
import { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/type'; | ||
|
||
export type GetDatasetDataListProps = PaginationProps & { | ||
searchText?: string; | ||
collectionId: string; | ||
}; | ||
export type GetDatasetDataListRes = PaginationResponse<DatasetDataListItemType>; | ||
|
||
async function handler( | ||
req: ApiRequestProps<GetDatasetDataListProps> | ||
): Promise<GetDatasetDataListRes> { | ||
let { offset, pageSize = 10, searchText = '', collectionId } = req.body; | ||
|
||
pageSize = Math.min(pageSize, 30); | ||
|
||
// 凭证校验 | ||
const { teamId, collection } = await authDatasetCollection({ | ||
req, | ||
authToken: true, | ||
authApiKey: true, | ||
collectionId, | ||
per: ReadPermissionVal | ||
}); | ||
|
||
const queryReg = new RegExp(`${replaceRegChars(searchText)}`, 'i'); | ||
const match = { | ||
teamId, | ||
datasetId: collection.datasetId._id, | ||
collectionId, | ||
...(searchText.trim() | ||
? { | ||
$or: [{ q: queryReg }, { a: queryReg }] | ||
} | ||
: {}) | ||
}; | ||
|
||
const [list, total] = await Promise.all([ | ||
MongoDatasetData.find(match, '_id datasetId collectionId q a chunkIndex') | ||
.sort({ chunkIndex: 1, updateTime: -1 }) | ||
.skip(offset) | ||
.limit(pageSize) | ||
.lean(), | ||
MongoDatasetData.countDocuments(match) | ||
]); | ||
|
||
return { | ||
list, | ||
total | ||
}; | ||
} | ||
|
||
export default NextAPI(handler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters