Skip to content

Deleting the primary book format fails with 400 when other formats exist #2455

Description

@a10kiloham

What went wrong?

When a book has multiple formats (e.g. a PDF and an EPUB) and the PDF is the primary file, trying to delete the PDF from the book's "Delete format" dropdown fails with an error toast:

Primary book file cannot be processed as an additional file: 10153
Failed to delete book format: Http failure response for .../api/v1/books/9754/files/10153: 400 OK

The UI explicitly offers the primary file in the delete dropdown (labeled [Primary]) and BookFileService.deleteBookFile even contains cache logic to promote the next format to primary on success — but the backend rejects the request, so deleting a primary format is currently impossible without deleting the whole book.

How can we reproduce it?

  1. Have a book with two book formats, e.g. PDF (primary) and EPUB.
  2. Open the book's metadata view → the "..." menu → Delete format.
  3. Choose the file marked [Primary] and confirm.

What happened: HTTP 400, "Primary book file cannot be processed as an additional file".
What you expected: the PDF is deleted and the EPUB becomes the primary format.

Root cause (from reading the code)

DELETE /api/v1/books/{bookId}/files/{fileId} routes to AdditionalFileService.deleteAdditionalFile, which calls validateAdditionalFile — a guard added in #463 that throws for the primary file. That guard is correct for the download endpoint (the primary has its own download route), but applying it to delete broke the UI's delete-primary flow.

Notably, the primary file is derived, not stored: BookEntity.getPrimaryBookFile() picks by the library's format priority, falling back to lowest file id. So deleting the primary would automatically promote the next format — no promotion logic is needed. Only deleting the last book format needs to stay blocked (that should be a whole-book delete instead).

What Build of Grimmory are you on?

Stable

Your setup

  • Grimmory version: current develop (0e67549)
  • How you're running it: Docker
  • Browser: Chrome
  • Operating system: Linux

Before submitting

  • I've searched existing issues and discussions and this hasn't been reported yet
  • I've reviewed this report and have completed it as fully as I can

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions