mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-19 18:44:17 +00:00
Test apidataset (#4830)
* Dataset (#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 <1468683855@qq.com>
This commit is contained in:
@@ -185,3 +185,40 @@ curl --location --request GET '{{baseURL}}/v1/file/read?id=xx' \
|
||||
{{< /tabs >}}
|
||||
|
||||
|
||||
### 4. 获取文件详细信息(用于获取文件信息)
|
||||
|
||||
{{< tabs tabTotal="2" >}}
|
||||
{{< tab tabName="请求示例" >}}
|
||||
{{< markdownify >}}
|
||||
|
||||
id 为文件的 id。
|
||||
|
||||
```bash
|
||||
curl --location --request GET '{{baseURL}}/v1/file/detail?id=xx' \
|
||||
--header 'Authorization: Bearer {{authorization}}'
|
||||
```
|
||||
|
||||
{{< /markdownify >}}
|
||||
{{< /tab >}}
|
||||
|
||||
{{< tab tabName="响应示例" >}}
|
||||
{{< markdownify >}}
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"success": true,
|
||||
"message": "",
|
||||
"data": {
|
||||
"id": "docs",
|
||||
"parentId": "",
|
||||
"name": "docs"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
{{< /markdownify >}}
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
|
||||
|
@@ -2,7 +2,9 @@ import type {
|
||||
APIFileListResponse,
|
||||
ApiFileReadContentResponse,
|
||||
APIFileReadResponse,
|
||||
APIFileServer
|
||||
ApiDatasetDetailResponse,
|
||||
APIFileServer,
|
||||
APIFileItem
|
||||
} from '@fastgpt/global/core/dataset/apiDataset';
|
||||
import axios, { type Method } from 'axios';
|
||||
import { addLog } from '../../../common/system/log';
|
||||
@@ -89,7 +91,7 @@ export const useApiDatasetRequest = ({ apiServer }: { apiServer: APIFileServer }
|
||||
`/v1/file/list`,
|
||||
{
|
||||
searchKey,
|
||||
parentId
|
||||
parentId: parentId || apiServer.basePath
|
||||
},
|
||||
'POST'
|
||||
);
|
||||
@@ -164,9 +166,34 @@ export const useApiDatasetRequest = ({ apiServer }: { apiServer: APIFileServer }
|
||||
return url;
|
||||
};
|
||||
|
||||
const getFileDetail = async ({
|
||||
apiFileId
|
||||
}: {
|
||||
apiFileId: string;
|
||||
}): Promise<ApiDatasetDetailResponse> => {
|
||||
const fileData = await request<ApiDatasetDetailResponse>(
|
||||
`/v1/file/detail`,
|
||||
{
|
||||
id: apiFileId
|
||||
},
|
||||
'GET'
|
||||
);
|
||||
|
||||
if (fileData) {
|
||||
return {
|
||||
id: fileData.id,
|
||||
name: fileData.name,
|
||||
parentId: fileData.parentId === null ? '' : fileData.parentId
|
||||
};
|
||||
}
|
||||
|
||||
return Promise.reject('File not found');
|
||||
};
|
||||
|
||||
return {
|
||||
getFileContent,
|
||||
listFiles,
|
||||
getFilePreviewUrl
|
||||
getFilePreviewUrl,
|
||||
getFileDetail
|
||||
};
|
||||
};
|
||||
|
@@ -923,7 +923,7 @@
|
||||
"not_open": "Not Open",
|
||||
"not_permission": "The current subscription package does not support team operation logs",
|
||||
"not_support": "Not Supported",
|
||||
"not_support_wechat_image": "WeChat image rendering is not supported",
|
||||
"not_support_wechat_image": "This is a WeChat picture",
|
||||
"not_yet_introduced": "No Introduction Yet",
|
||||
"open_folder": "Open Folder",
|
||||
"option": "Option",
|
||||
|
@@ -922,7 +922,7 @@
|
||||
"not_open": "未开启",
|
||||
"not_permission": "当前订阅套餐不支持团队操作日志",
|
||||
"not_support": "不支持",
|
||||
"not_support_wechat_image": "暂时不支持微信图片渲染",
|
||||
"not_support_wechat_image": "这是一张微信图片",
|
||||
"not_yet_introduced": "暂无介绍",
|
||||
"open_folder": "打开文件夹",
|
||||
"option": "选项",
|
||||
|
@@ -922,7 +922,7 @@
|
||||
"not_open": "未開啟",
|
||||
"not_permission": "當前訂閱套餐不支持團隊操作日誌",
|
||||
"not_support": "不支援",
|
||||
"not_support_wechat_image": "暫時不支持微信圖片渲染",
|
||||
"not_support_wechat_image": "這是一張微信圖片",
|
||||
"not_yet_introduced": "暫無介紹",
|
||||
"open_folder": "開啟資料夾",
|
||||
"option": "選項",
|
||||
|
@@ -13,11 +13,11 @@ const MdImage = ({ src, ...props }: { src?: string } & ImageProps) => {
|
||||
if (src?.includes('base64') && !src.startsWith('data:image')) {
|
||||
return <Box>Invalid base64 image</Box>;
|
||||
}
|
||||
|
||||
|
||||
if (props.alt?.startsWith('OFFIACCOUNT_MEDIA')) {
|
||||
return <Box>{t('common:not_support_wechat_image')}</Box>;
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Skeleton isLoaded={isLoaded}>
|
||||
<MyPhotoView
|
||||
|
@@ -52,7 +52,7 @@ const ApiDatasetForm = ({
|
||||
{ setTrue: openBaseurlSeletModal, setFalse: closeBaseurlSelectModal }
|
||||
] = useBoolean();
|
||||
|
||||
const parentId = yuqueServer?.basePath || feishuServer?.folderToken || apiServer?.basePath;
|
||||
const parentId = yuqueServer?.basePath || apiServer?.basePath;
|
||||
|
||||
const canSelectBaseUrl = useMemo(() => {
|
||||
switch (type) {
|
||||
@@ -61,23 +61,27 @@ const ApiDatasetForm = ({
|
||||
case DatasetTypeEnum.feishu:
|
||||
return feishuServer?.appId && feishuServer?.appSecret;
|
||||
case DatasetTypeEnum.apiDataset:
|
||||
return !!apiServer?.basePath;
|
||||
return !!apiServer?.baseUrl;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}, [
|
||||
type,
|
||||
yuqueServer?.token,
|
||||
yuqueServer?.userId,
|
||||
yuqueServer?.token,
|
||||
feishuServer?.appId,
|
||||
feishuServer?.appSecret,
|
||||
apiServer?.basePath
|
||||
apiServer?.baseUrl
|
||||
]);
|
||||
|
||||
// Unified function to get the current path
|
||||
const { loading: isFetching } = useRequest2(
|
||||
async () => {
|
||||
if (!datasetId && !(yuqueServer?.userId && yuqueServer?.token)) {
|
||||
if (
|
||||
!datasetId &&
|
||||
((yuqueServer && (!yuqueServer.userId || !yuqueServer?.token)) ||
|
||||
(apiServer && !apiServer?.baseUrl))
|
||||
) {
|
||||
return setPathNames(t('dataset:input_required_field_to_select_baseurl'));
|
||||
}
|
||||
if (!parentId) {
|
||||
@@ -141,7 +145,7 @@ const ApiDatasetForm = ({
|
||||
const renderDirectoryModal = () =>
|
||||
isOpenBaseurlSeletModal ? (
|
||||
<BaseUrlSelector
|
||||
selectId={type === DatasetTypeEnum.yuque ? yuqueServer?.basePath || 'root' : 'root'}
|
||||
selectId={yuqueServer?.basePath || apiServer?.basePath || 'root'}
|
||||
server={async (e: GetResourceFolderListProps) => {
|
||||
const params: GetApiDatasetCataLogProps = { parentId: e.parentId };
|
||||
|
||||
@@ -203,8 +207,8 @@ const ApiDatasetForm = ({
|
||||
{...register('apiServer.authorization')}
|
||||
/>
|
||||
</Flex>
|
||||
{/* {renderBaseUrlSelector()}
|
||||
{renderDirectoryModal()} */}
|
||||
{renderBaseUrlSelector()}
|
||||
{renderDirectoryModal()}
|
||||
</>
|
||||
)}
|
||||
{type === DatasetTypeEnum.feishu && (
|
||||
|
@@ -4,13 +4,15 @@ import type { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
|
||||
import type {
|
||||
APIFileServer,
|
||||
YuqueServer,
|
||||
FeishuServer
|
||||
FeishuServer,
|
||||
ApiDatasetDetailResponse
|
||||
} from '@fastgpt/global/core/dataset/apiDataset';
|
||||
import { getProApiDatasetFileDetailRequest } from '@/service/core/dataset/apiDataset/controller';
|
||||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import { authDataset } from '@fastgpt/service/support/permission/dataset/auth';
|
||||
import { ManagePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { useApiDatasetRequest } from '@fastgpt/service/core/dataset/apiDataset/api';
|
||||
|
||||
export type GetApiDatasetPathQuery = {};
|
||||
|
||||
@@ -24,6 +26,24 @@ export type GetApiDatasetPathBody = {
|
||||
|
||||
export type GetApiDatasetPathResponse = string;
|
||||
|
||||
const getFullPath = async (
|
||||
currentId: string,
|
||||
getFileDetail: ({ apiFileId }: { apiFileId: string }) => Promise<ApiDatasetDetailResponse>
|
||||
): Promise<string> => {
|
||||
const response = await getFileDetail({ apiFileId: currentId });
|
||||
|
||||
if (!response) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (response.parentId && response.parentId !== null) {
|
||||
const parentPath = await getFullPath(response.parentId, getFileDetail);
|
||||
return `${parentPath}/${response.name}`;
|
||||
}
|
||||
|
||||
return `/${response.name}`;
|
||||
};
|
||||
|
||||
async function handler(
|
||||
req: ApiRequestProps<GetApiDatasetPathBody, any>,
|
||||
res: ApiResponseType<GetApiDatasetPathResponse>
|
||||
@@ -70,27 +90,22 @@ async function handler(
|
||||
return Promise.reject(DatasetErrEnum.noApiServer);
|
||||
}
|
||||
|
||||
if (apiServer || feishuServer) {
|
||||
return Promise.reject('不支持获取 BaseUrl');
|
||||
if (feishuServer) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (apiServer) {
|
||||
return await getFullPath(parentId, useApiDatasetRequest({ apiServer }).getFileDetail);
|
||||
}
|
||||
|
||||
if (yuqueServer) {
|
||||
const getFullPath = async (currentId: string): Promise<string> => {
|
||||
const response = await getProApiDatasetFileDetailRequest({
|
||||
feishuServer,
|
||||
const yuqueFileGetter = async ({ apiFileId }: { apiFileId: string }) => {
|
||||
return await getProApiDatasetFileDetailRequest({
|
||||
yuqueServer,
|
||||
apiFileId: currentId
|
||||
apiFileId
|
||||
});
|
||||
|
||||
if (response.parentId) {
|
||||
const parentPath = await getFullPath(response.parentId);
|
||||
return `${parentPath}/${response.name}`;
|
||||
}
|
||||
|
||||
return `/${response.name}`;
|
||||
};
|
||||
|
||||
return await getFullPath(parentId);
|
||||
return await getFullPath(parentId, yuqueFileGetter);
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(DatasetErrEnum.noApiServer));
|
||||
|
@@ -48,7 +48,8 @@ async function handler(req: ApiRequestProps<Query>): Promise<DatasetItemType> {
|
||||
apiServer: dataset.apiServer
|
||||
? {
|
||||
baseUrl: dataset.apiServer.baseUrl,
|
||||
authorization: ''
|
||||
authorization: '',
|
||||
basePath: dataset.apiServer.basePath
|
||||
}
|
||||
: undefined,
|
||||
yuqueServer: dataset.yuqueServer
|
||||
|
@@ -170,6 +170,7 @@ async function handler(
|
||||
...(!!apiServer?.authorization && {
|
||||
'apiServer.authorization': apiServer.authorization
|
||||
}),
|
||||
...(!!apiServer?.basePath !== undefined && { 'apiServer.basePath': apiServer?.basePath }),
|
||||
...(!!yuqueServer?.userId && { 'yuqueServer.userId': yuqueServer.userId }),
|
||||
...(!!yuqueServer?.token && { 'yuqueServer.token': yuqueServer.token }),
|
||||
...(!!yuqueServer?.basePath !== undefined && {
|
||||
|
@@ -106,7 +106,8 @@ export const DatasetPageContextProvider = ({
|
||||
apiServer: data.apiServer
|
||||
? {
|
||||
baseUrl: data.apiServer.baseUrl,
|
||||
authorization: ''
|
||||
authorization: '',
|
||||
basePath: data.apiServer.basePath
|
||||
}
|
||||
: state.apiServer,
|
||||
yuqueServer: data.yuqueServer
|
||||
|
Reference in New Issue
Block a user