Commit Graph
15 Commits
Author SHA1 Message Date
DeryFerd 91174516a6 fix(api): gate unprotected routers with require_admin
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).
2026-10-30 03:27:02 +07:00
debpalash 41d0663cdc fix(longform): break lines at block-element boundaries when extracting EPUB text 2026-10-07 09:46:24 +05:30
Palash DebnathandClaude Sonnet 5.5 a0f874f119 test(import): use unbound TestClient for import-route test (#2509 review)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-01 23:03:20 +05:30
Rudy Celekli 51f386bd7b fix(import): recognize CR-only chapter boundaries
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
2026-10-01 13:20:54 -04:00
Palash Debnath 0834c8be28 feat(studio): consolidate community fixes and composer UI (#2419)
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.
2026-09-29 21:15:25 +05:30
Palash Debnath 2651be4c9d fix(epub): bound all metadata reads and ignore non-navigation links 2026-09-18 21:49:43 +05:30
Palash Debnath 817a222304 fix: detect wide EPUB encoding after XML whitespace 2026-09-18 15:30:54 +05:30
Palash Debnath aef5e03326 fix(import): fall back when declared codecs reject replacement decoding 2026-09-18 14:37:53 +05:30
kevin9327andClaude Opus 5 6398f01ac7 fix(import): detect a wide EPUB document that carries no byte-order mark
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>
2026-09-18 08:01:55 +09:00
kevin9327andClaude Opus 5 28ef19dcc6 fix(import): read UTF-32 marks, and survive a non-text declaration
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>
2026-09-18 07:44:30 +09:00
kevin9327andClaude Opus 5 706c8d9358 fix(audiobook): import an EPUB in the encoding it declares
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>
2026-09-18 07:35:27 +09:00
7678d4cca3 fix(audiobook): add AudiobookPlan.chapter_count so import doesn't 500 (#544)
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>
2026-06-20 09:15:40 +05:30
Palash Debnath ca8a2e8eb8 feat(audiobook): PDF ingest for /audiobook/import (ebook-in core value) (#459)
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.
2026-06-14 17:14:28 +05:30
Palash DebnathandClaude Opus 4.8 18e4c2347a fix(longform): correctness + robustness fixes from adversarial review (#418)
* 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>
2026-06-13 16:31:13 +05:30
Palash DebnathandClaude Opus 4.8 ea6833138b feat(audiobook): text + EPUB import → auto-chapter (PR 4/8) (#412)
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>
2026-06-13 14:33:33 +05:30