Skip to content

fix: Manual Import from an ebook request imports the ebook and leaves the audiobook alone - #492

Merged
kikootwo merged 1 commit into
mainfrom
fix/278-ebook-manual-import
Oct 27, 2026
Merged

kikootwo merged 1 commit into
mainfrom
fix/278-ebook-manual-import

Conversation

@kikootwo

@kikootwo kikootwo commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #278

What changed

  • The request type now flows from the request card to the details modal, the Manual Import browser and both APIs. An ebook card opens the browser with requestType: 'ebook' and its request id (src/components/audiobooks/AudiobookDetailsModal.tsx). An audiobook card, and a book opened without a request, open the audiobook import as before.
  • Browser (src/components/audiobooks/ManualImportBrowser.tsx, manual-import/BrowsePhase.tsx, ConfirmPhase.tsx): an ebook import browses with type=ebook, lists ebook files only, shows "Manual Ebook Import" and "N ebook file(s)", and sends requestId and requestType with the import. The audiobook import sends the same body as before.
  • Browse API (src/app/api/admin/filesystem/browse/route.ts): new type query parameter (audiobook, the default, or ebook; anything else is a 400). Ebook mode returns ebookFiles and no disc folders.
  • Import API (src/app/api/admin/manual-import/route.ts) with the new src/lib/services/manual-import.service.ts:
    • resolveImportTarget: the stored request's type decides the import's type. A requestType that disagrees with it is a 400, an unknown type is a 400, and a missing or deleted request is a 404. A request for another book is a 400.
    • resolveEbookSelection: an ebook import accepts only ebook files directly in the folder. A selected audio file, a path or .. in a name is a 400. With no selection it takes the folder's ebook files.
    • claimImportRequest: recycles or creates a request of the import's kind only. An ebook import reuses the named ebook request (or the newest ebook request of the book), else creates one with the available audiobook request as its parent. It never recycles, resets or re-organizes the audiobook request. An active request of that kind is a 409.
  • Organize (src/lib/processors/organize-files.processor.ts): the existing ebook branch now honours selectedFiles. It imports the preferred selected ebook file, and its source cleanup removes only that file, through the same delete guard (cleanupSourceAfterOrganize). A selection with no ebook in it fails the job with a clear message.
  • One ebook extension list: EBOOK_EXTENSIONS (src/lib/constants/audio-formats.ts, now with .azw) is in preference order. The organizer's format list and findEbookFile's preference order derive from it (src/lib/utils/import-inventory.ts, src/lib/utils/file-organizer.ts). The new preferredEbookFile() picks from a selection by that order.
  • Docs: documentation/features/manual-import.md (ebook import, Fixed Issues entry), documentation/integrations/ebook-sidecar.md (format list, Fixed Issues Review guidelines and start fixing issues #3), documentation/testing/e2e-harness.md (new spec row).

Why

The details modal never passed the request type to the Manual Import browser. So Manual Import from an ebook request card was the audiobook import. It listed and accepted only audio files, then recycled the book's audiobook request (even one already available) and re-ran the audiobook organize on the folder, with source cleanup if it was ticked. The ebook request stayed failed, and the folder's audio was imported into the library a second time.

Evidence

  • New e2e e2e/specs/regressions/278-ebook-manual-import.spec.ts. It sets up a book with an available audiobook request, imported from Seed Track.mp3, and a failed ebook request. The source folder holds Book.mp3 and Book.epub. The spec opens Manual Import from the ebook card in /requests, turns cleanup on and imports.
    • Branch image: 1 passed. The browser shows "Manual Ebook Import" and lists only Book.epub. The import names the ebook request. Only that request is organized, and it ends downloaded. The epub lands in the book's library folder with the same bytes. The audiobook request is untouched (status, progress, updatedAt, completedAt). The library folder still holds Seed Track.mp3 and no Book.mp3. Cleanup removed Book.epub and kept Book.mp3.
    • main image (333c88e): 16 of its checks fail on an assertion. The mp3 is listed and the epub is not. No request id or type is sent. The organize job runs on the audiobook request, which leaves available, and the ebook request stays failed. Book.mp3 is copied into the library, and cleanup removes the mp3 rather than the epub.
  • Unit tests, all new:
    • tests/api/admin-manual-import-ebook.routes.test.ts runs the real routes on a real temp folder. It covers type resolution, the 400/404/409 cases, ebook-only selection and the requests touched.
    • tests/processors/organize-ebook-manual-import.test.ts: the ebook branch imports the selected file and cleans up only that file.
    • tests/constants/ebook-extensions.test.ts: the one list, its order, .azw.
    • tests/components/audiobooks/ManualImportBrowser.test.tsx: the browse URL and the import body, for each type.
    • tests/components/audiobooks/AudiobookDetailsModal.manual-import.test.tsx: the modal passes the type and request id.
    • With main's src: 21 failed, 10 passed. 20 fail on an assertion. The other fails because preferredEbookFile did not exist yet. On this branch: 31/31, and 53/53 with the two existing manual-import test files.

Checks

  • Unit tests for the changed code (vitest related on the changed src files, plus the new test files): PASS, 141 files, 1843 passed, 1 skipped
  • Type check and lint: PASS (tsc --noEmit clean, e2e type check clean; ESLint reports nothing new in the touched files compared with main, and the new files are clean)
  • Image build: PASS
  • E2E on the branch image: 278-ebook-manual-import, 434-multi-disc-import, smoke, verified-import, verified-import-mapped (sab-remote), library-delete-guard, 242-delete-guard (media-bind): PASS (1, 5, 1, 7, 1, 15 and 12 passed)
  • Full unit suite: PR Tests (CI)

Risk and rollback

  • The audiobook Manual Import is unchanged: same browse listing, same body, same request handling. The audiobook and ebook requests now share one recyclable-status list, which includes downloaded and available, the statuses the audiobook import already recycled.
  • An ebook import writes the shared book row as the ebook organize branch already did (filePath, fileFormat: 'epub', status: 'completed'). This is existing behaviour of every ebook import and is left as is. The row's filesHash is unchanged. With the default ebook path template the folder is unchanged too; a separate ebook path template repoints the row's filePath to the ebook folder, as every automatic ebook import already does.
  • The organizer's ebook formats and preference order now come from EBOOK_EXTENSIONS; both are the same as before. .azw, which the organizer already accepted, joins EBOOK_EXTENSIONS, so the request download route (/api/requests/[id]/download) now also serves an .azw ebook. The ranking algorithm's title-format list is separate and unchanged.
  • An API caller that sends requestType that disagrees with the named request, or audio files to an ebook import, now gets a 400.
  • Rollback: revert this PR. Nothing stored is rewritten.

Release note

🤖 Generated with Claude Code

… audiobook

The details modal opened from an ebook request card now passes the request
type and id to the Manual Import browser. The browser lists ebook files
(`type=ebook`), and the import names the ebook request. The server takes the
type from the stored request (a disagreeing flag, or files of the other kind,
is a 400), recycles or creates only an ebook request, and queues the ebook
organize branch with the selected ebook files; that branch imports the
preferred selected file and its source cleanup removes only that file.
An ebook import no longer recycles or re-organizes the audiobook request.

EBOOK_EXTENSIONS is the one ebook extension list (now with .azw);
the organizer's format list and preference order derive from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kikootwo
kikootwo marked this pull request as ready for review October 27, 2026 11:10
@kikootwo
kikootwo merged commit 64df2b1 into main Oct 27, 2026
1 check passed
@kikootwo
kikootwo deleted the fix/278-ebook-manual-import branch October 27, 2026 11:10
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.

Manually import only allows for audiobook files

1 participant