mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 03:52:33 +02:00
Prevent adding a root folder that is the same as drone factory
This commit is contained in:
parent
e3916d5fc8
commit
485f05d4b9
@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using FluentValidation;
|
||||
using NLog;
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Extensions;
|
||||
using NzbDrone.Common.Exceptions;
|
||||
using HttpStatusCode = Nancy.HttpStatusCode;
|
||||
|
||||
namespace NzbDrone.Api.ErrorManagement
|
||||
{
|
||||
@ -31,14 +34,11 @@ public Response HandleException(NancyContext context, Exception exception)
|
||||
{
|
||||
_logger.Warn("Invalid request {0}", validationException.Message);
|
||||
|
||||
|
||||
return validationException.Errors.AsResponse(HttpStatusCode.BadRequest);
|
||||
|
||||
}
|
||||
|
||||
_logger.FatalException("Request Failed", exception);
|
||||
|
||||
|
||||
return new ErrorModel()
|
||||
{
|
||||
Message = exception.Message,
|
||||
|
@ -12,12 +12,10 @@ protected NzbDroneException(string message, params object[] args)
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected NzbDroneException(string message)
|
||||
: base(message)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,11 @@
|
||||
|
||||
namespace NzbDrone.Core.Configuration
|
||||
{
|
||||
public enum ConfigKey
|
||||
{
|
||||
DownloadedEpisodesFolder
|
||||
}
|
||||
|
||||
public class ConfigService : IConfigService
|
||||
{
|
||||
private readonly IConfigRepository _repository;
|
||||
@ -118,9 +123,9 @@ public SabPriorityType SabOlderTvPriority
|
||||
|
||||
public String DownloadedEpisodesFolder
|
||||
{
|
||||
get { return GetValue("DownloadedEpisodesFolder"); }
|
||||
get { return GetValue(ConfigKey.DownloadedEpisodesFolder.ToString()); }
|
||||
|
||||
set { SetValue("DownloadedEpisodesFolder", value); }
|
||||
set { SetValue(ConfigKey.DownloadedEpisodesFolder.ToString(), value); }
|
||||
}
|
||||
|
||||
public bool UseSeasonFolder
|
||||
@ -136,7 +141,6 @@ public string SeasonFolderFormat
|
||||
set { SetValue("SeasonFolderFormat", value); }
|
||||
}
|
||||
|
||||
|
||||
public bool AutoUnmonitorPreviouslyDownloadedEpisodes
|
||||
{
|
||||
get { return GetValueBoolean("AutoUnmonitorPreviouslyDownloadedEpisodes"); }
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
@ -26,12 +27,17 @@ public class RootFolderService : IRootFolderService
|
||||
private readonly IBasicRepository<RootFolder> _rootFolderRepository;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
public RootFolderService(IBasicRepository<RootFolder> rootFolderRepository, IDiskProvider diskProvider,ISeriesRepository seriesRepository)
|
||||
public RootFolderService(IBasicRepository<RootFolder> rootFolderRepository,
|
||||
IDiskProvider diskProvider,
|
||||
ISeriesRepository seriesRepository,
|
||||
IConfigService configService)
|
||||
{
|
||||
_rootFolderRepository = rootFolderRepository;
|
||||
_diskProvider = diskProvider;
|
||||
_seriesRepository = seriesRepository;
|
||||
_configService = configService;
|
||||
}
|
||||
|
||||
public virtual List<RootFolder> All()
|
||||
@ -66,7 +72,10 @@ public virtual RootFolder Add(RootFolder rootFolder)
|
||||
throw new DirectoryNotFoundException("Can't add root directory that doesn't exist.");
|
||||
|
||||
if (All().Exists(r => DiskProvider.PathEquals(r.Path, rootFolder.Path)))
|
||||
throw new InvalidOperationException("Root directory already exist.");
|
||||
throw new InvalidOperationException("Recent directory already exist.");
|
||||
|
||||
if (DiskProvider.PathEquals(_configService.DownloadedEpisodesFolder, rootFolder.Path))
|
||||
throw new InvalidOperationException("Drone Factory folder cannot be used.");
|
||||
|
||||
_rootFolderRepository.Insert(rootFolder);
|
||||
|
||||
|
@ -10,11 +10,11 @@ public interface ISeriesRepository : IBasicRepository<Series>
|
||||
{
|
||||
bool SeriesPathExists(string path);
|
||||
List<Series> Search(string title);
|
||||
|
||||
Series FindByTitle(string cleanTitle);
|
||||
Series FindByTvdbId(int tvdbId);
|
||||
void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
|
||||
Series FindBySlug(string slug);
|
||||
List<String> GetSeriesPaths();
|
||||
}
|
||||
|
||||
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
|
||||
@ -53,5 +53,10 @@ public Series FindBySlug(string slug)
|
||||
{
|
||||
return Query.SingleOrDefault(c => c.TitleSlug == slug.ToLower());
|
||||
}
|
||||
|
||||
public List<string> GetSeriesPaths()
|
||||
{
|
||||
return Query.Select(s => s.Path).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ public interface ISeriesService
|
||||
bool SeriesPathExists(string folder);
|
||||
List<Series> GetSeriesInList(IEnumerable<int> seriesIds);
|
||||
Series FindBySlug(string slug);
|
||||
List<String> GetSeriesPaths();
|
||||
}
|
||||
|
||||
public class SeriesService : ISeriesService
|
||||
@ -112,6 +113,11 @@ public Series FindBySlug(string slug)
|
||||
return series;
|
||||
}
|
||||
|
||||
public List<string> GetSeriesPaths()
|
||||
{
|
||||
return _seriesRepository.GetSeriesPaths();
|
||||
}
|
||||
|
||||
public Series FindByTitle(string title)
|
||||
{
|
||||
var tvdbId = _sceneMappingService.GetTvDbId(title);
|
||||
|
Loading…
Reference in New Issue
Block a user