Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ui/src/api/API_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ API 枚举与类型统一在 `src/api` 范围内管理,相关规则由本文
- Admin Router 与请求客户端直接读取 `window.MaxKB` 运行时路径配置;`Window` 和
`MaxKBRuntimeConfig` 的全局类型统一声明在根目录 `env.d.ts`。
- Admin 普通 JSON 请求使用 Axios;`request.ts` 导出 Axios 实例以及 `promise`、`get`、
`post`、`put` 和 `del` 请求封装。
`post`、`put`、`del`Blob 文件 `downloadRequest` 请求封装。
- 正常 JSON 接口返回 `Promise<T>`,请求层负责解包后端 `{ code, message, data }` 响应。
- GET 文件导出使用 `getExportFile`;需要通过 POST 同时传递查询参数和可选请求体的 Excel 导出
使用 `postExportExcel`。请求层统一获取 Blob、解析 `Content-Disposition` 文件名并触发浏览器
下载;业务 API 只需传入默认文件名、接口地址及业务参数
使用 `postExportExcel`;Skill 压缩包等指定请求方法的文件下载使用 `downloadRequest`。请求层统一
获取 Blob、解析 `Content-Disposition` 文件名并触发浏览器下载;业务 API 只需传入接口地址及业务参数
- 业务代码通过 `api.method().then(...)` 处理接口成功后的状态变化;通用接口错误由请求层统一
提示,不在调用处重复使用 `try/catch` 或 `.catch()` 提示相同错误。只有业务降级、状态恢复等
非提示类失败处理可以按需保留失败分支。
Expand Down
25 changes: 25 additions & 0 deletions ui/src/api/admin/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,31 @@ export function get<T = unknown>(
return promise<T>(request.get<ApiResponse<T>>(url, { params, timeout }), loading)
}

/** 发送指定方法的 Blob 请求并触发浏览器下载。 */
export async function downloadRequest(
url: string,
method: string,
data?: unknown,
params?: Dict<unknown>,
loading?: LoadingTarget,
): Promise<boolean> {
startLoading(loading)
try {
const response = await request.request<Blob>({
url,
method,
data,
params,
responseType: 'blob',
skipGlobalErrorMessage: true,
} as ExportRequestConfig)

return downloadExportResponse(response, 'download')
} finally {
finishLoading(loading)
}
}

/** 发送 GET 请求并将 Blob 响应下载为文件。 */
export async function getExportFile(
fileName: string,
Expand Down
42 changes: 21 additions & 21 deletions ui/src/api/admin/workspace/tool/tool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { del, getExportFile, get, post, put } from '../../core/request'
import { del, downloadRequest, getExportFile, get, post, put } from '../../core/request'
import type { ParamsPage, ResponsePage } from '../../core/types'
import type { Dict, ToolDebugPayload, ToolItem, ToolPayload, ToolPylintIssue } from '@/api/types'
import { getWorkspaceId } from '@/utils/resource-context'
Expand Down Expand Up @@ -28,6 +28,21 @@ const putTool = (toolId: string, payload: ToolPayload) => {
return put<ToolPayload, ToolItem>(`${getPrefix()}/${toolId}`, payload)
}

/** 检查工作空间工具的 Python 代码。 */
const postToolPylint = (code: string) => {
return post<{ code: string }, ToolPylintIssue[]>(`${getPrefix()}/pylint`, { code })
}

// const generateCode = (data: any) => {
// const p = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api'
// return postStream(`${p}${getPrefix()}/generate_code`, data)
// }

/** 调试普通工具代码并返回运行结果。 */
const postToolDebug = (payload: ToolDebugPayload) => {
return post<ToolDebugPayload, unknown>(`${getPrefix()}/debug`, payload)
}

/** 获取工具详情。 */
const getToolDetail = (toolId: string) => {
return get<ToolItem>(`${getPrefix()}/${toolId}`)
Expand All @@ -42,37 +57,22 @@ const postToolImport = (file: File, folderId: string) => {
}

/** 上传 Skill 压缩包并返回临时文件 ID。 */
const postSkillFile = (file: File) => {
const putUploadSkillFile = (file: File) => {
const payload = new FormData()
payload.append('file', file)
return post<FormData, string>(`${getPrefix()}/upload_skill_file`, payload)
return put<FormData, string>(`${getPrefix()}/upload_skill_file`, payload)
}

/** 下载 Skill 工具的压缩包。 */
const downloadSkillFile = (toolId: string, fileName: string) => {
return getExportFile(fileName, `${getPrefix()}/${toolId}/download_skill_file`)
const downloadSkillFile = (toolId: string) => {
return downloadRequest(`${getPrefix()}/${toolId}/download_skill_file`, 'GET')
}

/** 导出工作空间工具文件。 */
const exportTool = (toolId: string, toolName: string) => {
return getExportFile(`${toolName}.tool`, `${getPrefix()}/${toolId}/export`)
}

/** 检查工作空间工具的 Python 代码。 */
const postToolPylint = (code: string) => {
return post<{ code: string }, ToolPylintIssue[]>(`${getPrefix()}/pylint`, { code })
}

// const generateCode = (data: any) => {
// const p = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api'
// return postStream(`${p}${getPrefix()}/generate_code`, data)
// }

/** 调试普通工具代码并返回运行结果。 */
const postToolDebug = (payload: ToolDebugPayload) => {
return post<ToolDebugPayload, unknown>(`${getPrefix()}/debug`, payload)
}

/** 测试工具配置是否可连接。 */
const postToolTestConnection = (payload: ToolPayload) => {
return post<ToolPayload, boolean>(`${getPrefix()}/test_connection`, payload)
Expand Down Expand Up @@ -103,7 +103,7 @@ export default {
postTool,
postToolDebug,
postToolImport,
postSkillFile,
putUploadSkillFile,
postToolPylint,
postToolTestConnection,
putBatchDeleteTools,
Expand Down
7 changes: 7 additions & 0 deletions ui/src/assets/file-type/csv-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ui/src/assets/file-type/doc-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ui/src/assets/file-type/docx-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ui/src/assets/file-type/file-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions ui/src/assets/file-type/html-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ui/src/assets/file-type/md-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ui/src/assets/file-type/pdf-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions ui/src/assets/file-type/txt-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading