feat: implement server-side cover dimension detection and update badge thresholds

This commit is contained in:
Tiberiu Ichim 2026-02-17 19:30:48 +02:00
parent 5bf60d5ae3
commit d0c09d04f1
16 changed files with 353 additions and 10 deletions

View file

@ -164,7 +164,9 @@ class Book extends Model {
ebookFile: DataTypes.JSON,
chapters: DataTypes.JSON,
tags: DataTypes.JSON,
genres: DataTypes.JSON
genres: DataTypes.JSON,
coverWidth: DataTypes.INTEGER,
coverHeight: DataTypes.INTEGER
},
{
sequelize,
@ -201,6 +203,20 @@ class Book extends Model {
Book.addHook('afterCreate', async (instance) => {
libraryItemsBookFilters.clearCountCache('afterCreate')
})
Book.addHook('beforeSave', async (instance) => {
if (instance.changed('coverPath') && instance.coverPath) {
const { getImageDimensions } = require('../utils/ffmpegHelpers')
const dims = await getImageDimensions(instance.coverPath)
if (dims) {
instance.coverWidth = dims.width
instance.coverHeight = dims.height
} else {
instance.coverWidth = null
instance.coverHeight = null
}
}
})
}
/**
@ -629,6 +645,8 @@ class Book extends Model {
libraryItemId: libraryItemId,
metadata: this.oldMetadataToJSON(),
coverPath: this.coverPath,
coverWidth: this.coverWidth,
coverHeight: this.coverHeight,
tags: [...(this.tags || [])],
audioFiles: structuredClone(this.audioFiles),
chapters: structuredClone(this.chapters),
@ -648,6 +666,8 @@ class Book extends Model {
id: this.id,
metadata: this.oldMetadataToJSONMinified(),
coverPath: this.coverPath,
coverWidth: this.coverWidth,
coverHeight: this.coverHeight,
tags: [...(this.tags || [])],
numTracks: this.includedAudioFiles.length,
numAudioFiles: this.audioFiles?.length || 0,
@ -674,6 +694,8 @@ class Book extends Model {
libraryItemId: libraryItemId,
metadata: this.oldMetadataToJSONExpanded(),
coverPath: this.coverPath,
coverWidth: this.coverWidth,
coverHeight: this.coverHeight,
tags: [...(this.tags || [])],
audioFiles: structuredClone(this.audioFiles),
chapters: structuredClone(this.chapters),