1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-28 08:58:41 +02:00

Fixed: Ensure Root Folder exists when Adding Series

This commit is contained in:
Bogdan 2024-08-26 03:23:24 +03:00 committed by GitHub
parent 8af4246ff9
commit 8ceb306bf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 7 deletions

View File

@ -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()));
}
}
}

View File

@ -59,6 +59,7 @@ public SeriesController(IBroadcastSignalRMessage signalRBroadcaster,
SeriesAncestorValidator seriesAncestorValidator,
SystemFolderValidator systemFolderValidator,
QualityProfileExistsValidator qualityProfileExistsValidator,
RootFolderExistsValidator rootFolderExistsValidator,
SeriesFolderAsRootFolderValidator seriesFolderAsRootFolderValidator)
: base(signalRBroadcaster)
{
@ -88,6 +89,7 @@ public SeriesController(IBroadcastSignalRMessage signalRBroadcaster,
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 @@ private SeriesResource GetSeriesResourceById(int id, bool includeSeasonImages =
[RestPostById]
[Consumes("application/json")]
[Produces("application/json")]
public ActionResult<SeriesResource> AddSeries([FromBody] SeriesResource seriesResource)
{
var series = _addSeriesService.AddSeries(seriesResource.ToModel());
@ -165,6 +168,7 @@ public ActionResult<SeriesResource> AddSeries([FromBody] SeriesResource seriesRe
[RestPutById]
[Consumes("application/json")]
[Produces("application/json")]
public ActionResult<SeriesResource> UpdateSeries([FromBody] SeriesResource seriesResource, [FromQuery] bool moveFiles = false)
{
var series = _seriesService.GetSeries(seriesResource.Id);
@ -175,12 +179,12 @@ public ActionResult<SeriesResource> UpdateSeries([FromBody] SeriesResource serie
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);