1
Fork 0
mirror of https://github.com/thegeneralist01/archivr synced 2026-12-04 18:56:44 +01:00
archivr/crates/archivr-cli
TheGeneralist e40312734d
feat: entry export (HTML / PDF / Markdown) with quiet Archivr credit
Adds a self-contained export feature across core, server, CLI, and frontend.
Users can export one or more archived entries as a shareable bundle without
exposing the Archivr instance. A small 'Preserved with archivr' credit is
included by default and can be toggled off per export.

Core (crates/archivr-core/src/export/):
- brand.rs   — export CSS (palette from style-guide), CREDIT_HTML,
               CREDIT_INLINE_HTML (for snapshot injection)
- model.rs   — ExportEntry / ExportBody / Asset loading; tweet thread
               reconstruction (reply-graph DFS, sibling ordering)
- html.rs    — full HTML document renderer: all body kinds, AssetMode
               Bundle vs Print, render_cover for PDF cover pages
- markdown.rs — Markdown renderer with poster-linked video, blockquoted
               quote tweets, credit sub-tag
- bundle.rs  — ZIP writer (Deflated for text, Stored for binary,
               large_file for >= 4 GiB assets)
- pdf.rs     — print_pdf (headless Chrome), merge_documents (lopdf
               ID-offset merge), entry_pdf (snapshot injection,
               PDF-merge, HTML fallback)
- mod.rs     — export_entries, prune_stale_export_dirs, ExportFile,
               ffmpeg poster generation, full assembly dispatch

summarizer.rs: extract pub(crate) article_parts so the export module
reuses the article title/body logic without duplication.

Server (crates/archivr-server/src/exports.rs):
- GET /api/archives/:archive_id/export?entries=&format=&layout=&credit=
- Auth required (guests -> 401); per-UID ensure_entry_visible check
- Blocking spawn_blocking task; streaming response via ReaderStream
- ARCHIVR_EXPORT_PDF_TIMEOUT added to ENV_VARS (default 120 s)
- ARCHIVR_CHROME description updated to mention PDF export
- prune_stale_export_dirs called at startup (6 h TTL)

CLI (crates/archivr-cli/src/main.rs):
  archivr export <UIDs...> [--format html|pdf|markdown]
                           [--separate] [--no-credit] [-o DIR]

Frontend:
- api.js: downloadEntryExport (blob + filename from Content-Disposition)
- ExportDialog.jsx: native <dialog>; format selector; Combine toggle
  (>= 2 entries); credit toggle (on by default); error display
- ContextRail.jsx: single-entry Export... button after Preview; bulk
  Export N entries... section before delete zone; orderedSelection
  helper for DOM-order UIDs; ExportDialog mounted once per rail
- styles.css: .rail-export-btn, .export-dialog .export-format rules

Tests:
- 9 new cargo tests in export/mod.rs (HTML, Markdown, PDF merge,
  parent-child dedupe, separate layout, credit on/off, validation)
- 4 new cargo tests in exports.rs (401 no-auth, 200 ZIP, 400 bad
  format, 400 too many entries)
- 4 new bun tests in ExportDialog.test.jsx (single/multi uid, credit
  default, closed state)
- 2 new bun tests in api.test.js (query string, error propagation)

All 247 Rust tests and 50 frontend tests pass.

MCP follow-up: archivr-mcp export_entries tool (GET /api/.../export,
read-scope tokens accepted) — not built here.
2026-10-12 19:51:15 +02:00
..
src feat: entry export (HTML / PDF / Markdown) with quiet Archivr credit 2026-10-12 19:51:15 +02:00
Cargo.toml feat: add YouTube subtitles, local transcription, self-updating yt-dlp/Deno, X Article and thread titles (#39) 2026-10-05 19:41:06 +02:00