WeKnora/frontend/src
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
..
api fix(frontend): harden document chunk pagination state handling 2026-08-12 13:23:44 +08:00
assets feat(datasource): 支持 GitLab 数据源文档同步 (#2656) 2026-08-12 16:09:55 +08:00
components feat(im): support reverse proxy for feishu websocket long connection (#2550) 2026-08-12 16:18:27 +08:00
composables feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
config feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
directives feat(frontend): enhance chat image handling and typewriter effect 2026-06-18 18:42:16 +08:00
hooks fix(frontend): harden document chunk pagination state handling 2026-08-12 13:23:44 +08:00
i18n fix(datasource/gitlab): 修复项目路径编码与连接器单例缓存问题 (#2673) 2026-08-12 16:22:02 +08:00
router fix(invitation): harden auto-accept follow-ups from code review 2026-08-10 15:47:29 +08:00
stores feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 2026-08-11 15:42:02 +08:00
types fix(chunking): align preview with parent-child splitting / 修复预览与父子分块不一致 2026-08-05 15:09:14 +08:00
utils fix(ui): 统一剪贴板复制为公共方法,HTTP 环境回退 execCommand 2026-08-12 15:38:01 +08:00
views fix: support folder drag-and-drop upload with directory structure preserved (#2677) 2026-08-13 10:44:16 +08:00
wailsjs feat: implement automatic update checking and downloading functionality in the desktop app, enhancing user experience with seamless updates and corresponding UI settings 2026-04-11 18:51:16 +08:00
App.vue feat: 邀请链接在 invite_only 模式下改为登录后加入空间 2026-08-10 14:57:38 +08:00
embed-main.ts feat(embed): add widget, visitor chat, and management UI (#1657) 2026-06-12 23:10:39 +08:00
main.ts fix(invitation): harden auto-accept follow-ups from code review 2026-08-10 15:47:29 +08:00