mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-10-13 16:57:24 +08:00
* fix(cli): preserve directory structure in doc upload --recursive `doc upload --recursive` passed an empty customFileName to CreateKnowledgeFromFile, so every file landed in the knowledge base root and the directory tree it was asked to walk was lost. The web UI's folder upload does not have this problem -- it passes the browser-supplied relative path, which the server splits into folder_path + file_name via types.SplitKnowledgeRelativePath. Pass the path relative to the walked directory instead. Files directly under that directory still send "" so the request stays byte-identical to the previous behaviour for the common flat-directory case; only nested files gain a folder prefix. - knowledgeRelativePath() converts to forward slashes (the server splits on "/", so Windows backslashes would not separate) and returns "" for paths outside the walked root rather than leaking a "../" chain into the folder tree. - The test double previously discarded customFileName with `_,` -- which is why this could regress with the suite green. It now records the value and two tests cover the nested and flat cases. * fix(cli): reject only the parent component in knowledgeRelativePath Review feedback on the recursive-upload folder path: - `strings.HasPrefix(rel, "..")` also rejected children whose name merely starts with dots, e.g. `..drafts/report.pdf`. Replaced with a component-wise check (`rel == ".."` or `".."+separator` prefix). - Root-level files must send ""; the guard now returns "" for `filepath.Dir(rel) == "."` explicitly rather than relying on the accidental prefix match to encode that rule. Covered by a `..drafts/report.pdf` case in TestUploadRecursive_PreservesFolderStructure. * test(cli): expect an empty name for root files in knowledgeRelativePath knowledgeRelativePath returns "" for files directly under the walked root, so the test must expect that. Also wrap an over-long line. --------- Co-authored-by: wizardchen <wizardchen@tencent.com>