From f49388f3c4e78f776a729285050e4c46c79735ff 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 Artist Closes #5041 --- src/Lidarr.Api.V1/Artist/ArtistController.cs | 4 ++++ .../Validation/Paths/RootFolderExistsValidator.cs | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Lidarr.Api.V1/Artist/ArtistController.cs b/src/Lidarr.Api.V1/Artist/ArtistController.cs index e5829ff96..b31698541 100644 --- a/src/Lidarr.Api.V1/Artist/ArtistController.cs +++ b/src/Lidarr.Api.V1/Artist/ArtistController.cs @@ -63,6 +63,7 @@ public ArtistController(IBroadcastSignalRMessage signalRBroadcaster, SystemFolderValidator systemFolderValidator, QualityProfileExistsValidator qualityProfileExistsValidator, MetadataProfileExistsValidator metadataProfileExistsValidator, + RootFolderExistsValidator rootFolderExistsValidator, ArtistFolderAsRootFolderValidator artistFolderAsRootFolderValidator) : base(signalRBroadcaster) { @@ -95,6 +96,7 @@ public ArtistController(IBroadcastSignalRMessage signalRBroadcaster, PostValidator.RuleFor(s => s.Path).IsValidPath().When(s => s.RootFolderPath.IsNullOrWhiteSpace()); PostValidator.RuleFor(s => s.RootFolderPath) .IsValidPath() + .SetValidator(rootFolderExistsValidator) .SetValidator(artistFolderAsRootFolderValidator) .When(s => s.Path.IsNullOrWhiteSpace()); PostValidator.RuleFor(s => s.ArtistName).NotEmpty(); @@ -154,6 +156,7 @@ public List AllArtists(Guid? mbId) [RestPostById] [Consumes("application/json")] + [Produces("application/json")] public ActionResult AddArtist(ArtistResource artistResource) { var artist = _addArtistService.AddArtist(artistResource.ToModel()); @@ -163,6 +166,7 @@ public ActionResult AddArtist(ArtistResource artistResource) [RestPutById] [Consumes("application/json")] + [Produces("application/json")] public ActionResult UpdateArtist(ArtistResource artistResource, bool moveFiles = false) { var artist = _artistService.GetArtist(artistResource.Id); 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 @@ protected override bool IsValid(PropertyValidatorContext context) { 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())); } } }