Apply minified serialization to books inside collections

The GET /api/libraries/:id/collections endpoint captured the minified
flag on the response payload but never passed it down to the book
serialization, so each book was always returned fully expanded with its
complete libraryFiles array and heavy media fields (audioFiles, chapters,
tracks). For libraries with multi-file audiobooks this produced responses
of tens of megabytes even when minified=1 was requested.

Thread the minified flag through getOldCollectionsJsonExpanded and
Collection.toOldJSONExpanded so that, when requested, books use the
existing library item minified form. Non-minified requests are unchanged.

Fixes #5170
This commit is contained in:
Conor Bronsdon 2026-07-09 02:59:25 -07:00
parent 6f03467f35
commit 42c6798981
3 changed files with 117 additions and 5 deletions

View file

@ -29,9 +29,10 @@ class Collection extends Model {
* @param {import('./User')} user
* @param {string} [libraryId]
* @param {string[]} [include]
* @param {boolean} [minified=false]
* @async
*/
static async getOldCollectionsJsonExpanded(user, libraryId, include) {
static async getOldCollectionsJsonExpanded(user, libraryId, include, minified = false) {
let collectionWhere = null
if (libraryId) {
collectionWhere = {
@ -98,7 +99,7 @@ class Collection extends Model {
this.books = books
const collectionExpanded = c.toOldJSONExpanded()
const collectionExpanded = c.toOldJSONExpanded(minified)
// Map feed if found
if (c.feeds?.length) {
@ -272,7 +273,11 @@ class Collection extends Model {
}
}
toOldJSONExpanded() {
/**
* @param {boolean} [minified=false] When true, books use the minified library item serialization
* (omits libraryFiles and heavy media fields like chapters/tracks/audioFiles)
*/
toOldJSONExpanded(minified = false) {
if (!this.books) {
throw new Error('Books are required to expand Collection')
}
@ -282,7 +287,7 @@ class Collection extends Model {
const libraryItem = book.libraryItem
delete book.libraryItem
libraryItem.media = book
return libraryItem.toOldJSONExpanded()
return minified ? libraryItem.toOldJSONMinified() : libraryItem.toOldJSONExpanded()
})
return json