mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-15 09:42:25 +02:00
Update:batchUpdate endpoint validate req.body is an array of objects
This commit is contained in:
@ -539,12 +539,13 @@ class LibraryItemController {
|
|||||||
*/
|
*/
|
||||||
async batchUpdate(req, res) {
|
async batchUpdate(req, res) {
|
||||||
const updatePayloads = req.body
|
const updatePayloads = req.body
|
||||||
if (!updatePayloads?.length) {
|
if (!Array.isArray(updatePayloads) || !updatePayloads.length) {
|
||||||
return res.sendStatus(500)
|
Logger.error(`[LibraryItemController] Batch update failed. Invalid payload`)
|
||||||
|
return res.sendStatus(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that each update payload has a unique library item id
|
// Ensure that each update payload has a unique library item id
|
||||||
const libraryItemIds = [...new Set(updatePayloads.map((up) => up.id))]
|
const libraryItemIds = [...new Set(updatePayloads.map((up) => up?.id).filter((id) => id))]
|
||||||
if (!libraryItemIds.length || libraryItemIds.length !== updatePayloads.length) {
|
if (!libraryItemIds.length || libraryItemIds.length !== updatePayloads.length) {
|
||||||
Logger.error(`[LibraryItemController] Batch update failed. Each update payload must have a unique library item id`)
|
Logger.error(`[LibraryItemController] Batch update failed. Each update payload must have a unique library item id`)
|
||||||
return res.sendStatus(400)
|
return res.sendStatus(400)
|
||||||
|
Reference in New Issue
Block a user