You've already forked DataMate
feat(rag): 添加文件相对路径支持功能
- 在FileInfo DTO中新增relativePath字段 - 实现文件相对路径的规范化处理逻辑 - 将文件相对路径存储到元数据中 - 前端添加文件路径解析和显示功能 - 优化路径分隔符统一处理机制 - 更新文件列表展示逻辑以支持路径层级结构
This commit is contained in:
@@ -26,19 +26,20 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) {
|
||||
|
||||
const [selectedFilesMap, setSelectedFilesMap] = useState({});
|
||||
|
||||
const PATH_SEPARATOR = "/";
|
||||
const normalizePath = (value?: string) =>
|
||||
(value ?? "").replace(/\\/g, "/");
|
||||
(value ?? "").replace(/\\/g, PATH_SEPARATOR);
|
||||
|
||||
const resolveRelativeFileName = (file: DatasetFile) => {
|
||||
const resolveRelativePath = (file: DatasetFile) => {
|
||||
const normalizedName = normalizePath(file.fileName);
|
||||
if (normalizedName.includes("/")) {
|
||||
if (normalizedName.includes(PATH_SEPARATOR)) {
|
||||
return normalizedName.replace(/^\/+/, "");
|
||||
}
|
||||
|
||||
const rawPath = normalizePath(file.path || file.filePath);
|
||||
const datasetId = String(file.datasetId || "");
|
||||
if (rawPath && datasetId) {
|
||||
const marker = `/${datasetId}/`;
|
||||
const marker = `${PATH_SEPARATOR}${datasetId}${PATH_SEPARATOR}`;
|
||||
const index = rawPath.lastIndexOf(marker);
|
||||
if (index >= 0) {
|
||||
const relative = rawPath
|
||||
@@ -50,7 +51,7 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) {
|
||||
}
|
||||
}
|
||||
|
||||
const fallbackName = rawPath.split("/").pop();
|
||||
const fallbackName = rawPath.split(PATH_SEPARATOR).pop();
|
||||
return fallbackName || file.fileName;
|
||||
};
|
||||
|
||||
@@ -158,7 +159,8 @@ export default function AddDataDialog({ knowledgeBase, onDataAdded }) {
|
||||
const requestData = {
|
||||
files: Object.values(selectedFilesMap).map((file) => ({
|
||||
id: String(file.id),
|
||||
fileName: resolveRelativeFileName(file as DatasetFile),
|
||||
fileName: (file as DatasetFile).fileName,
|
||||
relativePath: resolveRelativePath(file as DatasetFile),
|
||||
})),
|
||||
processType: newKB.processType,
|
||||
chunkSize: Number(newKB.chunkSize), // 确保是数字类型
|
||||
|
||||
Reference in New Issue
Block a user