WeKnora/frontend/src/views/platform
wheatzone 2384fbae4e
fix: support folder drag-and-drop upload with directory structure preserved (#2677)
* fix: support folder drag-and-drop upload with directory structure preserved

Drag-dropping a folder onto the knowledge base page was treated as a
single phantom file (size 0, no extension) and failed with "unsupported
file type" on Chrome/Edge, or silently did nothing on Firefox.

Root cause: collectDroppedFiles checked dataTransfer.files first, which
Chrome/Edge populates with non-traversable directory entries for folder
drops. The function never reached the webkitGetAsEntry branch that can
recursively traverse directory contents.

Fix: reverse the priority — try webkitGetAsEntry first to recursively
traverse dropped directories, setting webkitRelativePath on each File to
preserve the folder structure (same format as <input webkitdirectory>).
Fall back to dataTransfer.files only for plain file drags or browsers
without webkitGetAsEntry support.

Additional details:
- readEntries() is called in a loop until empty (batches may be partial)
- Hidden files/directories (segments starting with .) are skipped,
  matching the button-based folder upload behavior
- Top-level dropped files keep webkitRelativePath empty so they upload
  as individual files, not folder uploads
- Object.defineProperty is used with try/catch for Safari compatibility

Closes #2676

* style: switch code comments to Chinese for consistency with existing file

* fix: don't fall back to phantom files after directory drag-drop

Once webkitGetAsEntry returns entries, trust the traversal result even
when it is empty (empty or hidden-only folders). Falling back to
dataTransfer.files reintroduced Chrome/Edge's size-0 directory File.
Also isolate per-item failures and cover the collector with unit tests.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-08-13 10:44:16 +08:00
..
RoutePlaceholder.vue feat(frontend): add publish integrations center and streamline agent editor 2026-06-24 20:09:19 +08:00
collectDroppedFiles.test.ts fix: support folder drag-and-drop upload with directory structure preserved (#2677) 2026-08-13 10:44:16 +08:00
collectDroppedFiles.ts fix: support folder drag-and-drop upload with directory structure preserved (#2677) 2026-08-13 10:44:16 +08:00
index.vue fix: support folder drag-and-drop upload with directory structure preserved (#2677) 2026-08-13 10:44:16 +08:00