feat: 支持导入思源 .sy.zip 笔记 - #1166
Open
jibwf wants to merge 1 commit into
Open
Conversation
在桌面端新增思源笔记导出包(.sy.zip)导入能力,复用现有「导入笔记」入口, 将 .sy 文档转换为 Markdown 并按 NoteGen 习惯放置资源文件。同时抽取安全的 ZIP 解压与进程管理模块,供备份恢复与导入 worker 共用,并补充完整测试与 CI 校验。 Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
本 PR 为 NoteGen 桌面端新增思源笔记导出包(
.sy.zip)导入能力。用户通过现有「导入笔记」按钮选择文件:若为.sy.zip则走思源导入流程,否则保持原有 Markdown 文件夹导入逻辑不变。导入结果写入当前工作区,
.sy文档转为 Markdown,资源文件按 NoteGen 既有习惯放置在各笔记同级{assetsPath}/目录(默认assets/),Markdown 内使用相对路径引用(如assets/image.png)。有子目录的文档会生成{文件夹名}/{文件夹名}.md,与点击文件夹时打开同名首页文档的现有行为一致。架构说明
.syJSON 解析、块树转 Markdown、块引用/数据库(AV)/资源路径处理新增文件(主要模块)
src/lib/import/siyuan/*src/lib/fs/exclusive-file.tssrc-tauri/src/siyuan_import.rssrc-tauri/src/zip_extract.rssrc-tauri/src/process_util.rssrc-tauri/src/maintenance_lock.rsscripts/siyuan-import-worker*.mjssrc-tauri/resources/node-runtime/tests/siyuan-*.spec.mjs+ fixtures对原有代码的改动(请重点审核)
1. 文件管理 / 导入入口
use-markdown-import.ts.sy.zip和普通目录;根据扩展名分发到思源导入或原 Markdown 导入import-lock.ts:Markdown 导入与思源导入互斥,避免并发file-more-menu.tsx/file-actions.tsx/file-manager.tsxuse-siyuan-import.ts与进度对话框siyuan-import-dialog.tsxfolder-item/index.tsx{文件夹名}/{文件夹名}.md则打开该文档2. 编辑器 / 图片路径(兼容导入后的 Markdown)
tiptap-editor.tsxsrc转换 effect 增加对activeFilePath的依赖,切换文件时重新解析相对路径data-relative-src与已转换asset://URL 的保留逻辑,避免重复转换导致图片丢失\u200b)markdown-paragraph.tsstripSiYuanInvisibleMarkdownChars,加载时清理不可见字符utils.ts/markdown-image-path.tsdecodeWorkspaceImagePath,处理 URL 编码的图片路径(如%20)3. Rust 后端
backup.rs(较大改动)zip_extract::extract_zip_safelyMaintenanceGuard,与思源导入互斥restore_app_data_from_temp,消除重复逻辑mcp_runtime.rs/skill_runtime.rsprocess_util.rslib.rs/main.rsimport_siyuan_archive、cancel_siyuan_importsiyuan_import、zip_extract、process_util、maintenance_lockshutdown_active_importprinting.rs/app_setup.rstauri.conf.json4. CI / 构建
.github/workflows/release.ymlfetch-node-runtime.mjs)build-siyuan-worker+verify:siyuan-worker)package.jsontest:import、build:siyuan-worker、verify:siyuan-worker、verify、smoke:desktop-siyuan5. 国际化
messages/*.json安全考量
..traversal、条目数/uncompressed 大小上限writeTextFileExclusive/copyFileExclusive,不覆盖已有笔记或资源已知限制 / 降级行为
TAURI_SIGNING_PRIVATE_KEY)缺失时 updater 签名步骤仍会失败,不影响.app构建测试
自动化测试
pnpm verify # 包含 typecheck + lint + test:import(59项) + verify:siyuan-workermacOS 构建与实测
已在 macOS(Apple Silicon / arm64) 本地完成桌面端构建与手动验证:
pnpm tauri buildNoteGen.app(v0.32.1,arm64),已安装至/Applications/NoteGen.app进行实测.dmg打包成功;末尾 updater 签名因缺少TAURI_SIGNING_PRIVATE_KEY报错,不影响.app本地安装与功能验证实测内容(思源
.sy.zip导入):.sy.zip走思源导入,选择文件夹仍走原 Markdown 导入Security,无多余assets笔记本或.siyuan-import隐藏目录)VPN/VPN.md,点击文件夹可打开同名首页)assets/目录,Markdown 引用为assets/...,Cryptography 等章节图片可正常显示手动验证建议(其他平台/Reviewer)
.sy.zip」测试包.sy.zipVPN/VPN.md)、图片显示变更规模