Skip to content

Commit

Permalink
fix metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Jan 21, 2025
1 parent 0bb93b9 commit d44fc26
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 48 deletions.
1 change: 1 addition & 0 deletions packages/global/core/dataset/apiDataset.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type APIFileServer = {
export type APIFileListResponse = {
list: APIFileItem[];
total: number;
metaData?: Record<string, any>;
};

export type APIFileContentResponse = {
Expand Down
12 changes: 5 additions & 7 deletions packages/web/hooks/useScrollPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,12 @@ export function useScrollPagination<
const res = await api({
offset,
pageSize,
...metaData,
metaData,
...params
} as TParams);

const { total: totalCount, list: dataList, metaData: resMetaData } = res;

setTotal(totalCount);
setMetaData(resMetaData);
setTotal(res.total);
setMetaData(res.metaData);

if (scrollLoadType === 'top') {
const prevHeight = ScrollContainerRef?.current?.scrollHeight || 0;
Expand All @@ -250,10 +248,10 @@ export function useScrollPagination<
);
}

setData((prevData) => (init ? dataList : [...dataList, ...prevData]));
setData((prevData) => (init ? res.list : [...res.list, ...prevData]));
adjustScrollPosition();
} else {
setData((prevData) => (init ? dataList : [...prevData, ...dataList]));
setData((prevData) => (init ? res.list : [...prevData, ...res.list]));
}
} catch (error: any) {
if (showErrorToast) {
Expand Down
19 changes: 4 additions & 15 deletions projects/app/src/pages/api/core/dataset/apiDataset/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,11 @@ export type GetApiDatasetFileListProps = {
datasetId: string;
offset: number;
pageSize: number;
};

export type GetApiDatasetFileListResponse = {
list: APIFileItem[];
total: number;
metaData?: Record<string, any>;
};

async function handler(req: NextApiRequest) {
let {
searchKey = '',
parentId = null,
datasetId,
nextPageToken = '',
pageSize,
offset = 0
} = req.body;
let { searchKey = '', parentId = null, datasetId, pageSize, offset = 0, metaData } = req.body;

const { dataset } = await authDataset({
req,
Expand Down Expand Up @@ -60,9 +49,9 @@ async function handler(req: NextApiRequest) {
feishuServer,
yuqueServer,
parentId,
nextPageToken,
offset,
pageSize
pageSize,
metaData
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import { ParentTreePathItemType } from '@fastgpt/global/common/parentFolder/type
import FolderPath from '@/components/common/folder/Path';
import { getSourceNameIcon } from '@fastgpt/global/core/dataset/utils';
import MyBox from '@fastgpt/web/components/common/MyBox';
import { APIFileItem } from '@fastgpt/global/core/dataset/apiDataset';
import { APIFileItem, APIFileListResponse } from '@fastgpt/global/core/dataset/apiDataset';
import SearchInput from '@fastgpt/web/components/common/Input/SearchInput';
import { useMount } from 'ahooks';
import { useScrollPagination } from '@fastgpt/web/hooks/useScrollPagination';
import {
GetApiDatasetFileListProps,
GetApiDatasetFileListResponse
} from '@/pages/api/core/dataset/apiDataset/list';
import { GetApiDatasetFileListProps } from '@/pages/api/core/dataset/apiDataset/list';

const DataProcess = dynamic(() => import('../commonProgress/DataProcess'), {
loading: () => <Loading fixed={false} />
Expand Down Expand Up @@ -62,18 +59,16 @@ const CustomAPIFileInput = () => {
data: apiFileList,
ScrollData,
isLoading
} = useScrollPagination<GetApiDatasetFileListProps, GetApiDatasetFileListResponse>(
getApiDatasetFileList,
{
pageSize: 15,
params: {
datasetId: datasetDetail._id,
parentId: parent?.parentId,
searchKey: searchKey
},
refreshDeps: [datasetDetail._id, datasetDetail.apiServer, parent, searchKey]
}
);
} = useScrollPagination<GetApiDatasetFileListProps, APIFileListResponse>(getApiDatasetFileList, {
pageSize: 15,
params: {
datasetId: datasetDetail._id,
parentId: parent?.parentId,
searchKey: searchKey
},

refreshDeps: [datasetDetail._id, datasetDetail.apiServer, parent, searchKey]
});

const { data: existIdList = [] } = useRequest2(
() => getApiDatasetFileListExistId({ datasetId: datasetDetail._id }),
Expand Down
11 changes: 7 additions & 4 deletions projects/app/src/service/core/dataset/apiDataset/controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { GetApiDatasetFileListResponse } from '@/pages/api/core/dataset/apiDataset/list';
import { FeishuServer, YuqueServer } from '@fastgpt/global/core/dataset/apiDataset';
import {
APIFileListResponse,
FeishuServer,
YuqueServer
} from '@fastgpt/global/core/dataset/apiDataset';
import { POST } from '@fastgpt/service/common/api/plusRequest';

export const getFeishuAndYuqueDatasetFileList = async (data: {
feishuServer?: FeishuServer;
yuqueServer?: YuqueServer;
parentId?: string;
nextPageToken?: string;
pageSize: number;
offset: number;
metaData?: Record<string, any>;
}) => {
const res = await POST<GetApiDatasetFileListResponse>('/core/dataset/systemApiDataset', {
const res = await POST<APIFileListResponse>('/core/dataset/systemApiDataset', {
type: 'list',
...data
});
Expand Down
8 changes: 3 additions & 5 deletions projects/app/src/web/core/dataset/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ import type { UpdateDatasetDataProps } from '@fastgpt/global/core/dataset/contro
import type { DatasetFolderCreateBody } from '@/pages/api/core/dataset/folder/create';
import type { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/type';
import type { GetScrollCollectionsProps } from '@/pages/api/core/dataset/collection/scrollList';
import type {
GetApiDatasetFileListProps,
GetApiDatasetFileListResponse
} from '@/pages/api/core/dataset/apiDataset/list';
import type { GetApiDatasetFileListProps } from '@/pages/api/core/dataset/apiDataset/list';
import type {
listExistIdQuery,
listExistIdResponse
} from '@/pages/api/core/dataset/apiDataset/listExistId';
import { APIFileListResponse } from '@fastgpt/global/core/dataset/apiDataset';

/* ======================== dataset ======================= */
export const getDatasets = (data: GetDatasetListBody) =>
Expand Down Expand Up @@ -224,6 +222,6 @@ export const getCollectionSource = (data: readCollectionSourceBody) =>

/* ================== apiDataset ======================== */
export const getApiDatasetFileList = (data: GetApiDatasetFileListProps) =>
POST<GetApiDatasetFileListResponse>('/core/dataset/apiDataset/list', data);
POST<APIFileListResponse>('/core/dataset/apiDataset/list', data);
export const getApiDatasetFileListExistId = (data: listExistIdQuery) =>
GET<listExistIdResponse>('/core/dataset/apiDataset/listExistId', data);

0 comments on commit d44fc26

Please sign in to comment.