Sixteen API routers declared APIRouter() with no dependencies, so their
mutating routes relied solely on ASGI middleware. In server mode bound to
0.0.0.0 without OMNIVOICE_API_KEY or a share PIN those routes were
reachable unauthenticated from LAN.
Desktop default (bind 127.0.0.1) is unchanged: require_admin permits
loopback, matching the routers that were already gated.
Router-level choices after review: openai_compat stays on require_consumer
because /v1 is the documented consumption surface for PIN and
trusted-network clients; the side-effectful pending-sample materialization
inside GET /profiles/{id}/audio uses a media-action admin gate
(require_admin_media_action) because media elements cannot carry the CSRF
marker header that require_admin_action demands — cross-site GETs stay
rejected and bare-server anonymous callers stay refused.
Handler tests that exercised the changed routers with a default TestClient
host now use an explicit loopback peer, matching the existing pattern for
gated routers. test_admin_route_policy.py asserts require_admin on every
gated router, require_consumer on /v1, and the media-action guard on the
profiles materialization branch.
Excluded: events/tts_stream (websocket-only, covered by
BearerKeyMiddleware), speech_platform (read-only discovery intentionally
reachable from tailnet and reverse proxy clients).
Consolidate community engine, workflow, dictation, and setup fixes with the Electron composer, sidebar, and voice UI.
Fix review findings in engine residency, remote exports, backup cleanup, bounded compressed-audio decoding, and reference preprocessing. Preserve contributor credits in CHANGELOG.md and leave the app version unchanged.
Supersedes #2325, #2338, #2368, #2377, #2379, #2380, #2383, #2384, #2387, #2390, #2391, #2392, #2393, #2395, #2400, #2401, #2402, #2409, #2410, and #2412.
CodeRabbit finding. UTF-16 without a mark is out of spec (XML 1.0 §4.3.3
requires one), but real EPUBs carry it -- and in such a document the
declaration is unreadable, because the ASCII byte patterns never match
NUL-interleaved bytes. The entry fell through to the UTF-8/Windows-1252
guess and narrated the markup.
XML 1.0 Appendix F reads the opening "<" instead: its byte pattern names
the width and byte order. Widest first, since "<\0\0\0" also starts "<\0".
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Two Greptile P1s on this PR, both real:
- A UTF-32 LE byte-order mark starts with the UTF-16 LE one, so the BOM
table matched UTF-16 first, stripped two bytes and read the file as
NUL-interleaved UTF-16; a UTF-32 BE mark matched nothing and fell through
to Windows-1252. The table lives in services.text_upload and is shared, so
/dub/import-srt and the .txt/.md branch of /audiobook/import carried the
same corruption -- it is fixed once, longest mark first, and both front
doors and the EPUB path inherit it.
- A declaration such as encoding="hex_codec" passes codecs.lookup but
bytes.decode refuses it with LookupError, which would have failed the
whole EPUB import. The codecs.lookup pre-check is gone: the decode itself
decides, and an encoding that cannot produce text now guesses like an
undeclared document does.
text_upload gains bom_encoding() so the EPUB path asks the one table rather
than keeping a second copy of it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Every EPUB chapter document was decoded as raw.decode("utf-8", "ignore").
UTF-8 is only the default for an XML document: a BOM or an encoding= /
charset= declaration overrides it, and EPUB 2 books -- including Calibre
conversions of older HTML -- routinely declare ISO-8859-1, Windows-1252 or
a CJK code page. errors="ignore" then silently DELETED every byte those
documents spell their accents, dashes and curly quotes with, so
"Le cafe etait ferme." imported, and was narrated, as "Le caf tait ferm.".
A UTF-16 document degraded further, into NUL-interleaved markup.
_decode_epub_entry now reads a BOM first (it outranks any declaration),
then the declared encoding when Python knows it, and otherwise falls back
to services.text_upload.decode_text_upload -- the same BOM -> UTF-8 ->
Windows-1252 ladder the .txt/.md branch of /audiobook/import already uses,
so both front doors onto the same pipeline agree. Nothing can raise: an
unknown or wrong declaration still imports, the way an undeclared file
does.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
POST /audiobook/import ended with `plan.chapter_count`, but AudiobookPlan
only exposed `char_count` (a property) and emitted `chapter_count` from
`to_dict()` — so the attribute access raised AttributeError, surfacing as
"500 Internal Server Error: 'AudiobookPlan' object has no attribute
'chapter_count'". The parse itself succeeded, so this hit every import
format (.txt/.md/.epub/.pdf), not just PDF.
Add a `chapter_count` property mirroring `char_count`, and have `to_dict()`
derive its key from it so the attribute and serialized key can't drift.
No API/schema/data change.
Tests: unit property test + a direct-handler /audiobook/import regression
(pdf/md/txt) that fails-before with the AttributeError.
Fixes#543
Co-authored-by: mergetest <test@local>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
The audiobook importer accepted .txt/.md/.epub but not PDF — the single most
common "ebook in" format. Add a pure `pdf_to_chapter_script(data)` that
extracts the text layer page-by-page and runs it through the existing
chapterizer, so PDFs land in the same `# Heading` + body grammar EPUB and
plaintext already produce (one front door onto the unchanged render pipeline).
- Dep: `pypdf>=4.0` — pure-Python, MIT, zero native deps, so PDF import behaves
identically on macOS/Windows/Linux (default-feature cross-platform rule).
EPUB + plaintext stay stdlib-only; only PDF needs a real parser.
- Robustness, surfaced as actionable 400s rather than silent empty imports:
corrupt file, password-protected (empty-password decrypt attempted first),
scanned/image-only (no text layer → clear "scanned PDF" message), and a
page-count ceiling. A single unparseable page is skipped, not fatal.
- Route: `.pdf` branch in audiobook_import; frontend accept filter +
api-client doc updated to `.txt,.md,.epub,.pdf`.
tests/test_longform_import.py: 5 PDF cases (extract+chapterize, no-marker
single chapter, corrupt, image-only, page-cap) using a hand-built in-memory
PDF — no PDF-authoring test dep, mirroring the in-memory-EPUB approach.
16 passed; frontend suite 401; CJK guard green.
* fix(longform): correctness + robustness fixes from adversarial review
Fixes the confirmed findings from a multi-agent review of the convergence:
HIGH (correctness/output):
- MP3 + cover produced a corrupt file (-map 2:v -c:v copy is invalid for mp3).
Cover art is now embedded for M4B only; mp3 skips it (m4b is the cover format).
- Chapter cache key omitted ref_text — editing only a profile's ref_text served
stale audio. ref_text is now part of the voice signature.
- Preview wrote audiobook_cache/ but the render reads longform_cache/ (rename
missed in PR 5) → cache-warming silently broke. Unified to longform_cache/.
Robustness (DoS/OOM guards):
- /audiobook/import caps upload at 64 MB; epub_to_chapter_script bounds per-entry
(25 MB) and cumulative (300 MB) uncompressed reads (zip-bomb guard).
- /longform/render rejects > 10,000 chapters (422).
Frontend leaks:
- StoriesEditor.removeTrack revokes the line's preview blob URL.
- AudiobookTab revokes the cover blob URL on replace/unmount.
Deferred fast-follows (also from review): render-cache disk eviction; restoring
the standalone chapter cue-sheet export (needs chapter times in the done event).
Tests: mp3-drops-cover, epub entry/total caps, import + chapter-count limits;
updated the cache-hit test for the 4-field voice sig. 70 backend + 334 frontend green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test(longform): pass EPUB caps as params, not monkeypatch (CI import-path fix)
The cap tests monkeypatched module constants, but in the full-suite CI context
the module loads under a different import path so the patch missed the function
(it used the real 300 MB cap → tests failed). epub_to_chapter_script now takes
max_entry_bytes/max_total_bytes kwargs (default to the constants); tests pass
small values directly — deterministic regardless of import path.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Spec PR 4. A front door onto the existing chapter parser: import a file, get a
chapter-delimited script in the editor.
Backend (new services/longform_import.py — pure, stdlib only, no new dep):
- chapterize_plaintext(text): inserts `# ` headings ahead of short standalone
chapter-title lines (Chapter/Part/Prologue/…); no-op if the text already has
H1s; long "Chapter …" sentences stay prose. ReDoS-safe (anchored, per-line).
- epub_to_chapter_script(bytes): parses EPUB (zipfile + ElementTree +
html.parser) in spine order → `# Title` + stripped body per document; skips
empty/nav pages; the heading becomes the chapter title (not narrated). Raises
ValueError on a malformed EPUB. ET.fromstring annotated `# nosec B314` (local
user file, no external-entity expansion).
- POST /audiobook/import (UploadFile) → {text, chapters}.
Frontend: an Import button (.txt/.md/.epub) that fills the script editor.
Tests: tests/test_longform_import.py (9) incl. an in-memory synthetic EPUB
(spine order, empty-doc skip, tag stripping, bad-zip). 64 backend + 326 frontend
green; build clean; en.json valid.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>