refactor: externalize editor upload context

This commit is contained in:
lix-2026
2026-05-24 23:43:22 +08:00
parent 5a96ea9eba
commit 437c690a39
4 changed files with 182 additions and 1 deletions
@@ -466,6 +466,36 @@ 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、文件树滚动、标题来源、单附件删除保留相邻附件。
### 9.5 Batch 4 执行记录(2026-05-24
Reasonix read-only audit
- run id: `reasonix-2026-05-24T15-27-18-395Z-12afda31`
- worker worktree: `/mnt/Data1T/mnote-wt-3-19-local-upload-context-b4`
- handoff: `/home/lix/.codex/runtime/reasonix-coding-worker/reasonix-2026-05-24T15-27-18-395Z-12afda31/process-handoff.md`
- 类型:只读审计,主控已读取 Hindsight recall、`process-handoff.md``process-handoff.json`
采纳内容:
- `local-upload-runtime.js` 新增 `resolveEditorUploadContext``editorRootFromUploadOptions``openEditorUploadFilePicker`
- `SIDEBAR_TREE_JS` 中保留同名 wrapper 和 inline fallback;优先委托 `window.__mnoteLocalUploadRuntime`,模块加载失败时保留旧行为。
- 本批不迁 `uploadFileToMediaAsset``uploadFilesWithResolvedTarget``insertUploadedAssetIntoEditor`。这些函数仍混合 API POST、file tree refresh、Tiptap chain 插入和 OnlyOffice/resource tab 逻辑,后续需要继续拆边界。
- `scripts/task472-side-target-secondary-pane-smoke.js` 补齐 `/api/local-folder/assets/upload` 当前必需的 `uploadIntent=editor.markdown.attach`,让 secondary pane smoke 恢复可运行。
已通过验证:
- `node --check rust/crates/mnote-web/browser/local-upload-runtime.js`
- `cargo fmt --manifest-path rust/Cargo.toml --all --check`
- `cargo check --manifest-path rust/Cargo.toml -p mnote-web`
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web local_upload_runtime_contains_editor_upload_context_helpers`
- `cargo test --manifest-path rust/Cargo.toml -p mnote-web sidebar_upload_runtime_routes_local_markdown_assets_to_local_folder`
- `node scripts/task479-local-folder-markdown-resource-lifecycle-smoke.js`
- 结果:`ok=true`
- 证据:命令 stdout JSON,覆盖 `editor-upload-to-page-resource-dir``filetree-folder-drop-to-target``broken-link-after-real-file-delete``direct-attach-open-without-active-md``editor-delete-one-attachment-preserves-adjacent` 等检查。
- `node scripts/task472-side-target-secondary-pane-smoke.js`
- 结果:`ok=true`
- 证据:命令 stdout JSON`assetId=local:asset:README/side-target-resource.md``officeAssetId=local:asset:README/side-target-office.docx`
## 10. 分阶段执行清单
### P0:定位辅助与基线保护
@@ -498,7 +528,7 @@ node scripts/task479-local-folder-markdown-resource-lifecycle-smoke.js
- office -> OnlyOffice path builder
- [ ]`SIDEBAR_TREE_JS` 中迁出本地文件夹上传目标计算和 adapter 调用;资源归属语义仍由 Rust API / kernel 合同决定。
- 2026-05-24 / `reasonix-2026-05-24T15-17-16-430Z-18054487` 只读审计:`leptos-tiptap` 只应发出上传 intent;本地 Markdown 路径、`rootUri``/api/local-folder/files/open` URL、`markdownRelativePath` 与真实上传落盘都归本设计的 shell host runtime。
- 下一刀低风险候选`resolveEditorUploadContext``editorRootFromUploadOptions``openEditorUploadFilePicker`优先保持调用 `uploadFilesWithResolvedTarget`同时迁上传主流程。
- 2026-05-24 / Batch 4 已迁`resolveEditorUploadContext``editorRootFromUploadOptions``openEditorUploadFilePicker`保持调用 `uploadFilesWithResolvedTarget`同时迁上传主流程。
- 暂不迁:`uploadFileToMediaAsset``uploadFilesWithResolvedTarget``insertUploadedAssetIntoEditor`。这些函数同时涉及 API POST、file tree refresh、Tiptap chain 插入、OnlyOffice/resource tab,需在后续批次继续拆边界。
- [ ] 保持现有 smoke
- `node scripts/task472-side-target-secondary-pane-smoke.js`