mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 11:43:56 +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 >}}
|
{{< /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,
|
APIFileListResponse,
|
||||||
ApiFileReadContentResponse,
|
ApiFileReadContentResponse,
|
||||||
APIFileReadResponse,
|
APIFileReadResponse,
|
||||||
APIFileServer
|
ApiDatasetDetailResponse,
|
||||||
|
APIFileServer,
|
||||||
|
APIFileItem
|
||||||
} from '@fastgpt/global/core/dataset/apiDataset';
|
} from '@fastgpt/global/core/dataset/apiDataset';
|
||||||
import axios, { type Method } from 'axios';
|
import axios, { type Method } from 'axios';
|
||||||
import { addLog } from '../../../common/system/log';
|
import { addLog } from '../../../common/system/log';
|
||||||
@@ -89,7 +91,7 @@ export const useApiDatasetRequest = ({ apiServer }: { apiServer: APIFileServer }
|
|||||||
`/v1/file/list`,
|
`/v1/file/list`,
|
||||||
{
|
{
|
||||||
searchKey,
|
searchKey,
|
||||||
parentId
|
parentId: parentId || apiServer.basePath
|
||||||
},
|
},
|
||||||
'POST'
|
'POST'
|
||||||
);
|
);
|
||||||
@@ -164,9 +166,34 @@ export const useApiDatasetRequest = ({ apiServer }: { apiServer: APIFileServer }
|
|||||||
return url;
|
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 {
|
return {
|
||||||
getFileContent,
|
getFileContent,
|
||||||
listFiles,
|
listFiles,
|
||||||
getFilePreviewUrl
|
getFilePreviewUrl,
|
||||||
|
getFileDetail
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -923,7 +923,7 @@
|
|||||||
"not_open": "Not Open",
|
"not_open": "Not Open",
|
||||||
"not_permission": "The current subscription package does not support team operation logs",
|
"not_permission": "The current subscription package does not support team operation logs",
|
||||||
"not_support": "Not Supported",
|
"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",
|
"not_yet_introduced": "No Introduction Yet",
|
||||||
"open_folder": "Open Folder",
|
"open_folder": "Open Folder",
|
||||||
"option": "Option",
|
"option": "Option",
|
||||||
|
@@ -922,7 +922,7 @@
|
|||||||
"not_open": "未开启",
|
"not_open": "未开启",
|
||||||
"not_permission": "当前订阅套餐不支持团队操作日志",
|
"not_permission": "当前订阅套餐不支持团队操作日志",
|
||||||
"not_support": "不支持",
|
"not_support": "不支持",
|
||||||
"not_support_wechat_image": "暂时不支持微信图片渲染",
|
"not_support_wechat_image": "这是一张微信图片",
|
||||||
"not_yet_introduced": "暂无介绍",
|
"not_yet_introduced": "暂无介绍",
|
||||||
"open_folder": "打开文件夹",
|
"open_folder": "打开文件夹",
|
||||||
"option": "选项",
|
"option": "选项",
|
||||||
|
@@ -922,7 +922,7 @@
|
|||||||
"not_open": "未開啟",
|
"not_open": "未開啟",
|
||||||
"not_permission": "當前訂閱套餐不支持團隊操作日誌",
|
"not_permission": "當前訂閱套餐不支持團隊操作日誌",
|
||||||
"not_support": "不支援",
|
"not_support": "不支援",
|
||||||
"not_support_wechat_image": "暫時不支持微信圖片渲染",
|
"not_support_wechat_image": "這是一張微信圖片",
|
||||||
"not_yet_introduced": "暫無介紹",
|
"not_yet_introduced": "暫無介紹",
|
||||||
"open_folder": "開啟資料夾",
|
"open_folder": "開啟資料夾",
|
||||||
"option": "選項",
|
"option": "選項",
|
||||||
|
@@ -52,7 +52,7 @@ const ApiDatasetForm = ({
|
|||||||
{ setTrue: openBaseurlSeletModal, setFalse: closeBaseurlSelectModal }
|
{ setTrue: openBaseurlSeletModal, setFalse: closeBaseurlSelectModal }
|
||||||
] = useBoolean();
|
] = useBoolean();
|
||||||
|
|
||||||
const parentId = yuqueServer?.basePath || feishuServer?.folderToken || apiServer?.basePath;
|
const parentId = yuqueServer?.basePath || apiServer?.basePath;
|
||||||
|
|
||||||
const canSelectBaseUrl = useMemo(() => {
|
const canSelectBaseUrl = useMemo(() => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -61,23 +61,27 @@ const ApiDatasetForm = ({
|
|||||||
case DatasetTypeEnum.feishu:
|
case DatasetTypeEnum.feishu:
|
||||||
return feishuServer?.appId && feishuServer?.appSecret;
|
return feishuServer?.appId && feishuServer?.appSecret;
|
||||||
case DatasetTypeEnum.apiDataset:
|
case DatasetTypeEnum.apiDataset:
|
||||||
return !!apiServer?.basePath;
|
return !!apiServer?.baseUrl;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
type,
|
type,
|
||||||
yuqueServer?.token,
|
|
||||||
yuqueServer?.userId,
|
yuqueServer?.userId,
|
||||||
|
yuqueServer?.token,
|
||||||
feishuServer?.appId,
|
feishuServer?.appId,
|
||||||
feishuServer?.appSecret,
|
feishuServer?.appSecret,
|
||||||
apiServer?.basePath
|
apiServer?.baseUrl
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Unified function to get the current path
|
// Unified function to get the current path
|
||||||
const { loading: isFetching } = useRequest2(
|
const { loading: isFetching } = useRequest2(
|
||||||
async () => {
|
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'));
|
return setPathNames(t('dataset:input_required_field_to_select_baseurl'));
|
||||||
}
|
}
|
||||||
if (!parentId) {
|
if (!parentId) {
|
||||||
@@ -141,7 +145,7 @@ const ApiDatasetForm = ({
|
|||||||
const renderDirectoryModal = () =>
|
const renderDirectoryModal = () =>
|
||||||
isOpenBaseurlSeletModal ? (
|
isOpenBaseurlSeletModal ? (
|
||||||
<BaseUrlSelector
|
<BaseUrlSelector
|
||||||
selectId={type === DatasetTypeEnum.yuque ? yuqueServer?.basePath || 'root' : 'root'}
|
selectId={yuqueServer?.basePath || apiServer?.basePath || 'root'}
|
||||||
server={async (e: GetResourceFolderListProps) => {
|
server={async (e: GetResourceFolderListProps) => {
|
||||||
const params: GetApiDatasetCataLogProps = { parentId: e.parentId };
|
const params: GetApiDatasetCataLogProps = { parentId: e.parentId };
|
||||||
|
|
||||||
@@ -203,8 +207,8 @@ const ApiDatasetForm = ({
|
|||||||
{...register('apiServer.authorization')}
|
{...register('apiServer.authorization')}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
{/* {renderBaseUrlSelector()}
|
{renderBaseUrlSelector()}
|
||||||
{renderDirectoryModal()} */}
|
{renderDirectoryModal()}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{type === DatasetTypeEnum.feishu && (
|
{type === DatasetTypeEnum.feishu && (
|
||||||
|
@@ -4,13 +4,15 @@ import type { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
|
|||||||
import type {
|
import type {
|
||||||
APIFileServer,
|
APIFileServer,
|
||||||
YuqueServer,
|
YuqueServer,
|
||||||
FeishuServer
|
FeishuServer,
|
||||||
|
ApiDatasetDetailResponse
|
||||||
} from '@fastgpt/global/core/dataset/apiDataset';
|
} from '@fastgpt/global/core/dataset/apiDataset';
|
||||||
import { getProApiDatasetFileDetailRequest } from '@/service/core/dataset/apiDataset/controller';
|
import { getProApiDatasetFileDetailRequest } from '@/service/core/dataset/apiDataset/controller';
|
||||||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
||||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||||
import { authDataset } from '@fastgpt/service/support/permission/dataset/auth';
|
import { authDataset } from '@fastgpt/service/support/permission/dataset/auth';
|
||||||
import { ManagePermissionVal } from '@fastgpt/global/support/permission/constant';
|
import { ManagePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||||
|
import { useApiDatasetRequest } from '@fastgpt/service/core/dataset/apiDataset/api';
|
||||||
|
|
||||||
export type GetApiDatasetPathQuery = {};
|
export type GetApiDatasetPathQuery = {};
|
||||||
|
|
||||||
@@ -24,6 +26,24 @@ export type GetApiDatasetPathBody = {
|
|||||||
|
|
||||||
export type GetApiDatasetPathResponse = string;
|
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(
|
async function handler(
|
||||||
req: ApiRequestProps<GetApiDatasetPathBody, any>,
|
req: ApiRequestProps<GetApiDatasetPathBody, any>,
|
||||||
res: ApiResponseType<GetApiDatasetPathResponse>
|
res: ApiResponseType<GetApiDatasetPathResponse>
|
||||||
@@ -70,27 +90,22 @@ async function handler(
|
|||||||
return Promise.reject(DatasetErrEnum.noApiServer);
|
return Promise.reject(DatasetErrEnum.noApiServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiServer || feishuServer) {
|
if (feishuServer) {
|
||||||
return Promise.reject('不支持获取 BaseUrl');
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiServer) {
|
||||||
|
return await getFullPath(parentId, useApiDatasetRequest({ apiServer }).getFileDetail);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yuqueServer) {
|
if (yuqueServer) {
|
||||||
const getFullPath = async (currentId: string): Promise<string> => {
|
const yuqueFileGetter = async ({ apiFileId }: { apiFileId: string }) => {
|
||||||
const response = await getProApiDatasetFileDetailRequest({
|
return await getProApiDatasetFileDetailRequest({
|
||||||
feishuServer,
|
|
||||||
yuqueServer,
|
yuqueServer,
|
||||||
apiFileId: currentId
|
apiFileId
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.parentId) {
|
|
||||||
const parentPath = await getFullPath(response.parentId);
|
|
||||||
return `${parentPath}/${response.name}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `/${response.name}`;
|
|
||||||
};
|
};
|
||||||
|
return await getFullPath(parentId, yuqueFileGetter);
|
||||||
return await getFullPath(parentId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(new Error(DatasetErrEnum.noApiServer));
|
return Promise.reject(new Error(DatasetErrEnum.noApiServer));
|
||||||
|
@@ -48,7 +48,8 @@ async function handler(req: ApiRequestProps<Query>): Promise<DatasetItemType> {
|
|||||||
apiServer: dataset.apiServer
|
apiServer: dataset.apiServer
|
||||||
? {
|
? {
|
||||||
baseUrl: dataset.apiServer.baseUrl,
|
baseUrl: dataset.apiServer.baseUrl,
|
||||||
authorization: ''
|
authorization: '',
|
||||||
|
basePath: dataset.apiServer.basePath
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
yuqueServer: dataset.yuqueServer
|
yuqueServer: dataset.yuqueServer
|
||||||
|
@@ -170,6 +170,7 @@ async function handler(
|
|||||||
...(!!apiServer?.authorization && {
|
...(!!apiServer?.authorization && {
|
||||||
'apiServer.authorization': apiServer.authorization
|
'apiServer.authorization': apiServer.authorization
|
||||||
}),
|
}),
|
||||||
|
...(!!apiServer?.basePath !== undefined && { 'apiServer.basePath': apiServer?.basePath }),
|
||||||
...(!!yuqueServer?.userId && { 'yuqueServer.userId': yuqueServer.userId }),
|
...(!!yuqueServer?.userId && { 'yuqueServer.userId': yuqueServer.userId }),
|
||||||
...(!!yuqueServer?.token && { 'yuqueServer.token': yuqueServer.token }),
|
...(!!yuqueServer?.token && { 'yuqueServer.token': yuqueServer.token }),
|
||||||
...(!!yuqueServer?.basePath !== undefined && {
|
...(!!yuqueServer?.basePath !== undefined && {
|
||||||
|
@@ -106,7 +106,8 @@ export const DatasetPageContextProvider = ({
|
|||||||
apiServer: data.apiServer
|
apiServer: data.apiServer
|
||||||
? {
|
? {
|
||||||
baseUrl: data.apiServer.baseUrl,
|
baseUrl: data.apiServer.baseUrl,
|
||||||
authorization: ''
|
authorization: '',
|
||||||
|
basePath: data.apiServer.basePath
|
||||||
}
|
}
|
||||||
: state.apiServer,
|
: state.apiServer,
|
||||||
yuqueServer: data.yuqueServer
|
yuqueServer: data.yuqueServer
|
||||||
|
Reference in New Issue
Block a user