From 8ceb306bf181665ba6a57182f6852bddf8671124 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 26 Aug 2024 03:23:24 +0300 Subject: [PATCH] Fixed: Ensure Root Folder exists when Adding Series --- .../Paths/RootFolderExistsValidator.cs | 3 ++- src/Sonarr.Api.V3/Series/SeriesController.cs | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/NzbDrone.Core/Validation/Paths/RootFolderExistsValidator.cs b/src/NzbDrone.Core/Validation/Paths/RootFolderExistsValidator.cs index 8b4c4e7a0..d879af0d9 100644 --- a/src/NzbDrone.Core/Validation/Paths/RootFolderExistsValidator.cs +++ b/src/NzbDrone.Core/Validation/Paths/RootFolderExistsValidator.cs @@ -1,4 +1,5 @@ using FluentValidation.Validators; +using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Core.RootFolders; @@ -19,7 +20,7 @@ namespace NzbDrone.Core.Validation.Paths { context.MessageFormatter.AppendArgument("path", context.PropertyValue?.ToString()); - return context.PropertyValue == null || _rootFolderService.All().Exists(r => r.Path.PathEquals(context.PropertyValue.ToString())); + return context.PropertyValue == null || _rootFolderService.All().Exists(r => r.Path.IsPathValid(PathValidationType.CurrentOs) && r.Path.PathEquals(context.PropertyValue.ToString())); } } } diff --git a/src/Sonarr.Api.V3/Series/SeriesController.cs b/src/Sonarr.Api.V3/Series/SeriesController.cs index 57ff76bc4..48d377e40 100644 --- a/src/Sonarr.Api.V3/Series/SeriesController.cs +++ b/src/Sonarr.Api.V3/Series/SeriesController.cs @@ -59,6 +59,7 @@ namespace Sonarr.Api.V3.Series SeriesAncestorValidator seriesAncestorValidator, SystemFolderValidator systemFolderValidator, QualityProfileExistsValidator qualityProfileExistsValidator, + RootFolderExistsValidator rootFolderExistsValidator, SeriesFolderAsRootFolderValidator seriesFolderAsRootFolderValidator) : base(signalRBroadcaster) { @@ -88,6 +89,7 @@ namespace Sonarr.Api.V3.Series PostValidator.RuleFor(s => s.Path).IsValidPath().When(s => s.RootFolderPath.IsNullOrWhiteSpace()); PostValidator.RuleFor(s => s.RootFolderPath) .IsValidPath() + .SetValidator(rootFolderExistsValidator) .SetValidator(seriesFolderAsRootFolderValidator) .When(s => s.Path.IsNullOrWhiteSpace()); PostValidator.RuleFor(s => s.Title).NotEmpty(); @@ -156,6 +158,7 @@ namespace Sonarr.Api.V3.Series [RestPostById] [Consumes("application/json")] + [Produces("application/json")] public ActionResult AddSeries([FromBody] SeriesResource seriesResource) { var series = _addSeriesService.AddSeries(seriesResource.ToModel()); @@ -165,6 +168,7 @@ namespace Sonarr.Api.V3.Series [RestPutById] [Consumes("application/json")] + [Produces("application/json")] public ActionResult UpdateSeries([FromBody] SeriesResource seriesResource, [FromQuery] bool moveFiles = false) { var series = _seriesService.GetSeries(seriesResource.Id); @@ -175,12 +179,12 @@ namespace Sonarr.Api.V3.Series var destinationPath = seriesResource.Path; _commandQueueManager.Push(new MoveSeriesCommand - { - SeriesId = series.Id, - SourcePath = sourcePath, - DestinationPath = destinationPath, - Trigger = CommandTrigger.Manual - }); + { + SeriesId = series.Id, + SourcePath = sourcePath, + DestinationPath = destinationPath, + Trigger = CommandTrigger.Manual + }); } var model = seriesResource.ToModel(series);