Files
mnote/.codex/reasonix-tasks/2026-05-25-batch-b-worker-d3-3-20-insert-uploaded-asset-runtime.md
T

72 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Reasonix Batch B / Worker D33-20 insertUploadedAssetIntoEditor 外置候选实现
Project root`/mnt/Data1T/mnote-worktrees/0525-b3-upload-insert-runtime`
## 目标
在独立 worktree 中产出候选 patch:把 `SIDEBAR_TREE_JS``insertUploadedAssetIntoEditor(asset, targetRoot)` 的主体同构迁入 `rust/crates/mnote-web/browser/local-upload-runtime.js``layout.rs` 只保留委托 wrapper 和 inline fallback。不得改变上传落盘、资源归属、OnlyOffice URL 或 editor 插入行为。
## 允许修改
- `rust/crates/mnote-web/browser/local-upload-runtime.js`
- `rust/crates/mnote-web/src/ssr/pages/layout.rs`
必要时只更新 `layout.rs` 中现有字符串断言测试。不要修改设计文档、AGENTS、其它源码、generated wasm、git 状态或提交。
## 实现要求
- `local-upload-runtime.js` 新增 `insertUploadedAssetIntoEditor(asset, targetRoot, deps)`,并导出到 `window.__mnoteLocalUploadRuntime.insertUploadedAssetIntoEditor`
- `layout.rs` 中原 `insertUploadedAssetIntoEditor(asset, targetRoot)` 优先委托:
`localUploadRuntimeFunction('insertUploadedAssetIntoEditor')`
- 外置 runtime 不复制 resource/open 长期业务语义,必须通过 `deps` 接收以下既有 helper
- `uploadedAssetTitle`
- `localAssetOpenUrl`
- `uploadedAssetUrl`
- `uploadedAssetType`
- `isLocalUploadedAsset`
- `buildOnlyOfficeAssetOpenUrl`
- `fetchCurrentOnlyOfficeUserId`
- `buildOnlyOfficeOpenPath`
- `inferOnlyOfficeFileType`
- `currentDocumentId`
- `uploadedAttachmentClass`
- `uploadedFileSize`
- `cssEscape`
- `enhanceEditorAttachmentLinks`
- 保持以下 DOM attribute 行为完全不变:
- `data-mnote-last-upload-inserted`
- `data-mnote-last-upload-asset-id`
- `data-mnote-last-upload-insert-error`
- 保持 image 分支 `setImage({ src, alt, title })` 行为不变。
- 保持附件 link content、`storedHref``class``target``rel`、后续 `setTimeout` enhance 行为不变。
- runtime 不存在时,inline fallback 必须继续执行原实现。
## 禁止事项
- 不迁 `uploadFileToMediaAsset` / `uploadFilesWithResolvedTarget` 编排流程。
- 不改 `/api/local-folder/assets/upload` 合同。
- 不改 resource open / OnlyOffice URL 语义。
- 不做格式化之外的邻近重构。
- 不提交 git。
## 验收命令
```bash
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 -- --test-threads=1
cargo test --manifest-path rust/Cargo.toml -p mnote-web sidebar_upload_runtime_routes_local_markdown_assets_to_local_folder -- --test-threads=1
```
## 输出要求
handoff 必须列出:
- 修改文件。
- 委托 deps 清单。
- 是否保持 fallback。
- 验收命令和结果。
- 未覆盖风险。
- `git diff --stat`