Skip to content

feat(media): global asset library backend storage (#54)#104

Merged
appergb merged 1 commit into
mainfrom
feat-54-library-backend
Jun 23, 2026
Merged

feat(media): global asset library backend storage (#54)#104
appergb merged 1 commit into
mainfrom
feat-54-library-backend

Conversation

@Felix201209

Copy link
Copy Markdown
Collaborator

实现简述

新增 crates/opentake-media/src/library.rs:全局可复用素材库的后端存储层(#37 的后端打底,#37-B/#37-C 依赖)。

  • LibraryStore:以显式根目录构造(便于测试 + 由 [#37-B] 全局库 Tauri 命令层(list/favorite/categorize/rename/delete/import_to_project) #55 命令层从 Tauri app_data_dir 传入),内部含 Mutex 串行化清单读改写。
  • default_library_dir():用 dirs crate 跨平台解析 <data dir>/OpenTake/Library(macOS 即 ~/Library/Application Support/OpenTake/Library/)。
  • library.json 清单:{ version, entries: [...] },条目 LibraryEntry { id, type, category, favoritedAt, source, thumb },serde camelCase + type 重命名 + 每字段 #[serde(default)] 容旧。
  • copy-on-favorite:收藏即把源文件字节复制进库,survive 原文件被移动/删除。
  • hash 去重:库内文件名 = 内容的 SHA-256 hex,同字节收藏两次只存一份、复用既有条目。
  • 原子并发安全:清单写临时文件再 rename 覆盖(同卷原子);收藏文件同样 tmp→rename;Mutex 防并发收藏互相覆盖。
  • lib.rs 仅追加一行 pub mod library;;Cargo.toml 新增 dirs = "6"

逐条对照 #54 验收

  • 收藏 → 文件出现在全局库目录 + 清单写入favorite_copies_file_and_writes_manifest 验证 files/<hash><ext> 落盘 + library.json 写入 + 重载一致。
  • 重复收藏不重复存(hash)dedup_same_content_does_not_duplicate:两个不同源路径、相同字节 → 同一 id、清单 1 条、库内 1 文件。
  • 清单读写原子、并发安全 — tmp 文件 + std::fs::rename 原子覆盖;Mutex 串行化读改写。
  • cargo test:copy-on-favorite、去重、分类过滤 — 10 个单测覆盖收藏复制、去重、entries_in_category 分类过滤(Some(c) / None 分区)、移除、serde 全字段 roundtrip、camelCase JSON。
  • fmt + clippy 绿

测试结果

  • cargo fmt --all:无改动。
  • cargo clippy -p opentake-media --all-targets -- -D warnings:绿。
  • cargo test -p opentake-media:214 passed + 10 new(library)passed, 0 failed

Closes #54

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Felix201209 Felix201209 requested a review from appergb as a code owner June 23, 2026 12:39
Copilot AI review requested due to automatic review settings June 23, 2026 12:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Felix201209

Copy link
Copy Markdown
Collaborator Author

COME REVIEW!!!

@appergb appergb left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审核通过 ✅(自动审核流程)

  • 独立新文件 crates/opentake-media/src/library.rs,不碰既有 media.rs/MediaPanel,#91 重写计划无重叠
  • CI 双绿(Rust fmt/clippy/test + Web build);本地复核 cargo check/fmt/clippy 干净、214 测试全过(含 9 个 library 测试)。
  • issue #54 三项验收(copy-on-favorite+manifest 写入、SHA-256 内容寻址去重、原子写 .tmp rename + Mutex 并发安全)均有测试覆盖。
  • 路径安全(id 为 SHA-256 hex、ext 经 Path::extension() 提取,无遍历)。无硬编码密钥。
  • 上游 palmier-pro 无全局库模块,#37 为 OpenTake 新增子系统,无 1:1 要求。

合并后 #106 将自动 retarget 到 main。

@Felix201209 一个 follow-up(非阻塞):library.rs:322 remove() 用 let _ = std::fs::remove_file(path) 静默吞错,建议在 #106 命令层合并前补一行 tracing::warn! 记录删除失败,避免 manifest 与磁盘状态不一致时无日志可查。

@appergb appergb merged commit 3cc3be6 into main Jun 23, 2026
2 checks passed
@appergb appergb deleted the feat-54-library-backend branch June 23, 2026 13:25
@appergb appergb restored the feat-54-library-backend branch June 23, 2026 13:27
@appergb appergb deleted the feat-54-library-backend branch June 23, 2026 13:31
H-Chris233 pushed a commit to H-Chris233/OpenTake that referenced this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[#37-A] 全局素材库后端存储层(目录 + library.json + copy-on-favorite + 去重)

3 participants