Skip to content

Commit

Permalink
Fix create library with mark media as finished when setting #3856
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Jan 18, 2025
1 parent ebaae98 commit 4a3254d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions server/controllers/LibraryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`)
Expand Down Expand Up @@ -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') {
Expand All @@ -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 {
Expand Down

0 comments on commit 4a3254d

Please sign in to comment.