refactor: externalize local upload helpers

Add local-upload-runtime.js as a browser runtime module for upload and attachment helper functions, with sidebar fallback wrappers and a fixed runtime asset route.

While validating task479, fix the editor attachment delete path so DOM-selected local attachment links are mapped back to a Tiptap text selection before delete_selection(), preserving undo history and adjacent links.
This commit is contained in:
lix-2026
2026-05-24 22:42:53 +08:00
parent 418f8ff8b0
commit 0a03572601
10 changed files with 353 additions and 19 deletions
@@ -417,6 +417,55 @@ CodeGraph 复核:
- `codegraph_search startWithWebSocket` -> `rust/crates/mnote-web/browser/tree-live-controller.js`
- `codegraph_search startWithSseFallback` -> `rust/crates/mnote-web/browser/tree-live-controller.js`
### 9.4 Batch 3 执行记录(2026-05-24
Reasonix implementation run
- run id: `reasonix-2026-05-24T14-22-14-401Z-ea414358`
- worktree: `/mnt/Data1T/mnote-wt-3-19-local-upload-b3`
- 结果:未采纳。该 run 卡在提交 plan 后没有产生工作区 diff,也没有写出 handoff;主控终止残留 runner / acp 进程并删除临时 worktree。
Codex 主控直接完成的最小切片:
- 新增 `rust/crates/mnote-web/browser/local-upload-runtime.js`
- 新增固定 asset route`GET /api/mnote-browser-runtime/local-upload-runtime.js`
- `PageLayout``SIDEBAR_TREE_JS` 前注入 `type="module"` 外置脚本。
- `SIDEBAR_TREE_JS` 中以下上传/附件展示 helper 先做 runtime 代理,保留原实现 fallback
- `uploadedAssetTitle`
- `uploadedAssetUrl`
- `localAssetOpenUrl`
- `uploadedAssetType`
- `fileTreeIconKindForFileName`
- `isLocalUploadedAsset`
- `uploadedAssetExtension`
- `isNonOfficeAttachmentName`
- `attachmentExtensionFromFileName`
- `isPdfAttachmentFileName`
- `isCodeAttachmentFileName`
- `inferCodeAttachmentLanguage`
- `attachmentClassForFileName`
- `uploadedAttachmentClass`
- `uploadedFileSize`
采纳边界:
- 本批次不迁移 `uploadFileToMediaAsset``insertUploadedAssetIntoEditor``uploadFilesWithResolvedTarget` 主流程。
- 本批次不修改 `/api/local-folder/assets/upload` 请求字段、secondary pane 目标选择、resource tab、OnlyOffice、PDF/code 打开逻辑。
验证:
```bash
node --check rust/crates/mnote-web/browser/local-upload-runtime.js
cargo fmt --manifest-path rust/Cargo.toml --all --check
cargo test -p mnote-web sidebar_upload_runtime_routes_local_markdown_assets_to_local_folder
node scripts/task479-local-folder-markdown-resource-lifecycle-smoke.js
```
结果:
- `local-upload-runtime.js` route 返回 `200``content-type=application/javascript; charset=utf-8`
- `task479` 最终 `ok=true`,覆盖主编辑区上传目录、filetree folder drop、broken link 保留、无 active document 附件 tab、文件树滚动、标题来源、单附件删除保留相邻附件。
## 10. 分阶段执行清单
### P0:定位辅助与基线保护
@@ -439,7 +488,7 @@ CodeGraph 复核:
### P1:外置 resource open / local upload adapter
- [x] 新增 `rust/crates/mnote-web/browser/resource-open-runtime.js`
- [ ] 新增 `rust/crates/mnote-web/browser/local-upload-runtime.js`,或先与 resource open 合并为单个不超过 800 行的 `resource-open-runtime.js`
- [x] 新增 `rust/crates/mnote-web/browser/local-upload-runtime.js`,或先与 resource open 合并为单个不超过 800 行的 `resource-open-runtime.js`
- [x] 第一刀只迁 `layout.rs` 中 resource open 的纯函数和 bridge`web_shell.rs` 的 resource tab DOM、session、pane host 生命周期保持在后续 `document-pane-host-runtime.js` 批次。
- [ ]`SIDEBAR_TREE_JS` / `web_shell.rs` 中迁出资源打开路径适配,不改变现有 open intent
- page row -> 当前 pane page tab