Skip to content

Commit 2d2d0ff

Browse files
Test apidataset (labring#4830)
* Dataset (labring#4822) * apidataset support to basepath * Resolve the error of the Feishu Knowledge Base modification configuration page not supporting baseurl bug. * apibasepath * add * perf: api dataset --------- Co-authored-by: dreamer6680 <[email protected]>
1 parent c6e0b5a commit 2d2d0ff

File tree

11 files changed

+120
-34
lines changed

11 files changed

+120
-34
lines changed

docSite/content/zh-cn/docs/guide/knowledge_base/api_dataset.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,40 @@ curl --location --request GET '{{baseURL}}/v1/file/read?id=xx' \
185185
{{< /tabs >}}
186186

187187

188+
### 4. 获取文件详细信息(用于获取文件信息)
189+
190+
{{< tabs tabTotal="2" >}}
191+
{{< tab tabName="请求示例" >}}
192+
{{< markdownify >}}
193+
194+
id 为文件的 id
195+
196+
```bash
197+
curl --location --request GET '{{baseURL}}/v1/file/detail?id=xx' \
198+
--header 'Authorization: Bearer {{authorization}}'
199+
```
200+
201+
{{< /markdownify >}}
202+
{{< /tab >}}
203+
204+
{{< tab tabName="响应示例" >}}
205+
{{< markdownify >}}
206+
207+
```json
208+
{
209+
"code": 200,
210+
"success": true,
211+
"message": "",
212+
"data": {
213+
"id": "docs",
214+
"parentId": "",
215+
"name": "docs"
216+
}
217+
}
218+
```
219+
220+
{{< /markdownify >}}
221+
{{< /tab >}}
222+
{{< /tabs >}}
223+
224+

packages/service/core/dataset/apiDataset/api.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import type {
22
APIFileListResponse,
33
ApiFileReadContentResponse,
44
APIFileReadResponse,
5-
APIFileServer
5+
ApiDatasetDetailResponse,
6+
APIFileServer,
7+
APIFileItem
68
} from '@fastgpt/global/core/dataset/apiDataset';
79
import axios, { type Method } from 'axios';
810
import { addLog } from '../../../common/system/log';
@@ -89,7 +91,7 @@ export const useApiDatasetRequest = ({ apiServer }: { apiServer: APIFileServer }
8991
`/v1/file/list`,
9092
{
9193
searchKey,
92-
parentId
94+
parentId: parentId || apiServer.basePath
9395
},
9496
'POST'
9597
);
@@ -164,9 +166,34 @@ export const useApiDatasetRequest = ({ apiServer }: { apiServer: APIFileServer }
164166
return url;
165167
};
166168

169+
const getFileDetail = async ({
170+
apiFileId
171+
}: {
172+
apiFileId: string;
173+
}): Promise<ApiDatasetDetailResponse> => {
174+
const fileData = await request<ApiDatasetDetailResponse>(
175+
`/v1/file/detail`,
176+
{
177+
id: apiFileId
178+
},
179+
'GET'
180+
);
181+
182+
if (fileData) {
183+
return {
184+
id: fileData.id,
185+
name: fileData.name,
186+
parentId: fileData.parentId === null ? '' : fileData.parentId
187+
};
188+
}
189+
190+
return Promise.reject('File not found');
191+
};
192+
167193
return {
168194
getFileContent,
169195
listFiles,
170-
getFilePreviewUrl
196+
getFilePreviewUrl,
197+
getFileDetail
171198
};
172199
};

packages/web/i18n/en/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@
923923
"not_open": "Not Open",
924924
"not_permission": "The current subscription package does not support team operation logs",
925925
"not_support": "Not Supported",
926-
"not_support_wechat_image": "WeChat image rendering is not supported",
926+
"not_support_wechat_image": "This is a WeChat picture",
927927
"not_yet_introduced": "No Introduction Yet",
928928
"open_folder": "Open Folder",
929929
"option": "Option",

packages/web/i18n/zh-CN/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@
922922
"not_open": "未开启",
923923
"not_permission": "当前订阅套餐不支持团队操作日志",
924924
"not_support": "不支持",
925-
"not_support_wechat_image": "暂时不支持微信图片渲染",
925+
"not_support_wechat_image": "这是一张微信图片",
926926
"not_yet_introduced": "暂无介绍",
927927
"open_folder": "打开文件夹",
928928
"option": "选项",

packages/web/i18n/zh-Hant/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@
922922
"not_open": "未開啟",
923923
"not_permission": "當前訂閱套餐不支持團隊操作日誌",
924924
"not_support": "不支援",
925-
"not_support_wechat_image": "暫時不支持微信圖片渲染",
925+
"not_support_wechat_image": "這是一張微信圖片",
926926
"not_yet_introduced": "暫無介紹",
927927
"open_folder": "開啟資料夾",
928928
"option": "選項",

projects/app/src/components/Markdown/img/Image.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const MdImage = ({ src, ...props }: { src?: string } & ImageProps) => {
1313
if (src?.includes('base64') && !src.startsWith('data:image')) {
1414
return <Box>Invalid base64 image</Box>;
1515
}
16-
16+
1717
if (props.alt?.startsWith('OFFIACCOUNT_MEDIA')) {
1818
return <Box>{t('common:not_support_wechat_image')}</Box>;
1919
}
20-
20+
2121
return (
2222
<Skeleton isLoaded={isLoaded}>
2323
<MyPhotoView

projects/app/src/pageComponents/dataset/ApiDatasetForm.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const ApiDatasetForm = ({
5252
{ setTrue: openBaseurlSeletModal, setFalse: closeBaseurlSelectModal }
5353
] = useBoolean();
5454

55-
const parentId = yuqueServer?.basePath || feishuServer?.folderToken || apiServer?.basePath;
55+
const parentId = yuqueServer?.basePath || apiServer?.basePath;
5656

5757
const canSelectBaseUrl = useMemo(() => {
5858
switch (type) {
@@ -61,23 +61,27 @@ const ApiDatasetForm = ({
6161
case DatasetTypeEnum.feishu:
6262
return feishuServer?.appId && feishuServer?.appSecret;
6363
case DatasetTypeEnum.apiDataset:
64-
return !!apiServer?.basePath;
64+
return !!apiServer?.baseUrl;
6565
default:
6666
return false;
6767
}
6868
}, [
6969
type,
70-
yuqueServer?.token,
7170
yuqueServer?.userId,
71+
yuqueServer?.token,
7272
feishuServer?.appId,
7373
feishuServer?.appSecret,
74-
apiServer?.basePath
74+
apiServer?.baseUrl
7575
]);
7676

7777
// Unified function to get the current path
7878
const { loading: isFetching } = useRequest2(
7979
async () => {
80-
if (!datasetId && !(yuqueServer?.userId && yuqueServer?.token)) {
80+
if (
81+
!datasetId &&
82+
((yuqueServer && (!yuqueServer.userId || !yuqueServer?.token)) ||
83+
(apiServer && !apiServer?.baseUrl))
84+
) {
8185
return setPathNames(t('dataset:input_required_field_to_select_baseurl'));
8286
}
8387
if (!parentId) {
@@ -141,7 +145,7 @@ const ApiDatasetForm = ({
141145
const renderDirectoryModal = () =>
142146
isOpenBaseurlSeletModal ? (
143147
<BaseUrlSelector
144-
selectId={type === DatasetTypeEnum.yuque ? yuqueServer?.basePath || 'root' : 'root'}
148+
selectId={yuqueServer?.basePath || apiServer?.basePath || 'root'}
145149
server={async (e: GetResourceFolderListProps) => {
146150
const params: GetApiDatasetCataLogProps = { parentId: e.parentId };
147151

@@ -203,8 +207,8 @@ const ApiDatasetForm = ({
203207
{...register('apiServer.authorization')}
204208
/>
205209
</Flex>
206-
{/* {renderBaseUrlSelector()}
207-
{renderDirectoryModal()} */}
210+
{renderBaseUrlSelector()}
211+
{renderDirectoryModal()}
208212
</>
209213
)}
210214
{type === DatasetTypeEnum.feishu && (

projects/app/src/pages/api/core/dataset/apiDataset/getPathNames.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import type { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
44
import type {
55
APIFileServer,
66
YuqueServer,
7-
FeishuServer
7+
FeishuServer,
8+
ApiDatasetDetailResponse
89
} from '@fastgpt/global/core/dataset/apiDataset';
910
import { getProApiDatasetFileDetailRequest } from '@/service/core/dataset/apiDataset/controller';
1011
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
1112
import { authCert } from '@fastgpt/service/support/permission/auth/common';
1213
import { authDataset } from '@fastgpt/service/support/permission/dataset/auth';
1314
import { ManagePermissionVal } from '@fastgpt/global/support/permission/constant';
15+
import { useApiDatasetRequest } from '@fastgpt/service/core/dataset/apiDataset/api';
1416

1517
export type GetApiDatasetPathQuery = {};
1618

@@ -24,6 +26,24 @@ export type GetApiDatasetPathBody = {
2426

2527
export type GetApiDatasetPathResponse = string;
2628

29+
const getFullPath = async (
30+
currentId: string,
31+
getFileDetail: ({ apiFileId }: { apiFileId: string }) => Promise<ApiDatasetDetailResponse>
32+
): Promise<string> => {
33+
const response = await getFileDetail({ apiFileId: currentId });
34+
35+
if (!response) {
36+
return '';
37+
}
38+
39+
if (response.parentId && response.parentId !== null) {
40+
const parentPath = await getFullPath(response.parentId, getFileDetail);
41+
return `${parentPath}/${response.name}`;
42+
}
43+
44+
return `/${response.name}`;
45+
};
46+
2747
async function handler(
2848
req: ApiRequestProps<GetApiDatasetPathBody, any>,
2949
res: ApiResponseType<GetApiDatasetPathResponse>
@@ -70,27 +90,22 @@ async function handler(
7090
return Promise.reject(DatasetErrEnum.noApiServer);
7191
}
7292

73-
if (apiServer || feishuServer) {
74-
return Promise.reject('不支持获取 BaseUrl');
93+
if (feishuServer) {
94+
return '';
95+
}
96+
97+
if (apiServer) {
98+
return await getFullPath(parentId, useApiDatasetRequest({ apiServer }).getFileDetail);
7599
}
76100

77101
if (yuqueServer) {
78-
const getFullPath = async (currentId: string): Promise<string> => {
79-
const response = await getProApiDatasetFileDetailRequest({
80-
feishuServer,
102+
const yuqueFileGetter = async ({ apiFileId }: { apiFileId: string }) => {
103+
return await getProApiDatasetFileDetailRequest({
81104
yuqueServer,
82-
apiFileId: currentId
105+
apiFileId
83106
});
84-
85-
if (response.parentId) {
86-
const parentPath = await getFullPath(response.parentId);
87-
return `${parentPath}/${response.name}`;
88-
}
89-
90-
return `/${response.name}`;
91107
};
92-
93-
return await getFullPath(parentId);
108+
return await getFullPath(parentId, yuqueFileGetter);
94109
}
95110

96111
return Promise.reject(new Error(DatasetErrEnum.noApiServer));

projects/app/src/pages/api/core/dataset/detail.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ async function handler(req: ApiRequestProps<Query>): Promise<DatasetItemType> {
4848
apiServer: dataset.apiServer
4949
? {
5050
baseUrl: dataset.apiServer.baseUrl,
51-
authorization: ''
51+
authorization: '',
52+
basePath: dataset.apiServer.basePath
5253
}
5354
: undefined,
5455
yuqueServer: dataset.yuqueServer

projects/app/src/pages/api/core/dataset/update.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ async function handler(
170170
...(!!apiServer?.authorization && {
171171
'apiServer.authorization': apiServer.authorization
172172
}),
173+
...(!!apiServer?.basePath !== undefined && { 'apiServer.basePath': apiServer?.basePath }),
173174
...(!!yuqueServer?.userId && { 'yuqueServer.userId': yuqueServer.userId }),
174175
...(!!yuqueServer?.token && { 'yuqueServer.token': yuqueServer.token }),
175176
...(!!yuqueServer?.basePath !== undefined && {

projects/app/src/web/core/dataset/context/datasetPageContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export const DatasetPageContextProvider = ({
106106
apiServer: data.apiServer
107107
? {
108108
baseUrl: data.apiServer.baseUrl,
109-
authorization: ''
109+
authorization: '',
110+
basePath: data.apiServer.basePath
110111
}
111112
: state.apiServer,
112113
yuqueServer: data.yuqueServer

0 commit comments

Comments
 (0)