From 4a3254d33885a20c6de42845b116f9090ec976ee Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 18 Jan 2025 15:57:44 -0600 Subject: [PATCH] Fix create library with mark media as finished when setting #3856 --- server/controllers/LibraryController.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index d73b92d234..0ece483f8b 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -100,6 +100,15 @@ class LibraryController { return res.status(400).send(`Invalid request. Settings "${key}" must be a string`) } newLibraryPayload.settings[key] = req.body.settings[key] + } else if (key === 'markAsFinishedPercentComplete' || key === 'markAsFinishedTimeRemaining') { + if (req.body.settings[key] !== null && isNaN(req.body.settings[key])) { + return res.status(400).send(`Invalid request. Setting "${key}" must be a number`) + } else if (key === 'markAsFinishedPercentComplete' && req.body.settings[key] !== null && (Number(req.body.settings[key]) < 0 || Number(req.body.settings[key]) > 100)) { + return res.status(400).send(`Invalid request. Setting "${key}" must be between 0 and 100`) + } else if (key === 'markAsFinishedTimeRemaining' && req.body.settings[key] !== null && Number(req.body.settings[key]) < 0) { + return res.status(400).send(`Invalid request. Setting "${key}" must be greater than or equal to 0`) + } + newLibraryPayload.settings[key] = req.body.settings[key] === null ? null : Number(req.body.settings[key]) } else { if (typeof req.body.settings[key] !== typeof newLibraryPayload.settings[key]) { return res.status(400).send(`Invalid request. Setting "${key}" must be of type ${typeof newLibraryPayload.settings[key]}`) @@ -325,7 +334,7 @@ class LibraryController { } if (req.body.settings[key] !== updatedSettings[key]) { hasUpdates = true - updatedSettings[key] = Number(req.body.settings[key]) + updatedSettings[key] = req.body.settings[key] === null ? null : Number(req.body.settings[key]) Logger.debug(`[LibraryController] Library "${req.library.name}" updating setting "${key}" to "${updatedSettings[key]}"`) } } else if (key === 'markAsFinishedTimeRemaining') { @@ -338,7 +347,7 @@ class LibraryController { } if (req.body.settings[key] !== updatedSettings[key]) { hasUpdates = true - updatedSettings[key] = Number(req.body.settings[key]) + updatedSettings[key] = req.body.settings[key] === null ? null : Number(req.body.settings[key]) Logger.debug(`[LibraryController] Library "${req.library.name}" updating setting "${key}" to "${updatedSettings[key]}"`) } } else {