Fixed: RootFolderPath not set for Movies from API

pull/8462/head
Qstick 2 years ago
parent ff1449c01e
commit 850fef5c43

@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
.Returns((string path) => Directory.GetParent(path).FullName); .Returns((string path) => Directory.GetParent(path).FullName);
Mocker.GetMock<IRootFolderService>() Mocker.GetMock<IRootFolderService>()
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>())) .Setup(s => s.GetBestRootFolderPath(It.IsAny<string>(), null))
.Returns(_rootFolder); .Returns(_rootFolder);
Mocker.GetMock<IMediaFileService>() Mocker.GetMock<IMediaFileService>()

@ -57,7 +57,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieFileMovingServiceTests
.Returns(true); .Returns(true);
Mocker.GetMock<IRootFolderService>() Mocker.GetMock<IRootFolderService>()
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>())) .Setup(s => s.GetBestRootFolderPath(It.IsAny<string>(), null))
.Returns(rootFolder); .Returns(rootFolder);
} }

@ -1,4 +1,4 @@
using System.IO; using System.IO;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.MovieTests
public void GivenExistingRootFolder(string rootFolder) public void GivenExistingRootFolder(string rootFolder)
{ {
Mocker.GetMock<IRootFolderService>() Mocker.GetMock<IRootFolderService>()
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>())) .Setup(s => s.GetBestRootFolderPath(It.IsAny<string>(), null))
.Returns(rootFolder); .Returns(rootFolder);
} }

@ -55,7 +55,7 @@ namespace NzbDrone.Core.Test.MovieTests
.Callback<int>((i) => { throw new MovieNotFoundException(i); }); .Callback<int>((i) => { throw new MovieNotFoundException(i); });
Mocker.GetMock<IRootFolderService>() Mocker.GetMock<IRootFolderService>()
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>())) .Setup(s => s.GetBestRootFolderPath(It.IsAny<string>(), null))
.Returns(string.Empty); .Returns(string.Empty);
} }

@ -19,7 +19,7 @@ namespace NzbDrone.Core.RootFolders
RootFolder Add(RootFolder rootDir); RootFolder Add(RootFolder rootDir);
void Remove(int id); void Remove(int id);
RootFolder Get(int id, bool timeout); RootFolder Get(int id, bool timeout);
string GetBestRootFolderPath(string path); string GetBestRootFolderPath(string path, List<RootFolder> rootFolders = null);
} }
public class RootFolderService : IRootFolderService public class RootFolderService : IRootFolderService
@ -180,9 +180,11 @@ namespace NzbDrone.Core.RootFolders
return rootFolder; return rootFolder;
} }
public string GetBestRootFolderPath(string path) public string GetBestRootFolderPath(string path, List<RootFolder> rootFolders = null)
{ {
var possibleRootFolder = All().Where(r => r.Path.IsParentPath(path)).MaxBy(r => r.Path.Length); var allRootFoldersToConsider = rootFolders ?? All();
var possibleRootFolder = allRootFoldersToConsider.Where(r => r.Path.IsParentPath(path)).MaxBy(r => r.Path.Length);
if (possibleRootFolder == null) if (possibleRootFolder == null)
{ {

@ -20,6 +20,7 @@ using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Commands; using NzbDrone.Core.Movies.Commands;
using NzbDrone.Core.Movies.Events; using NzbDrone.Core.Movies.Events;
using NzbDrone.Core.Movies.Translations; using NzbDrone.Core.Movies.Translations;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
using NzbDrone.Core.Validation.Paths; using NzbDrone.Core.Validation.Paths;
using NzbDrone.SignalR; using NzbDrone.SignalR;
@ -45,6 +46,7 @@ namespace Radarr.Api.V3.Movies
private readonly IAddMovieService _addMovieService; private readonly IAddMovieService _addMovieService;
private readonly IMapCoversToLocal _coverMapper; private readonly IMapCoversToLocal _coverMapper;
private readonly IManageCommandQueue _commandQueueManager; private readonly IManageCommandQueue _commandQueueManager;
private readonly IRootFolderService _rootFolderService;
private readonly IUpgradableSpecification _qualityUpgradableSpecification; private readonly IUpgradableSpecification _qualityUpgradableSpecification;
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly Logger _logger; private readonly Logger _logger;
@ -55,6 +57,7 @@ namespace Radarr.Api.V3.Movies
IAddMovieService addMovieService, IAddMovieService addMovieService,
IMapCoversToLocal coverMapper, IMapCoversToLocal coverMapper,
IManageCommandQueue commandQueueManager, IManageCommandQueue commandQueueManager,
IRootFolderService rootFolderService,
IUpgradableSpecification qualityUpgradableSpecification, IUpgradableSpecification qualityUpgradableSpecification,
IConfigService configService, IConfigService configService,
RootFolderValidator rootFolderValidator, RootFolderValidator rootFolderValidator,
@ -76,6 +79,7 @@ namespace Radarr.Api.V3.Movies
_configService = configService; _configService = configService;
_coverMapper = coverMapper; _coverMapper = coverMapper;
_commandQueueManager = commandQueueManager; _commandQueueManager = commandQueueManager;
_rootFolderService = rootFolderService;
_logger = logger; _logger = logger;
SharedValidator.RuleFor(s => s.QualityProfileId).ValidId(); SharedValidator.RuleFor(s => s.QualityProfileId).ValidId();
@ -145,6 +149,10 @@ namespace Radarr.Api.V3.Movies
} }
MapCoversToLocal(moviesResources, coverFileInfos); MapCoversToLocal(moviesResources, coverFileInfos);
var rootFolders = _rootFolderService.All();
moviesResources.ForEach(m => m.RootFolderPath = _rootFolderService.GetBestRootFolderPath(m.Path, rootFolders));
} }
return moviesResources; return moviesResources;
@ -171,6 +179,8 @@ namespace Radarr.Api.V3.Movies
var resource = movie.ToResource(availDelay, translation, _qualityUpgradableSpecification); var resource = movie.ToResource(availDelay, translation, _qualityUpgradableSpecification);
MapCoversToLocal(resource); MapCoversToLocal(resource);
resource.RootFolderPath = _rootFolderService.GetBestRootFolderPath(resource.Path);
return resource; return resource;
} }

Loading…
Cancel
Save