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

@ -1407,6 +1407,39 @@ class LibraryController {
})
}
/**
* POST: /api/libraries/:id/update-cover-dimensions
* Recompute cover dimensions for all items in library
*
* @param {LibraryControllerRequest} req
* @param {Response} res
*/
async updateCoverDimensions(req, res) {
if (!req.user.isAdminOrUp) {
Logger.error(`[LibraryController] Non-admin user "${req.user.username}" attempted to update cover dimensions`)
return res.sendStatus(403)
}
const items = await Database.libraryItemModel.findAllExpandedWhere({
libraryId: req.library.id
})
let updatedCount = 0
for (const item of items) {
if (item.media?.coverPath) {
// Force coverPath to be seen as changed to trigger beforeSave hook
item.media.changed('coverPath', true)
await item.media.save()
updatedCount++
}
}
Logger.info(`[LibraryController] Updated cover dimensions for ${updatedCount} items in library "${req.library.name}"`)
res.json({
updated: updatedCount
})
}
/**
* GET: /api/libraries/:id/podcast-titles
*

View file

@ -601,6 +601,8 @@ class LibraryItemController {
}
req.libraryItem.media.coverPath = result.cover
req.libraryItem.media.coverWidth = result.width
req.libraryItem.media.coverHeight = result.height
req.libraryItem.media.changed('coverPath', true)
await req.libraryItem.media.save()
@ -634,6 +636,8 @@ class LibraryItemController {
}
if (validationResult.updated) {
req.libraryItem.media.coverPath = validationResult.cover
req.libraryItem.media.coverWidth = validationResult.width
req.libraryItem.media.coverHeight = validationResult.height
req.libraryItem.media.changed('coverPath', true)
await req.libraryItem.media.save()