Skip to content

✨ 1. Knowledge base tracing results support downloading. 2. File download requests are made to the backend interface, instead of directly accessing Minio.#1975

Merged
Phinease merged 4 commits intodevelopfrom
develop_file_download_api
Dec 4, 2025
Merged

✨ 1. Knowledge base tracing results support downloading. 2. File download requests are made to the backend interface, instead of directly accessing Minio.#1975
Phinease merged 4 commits intodevelopfrom
develop_file_download_api

Conversation

@Zhi-a
Copy link
Copy Markdown
Contributor

@Zhi-a Zhi-a commented Dec 2, 2025

✨ 1. Knowledge base tracing results support downloading.

  1. File download requests are made to the backend interface, instead of directly accessing Minio.

1、知识库溯源结果(nexent、datamate)支持文件下载
2、知识库溯源结果,说明分片知识来源(nexent、datamate)
3、修复直接访问Minio URL下载文件问题。当前通过前端调用后端下载文件接口,返回文件流,并通过浏览器下载文件。

https://github.com/user-attachments/assets/c6c21899-3532-4fde-a822-37702350983c
image

@Zhi-a Zhi-a requested a review from Phinease as a code owner December 2, 2025 12:36
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 2, 2025

Codecov Report

❌ Patch coverage is 95.17241% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/apps/file_management_app.py 94.53% 3 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@Zhi-a Zhi-a force-pushed the develop_file_download_api branch from 632b676 to 0fa5714 Compare December 3, 2025 02:53
2. File download requests are made to the backend interface, instead of directly accessing Minio.
@Zhi-a Zhi-a force-pushed the develop_file_download_api branch from 0fa5714 to 9f6444c Compare December 3, 2025 03:24
Zhi-a added 2 commits December 3, 2025 11:25
2. File download requests are made to the backend interface, instead of directly accessing Minio.
2. File download requests are made to the backend interface, instead of directly accessing Minio.
@Zhi-a Zhi-a force-pushed the develop_file_download_api branch 5 times, most recently from 96080fe to 2e8d4f9 Compare December 3, 2025 12:41
Comment on lines +246 to +309
// Handle datamate source type separately
if (source_type === "datamate") {
if (!datamateDatasetId || !datamateFileId || !datamateBaseUrl) {
if (!url || url === "#") {
message.error(t("chatRightPanel.fileDownloadError", "Missing Datamate dataset or file information"));
return;
}
}
await storageService.downloadDatamateFile({
url: url !== "#" ? url : undefined,
baseUrl: datamateBaseUrl,
datasetId: datamateDatasetId,
fileId: datamateFileId,
filename: filename || undefined,
});
message.success(t("chatRightPanel.fileDownloadSuccess", "File download started"));
return;
}

// Check if URL is a direct http/https URL that can be accessed directly
// Exclude backend API endpoints (containing /api/file/download/)
if (
url &&
url !== "#" &&
(url.startsWith("http://") || url.startsWith("https://")) &&
!url.includes("/api/file/download/")
) {
// Direct download from HTTP/HTTPS URL without backend
const link = document.createElement("a");
link.href = url;
link.download = filename || "download";
link.style.display = "none";
document.body.appendChild(link);
link.click();
setTimeout(() => {
document.body.removeChild(link);
}, 100);
message.success(t("chatRightPanel.fileDownloadSuccess", "File download started"));
return;
}

// Handle regular file source type
// For knowledge base files, backend stores the MinIO object_name in path_or_url,
// so we should always try to extract it from the URL and avoid guessing from filename.
let objectName: string | undefined = undefined;

if (url && url !== "#") {
objectName = extractObjectNameFromImageUrl(url) || undefined;
}

if (!objectName) {
message.error(t("chatRightPanel.fileDownloadError", "Cannot determine file object name"));
return;
}

await storageService.downloadFile(objectName, filename || "download");
message.success(t("chatRightPanel.fileDownloadSuccess", "File download started"));
} catch (error) {
log.error("Failed to download file:", error);
message.error(t("chatRightPanel.fileDownloadError", "Failed to download file. Please try again."));
} finally {
setIsDownloading(false);
}
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里只判断了source_type为datamate的情况,当下载了文件之后,会通过return强制退出函数。理论上应该采取:

if (url && url !== "#") {
  if (source_type === "datamate") {
    await storageService.downloadDatamateFile
  } else { //默认使用这个进行下载,后续如果需要支持其他来源的文件下载,可以在这里再添加判断。
    await storageService.downloadFile(objectName, filename || "download");
  }
} else { // 统一判断url
  message.error(t("chatRightPanel.fileDownloadError", "Missing Datamate dataset or file information"));
  return;
}

@Zhi-a Zhi-a force-pushed the develop_file_download_api branch from 2e8d4f9 to 4095952 Compare December 4, 2025 02:45
2. File download requests are made to the backend interface, instead of directly accessing Minio.
@Zhi-a Zhi-a force-pushed the develop_file_download_api branch from 4095952 to 7a2e178 Compare December 4, 2025 03:11
@Phinease Phinease merged commit a0b95bc into develop Dec 4, 2025
9 checks passed
@Zhi-a Zhi-a deleted the develop_file_download_api branch December 5, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants