Add all minified fields to expanded library item JSON so socket updates remain a strict superset of shelf payloads

This commit is contained in:
mikiher 2026-07-01 22:30:21 +03:00
parent 6f03467f35
commit 3bb53d939d
4 changed files with 196 additions and 36 deletions

View file

@ -647,6 +647,11 @@ class Book extends Model {
}
}
/**
* Minified book JSON for list/shelf endpoints.
* `toOldJSONExpanded()` must be a strict superset: every key here must exist in expanded
* with the same value semantics. Only additive changes to expanded; never remove or rename keys.
*/
toOldJSONMinified() {
if (!this.authors) {
throw new Error(`[Book] Cannot convert to old JSON because authors are not loaded`)
@ -669,6 +674,12 @@ class Book extends Model {
}
}
/**
* Expanded book JSON for item detail and socket events.
* Must be a strict superset of `toOldJSONMinified()` built by spreading minified, then adding expanded-only fields.
*
* @param {string} libraryItemId
*/
toOldJSONExpanded(libraryItemId) {
if (!libraryItemId) {
throw new Error(`[Book] Cannot convert to old JSON because libraryItemId is not provided`)
@ -681,16 +692,12 @@ class Book extends Model {
}
return {
id: this.id,
libraryItemId: libraryItemId,
...this.toOldJSONMinified(),
libraryItemId,
metadata: this.oldMetadataToJSONExpanded(),
coverPath: this.coverPath,
tags: [...(this.tags || [])],
audioFiles: structuredClone(this.audioFiles),
chapters: structuredClone(this.chapters),
ebookFile: structuredClone(this.ebookFile),
duration: this.duration,
size: this.size,
tracks: this.getTracklist(libraryItemId)
}
}