Repository navigation
fix: an ebook request delete removes only the ebook file that request placed - #532
Merged
Merged
Conversation
… placed The ebook organize now records the file it copied into the library (Request.placedEbookFiles: path, size, sha256), and only for a 'copied' placement. A request delete removes only recorded files that are unchanged, not recorded by another active request, and in a folder the library delete guard allows. A request with no record removes nothing; a delivered one says why. Adds one nullable column. Closes #497. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…placed-only Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ile check and kept reasons - No response that returns a request row carries placedEbookFiles (absolute library paths): GET/POST /api/requests, GET/PATCH /api/requests/[id], manual-search, select-torrent, request-with-torrent, admin approve, pending-approval and the reported-issue replace. - "Another request recorded this file" now means the same file: same sha256 and size, and the other entry's path reaches the same file (dev/ino), so a symlinked or differently spelled folder counts and a stale entry does not. - A request that delivered before its first recorded import gets an earlier-import marker; its delete still removes the recorded files and says the earlier file was kept. Kept reasons no longer claim a pre-upgrade import when the record write failed, and each reason shows once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #497
What changed
processEbookOrganization,src/lib/processors/organize-files.processor.ts): after a successful organize, one call to the newrecordEbookPlacement()(src/lib/utils/ebook-placement.ts) records the ebook file the import placed inRequest.placedEbookFilesas{ path, size, sha256, placedAt }. It records only whenplaceFilereturnedcopied, which is the only status where RMAB created the file.identical,presentanddiffersmean the library already had the file, so nothing is added and the field becomes[]. The hash is read from the placed bytes (after the Kindle fix). Later imports of the same request append; the same path is replaced by the newest entry. When there is no record yet but the request had already delivered (an import from before this version, or a record write that failed, then a re-import such as Manual Import), the record starts with an{ "earlierImport": "unrecorded" }marker. A hash or database error is a warning and never fails the import; the file is then simply never removed by a delete.removeEbookFiles,src/lib/services/request-delete-files.ts): removes only the recorded files. For each entry, the file stays when:the placement record could not be readassertSafeLibraryDeleteon the file's own folder, without the audio evidence rule): the existing reasons, e.g.it is also the folder of "<title>"<name> is no longer the file RMAB placed<name> changed since RMAB placed it<name> is also the ebook of another requestRMAB has no record of the ebook files this request placed (it was imported before RMAB kept one, or the record could not be saved), so no ebook file was removed; a never-delivered request (e.g.failed) gets no reason.[]givesRMAB has no record that this request placed the ebook (its import found it already in the library), so it was not removed. The marker addsan earlier import of this request has no record (...), so its ebook file was not removed, and the recorded files after it are still removed. Each reason shows once. SQL NULL and JSON null read the same; JSON null is never written.GETandPOST /api/requests,GETandPATCH /api/requests/[id](admins included), manual search, select-torrent, request-with-torrent, admin approve, pending approval and the reported-issue replace all leave it out (hidePlacementRecord(), also insidehideStoredPick(), insrc/lib/services/request-detail-query.ts). The owner detail view already used a field list without it.Audiobook.filePathfor ebooks, so a customebook_path_templatefolder is handled through the recorded path.planEbookDelete(src/lib/utils/library-delete-guard.ts), which guessed from the folder's contents, is removed.requests.placed_ebook_files(Json?). Nothing renamed, dropped or narrowed.documentation/admin-features/request-deletion.md(D2, schema note, Fixed Issues Optimize documentation for AI token efficiency #8 with its limits),documentation/integrations/ebook-sidecar.md(Delete Behavior),documentation/phase3/file-organization.md(ebook placement record),documentation/backend/database.md(Requests),documentation/backend/services/api-tokens.md(responses),documentation/testing/e2e-harness.md(the two new specs and the changed R5).Why
Deleting any ebook request unlinked the only ebook in the book folder, or every ebook there when the folder passed the audio evidence rule, whatever the request's status. A
failedebook request that never downloaded anything removed the user's own epub sitting beside an imported audiobook. Nothing recorded which file an ebook import placed: the organizer knew it in memory only, and the processor stored only the folder. So the delete could only guess, and a user's own file looks the same as RMAB's. The record makes the delete act on what the request actually put there.Evidence
tests/services/request-delete.ebook-placement.test.tsandtests/services/request-delete.ebook-placement-guard.test.tsrun the realdeleteRequest()on temp library folders (Prisma mocked): the issue's steps, every status with no record, NULL,[]and the earlier-import marker, a second ebook request in another format, a file another request recorded (same path, or through a symlinked folder either way round) and a stale entry of another request that does not keep it, a recycled request, a custom ebook template, a changed, resized, linked or missing file, every malformed entry shape, rules a-c (outside the library, the media root, a configured root, a folder holding another book's folder, a shared flat folder), a reason shared by two files shown once, symlinked title folders, and an unlink failure.tests/processors/organize-ebook-placement.test.tsruns the realprocessOrganizeFiles()with the realFileOrganizer.organizeEbook()andplaceFile()into a temp library:copiedwrites one entry with the file's size and sha256;present,identical(compared, and in place) anddiffers(same size, and other size) write[]and leave the library file untouched; earlier entries are kept; a failed record write still endsdownloaded.tests/utils/ebook-placement.test.ts: record reading and validation (the marker included), entry building, merging, the write (marker only on a NULL record with an earlier delivery) and its never-throws paths, and the other-requests lookup.tests/api/requests-placement-record.routes.test.ts:GET /api/requestsfor a user and an admin,POST /api/requests,GET /api/requests/[id]as admin,PATCH /api/requests/[id], pending approval, and the two helpers: noplacedEbookFilesin any response.main'ssrc(efcccc9) and the first set of test files: 46 failed and 8 passed, all 46 on an assertion. The response, shared-file and reason tests fail on the branch's first commit (1423531): 19 of the 20 new tests (17 on an assertion, 2 on the helper that did not exist); the 20th checks that an existing record is never marked.Checks
vitest relatedon the changedsrcfiles plus the changed and new test files): PASS, 112 files, 1397 teststsc --noEmitclean; ESLint reports nothing new in the touched files compared withmain, and the new files are clean)smoke1/1,497-ebook-delete3/3 (a, b, c),library-delete-guard15/15 (R5 removes only the recorded ebook),278-ebook-manual-import1/1,242-delete-guard12/12 (5B and 5C included), and the upgrade from 1.2.12 with497-ebook-legacy(seed 1/1, verify 1/1; requests 6 -> 6, audiobooks 3 -> 3)Risk and rollback
Ebooks, a shelf) stored by one book, a delete removes only the recorded file; other ebooks there stay. Before, it refused when the folder held several ebooks. Once two books store that folder, rule c keeps every recorded file there.prisma db push); existing rows read NULL. Each ebook import reads the placed file once more to hash it.media_dirare kept after the library moves; the ebook's own folder (custom template) is left empty after its only file goes.prisma db push --accept-data-lossdrops the column, so a later upgrade treats those requests as imported before the record (files kept).Release note
🤖 Generated with Claude Code