Skip to content

feat(library): /library 模块 — 用户技术文档精读 (V0.8)#54

Merged
bob798 merged 2 commits into
mainfrom
feat/library-module
May 21, 2026
Merged

feat(library): /library 模块 — 用户技术文档精读 (V0.8)#54
bob798 merged 2 commits into
mainfrom
feat/library-module

Conversation

@bob798

@bob798 bob798 commented May 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • 后端:新增 library_articles 表(LibraryArticle ORM model)+ library_service.py(trafilatura URL 抓取 + 粘贴 Markdown 导入 + CRUD)+ app/routers/library.py(7 个端点:CRUD + 3 个解读端点);添加 trafilatura>=2.0.0 依赖;VALID_SOURCE_TYPES 加入 "library"
  • 前端:新增 Library.vue(列表页 + 添加文章模态框)+ LibraryArticle.vue(阅读详情 + 点词浮气泡 + 选区翻译 + 本文沉淀侧栏);路由 /library + /library/:id;Home 页导航加入「文章库」入口
  • 测试:13 个测试全绿,覆盖粘贴导入、URL 去重、分页、软删、explain 自动入库 vocabulary、phonetic、vocab_count

Key Design Decisions

  • URL 去重:(user_id, source_url) 唯一约束;命中返回 {existing: true, ...} + 200
  • 解读自动入库:复用 articles 路由的 _auto_save_vocab 模式(先占位 → 完成回填 explanation_json)
  • 软删:文章软删不级联 vocabulary(已沉淀语言点独立于文章生命周期)
  • 抓取失败:400 + {error: "fetch_failed", hint: "..."},前端自动切到粘贴 tab
  • Markdown 渲染:MVP 内置简单渲染器(无 marked/DOMPurify 外部依赖,不影响 bundle size budget)

Test plan

  • pytest tests/test_v08_library.py -v → 13 passed
  • 手测:粘贴 URL → 抓回正文 → 点词出气泡 → IPA 秒出 → 展开解读 → 本文沉淀侧栏出现条目
  • 手测:粘贴正文(Markdown 模式)完整流程
  • 手测:抓取失败 → 自动切粘贴 tab
  • 手测:软删文章 → 已沉淀词不丢失

🤖 Generated with Claude Code

bob798 and others added 2 commits May 21, 2026 23:03
New module allowing users to import English tech docs (via URL or paste),
read them in-app with click-to-translate, and automatically save vocabulary
to the shared `vocabulary` table with source_type='library'.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
# Conflicts:
#	app/services/vocab_service.py
@bob798 bob798 merged commit 2a3b6b7 into main May 21, 2026
1 check passed
@bob798 bob798 deleted the feat/library-module branch May 21, 2026 15:25
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.

1 participant