mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-30 11:48:26 -07:00
New: Indexer Setting for absolute maximum size for a release
This commit is contained in:
parent
96c59e2b2b
commit
d9a8a92b8e
9 changed files with 158 additions and 3 deletions
|
@ -47,6 +47,18 @@ function IndexerOptions(props) {
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
|
<FormGroup>
|
||||||
|
<FormLabel>Maximum Size</FormLabel>
|
||||||
|
|
||||||
|
<FormInputGroup
|
||||||
|
type={inputTypes.NUMBER}
|
||||||
|
name="maximumSize"
|
||||||
|
helpText="Maximum size for a release to be grabbed in MB. Set to zero to set to unlimited."
|
||||||
|
onChange={onInputChange}
|
||||||
|
{...settings.maximumSize}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<FormLabel>Retention</FormLabel>
|
<FormLabel>Retention</FormLabel>
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using Lidarr.Http.Validation;
|
using Lidarr.Http.Validation;
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ namespace Lidarr.Api.V1.Config
|
||||||
SharedValidator.RuleFor(c => c.MinimumAge)
|
SharedValidator.RuleFor(c => c.MinimumAge)
|
||||||
.GreaterThanOrEqualTo(0);
|
.GreaterThanOrEqualTo(0);
|
||||||
|
|
||||||
|
SharedValidator.RuleFor(c => c.MaximumSize)
|
||||||
|
.GreaterThanOrEqualTo(0);
|
||||||
|
|
||||||
SharedValidator.RuleFor(c => c.Retention)
|
SharedValidator.RuleFor(c => c.Retention)
|
||||||
.GreaterThanOrEqualTo(0);
|
.GreaterThanOrEqualTo(0);
|
||||||
|
|
||||||
|
@ -25,4 +28,4 @@ namespace Lidarr.Api.V1.Config
|
||||||
return IndexerConfigResourceMapper.ToResource(model);
|
return IndexerConfigResourceMapper.ToResource(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using Lidarr.Http.REST;
|
using Lidarr.Http.REST;
|
||||||
|
|
||||||
namespace Lidarr.Api.V1.Config
|
namespace Lidarr.Api.V1.Config
|
||||||
|
@ -6,6 +6,7 @@ namespace Lidarr.Api.V1.Config
|
||||||
public class IndexerConfigResource : RestResource
|
public class IndexerConfigResource : RestResource
|
||||||
{
|
{
|
||||||
public int MinimumAge { get; set; }
|
public int MinimumAge { get; set; }
|
||||||
|
public int MaximumSize { get; set; }
|
||||||
public int Retention { get; set; }
|
public int Retention { get; set; }
|
||||||
public int RssSyncInterval { get; set; }
|
public int RssSyncInterval { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -17,6 +18,7 @@ namespace Lidarr.Api.V1.Config
|
||||||
return new IndexerConfigResource
|
return new IndexerConfigResource
|
||||||
{
|
{
|
||||||
MinimumAge = model.MinimumAge,
|
MinimumAge = model.MinimumAge,
|
||||||
|
MaximumSize = model.MaximumSize,
|
||||||
Retention = model.Retention,
|
Retention = model.Retention,
|
||||||
RssSyncInterval = model.RssSyncInterval,
|
RssSyncInterval = model.RssSyncInterval,
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||||
|
{
|
||||||
|
public class MaximumSizeSpecificationFixture : CoreTest<MaximumSizeSpecification>
|
||||||
|
{
|
||||||
|
private RemoteAlbum _remoteAlbum;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_remoteAlbum = new RemoteAlbum() { Release = new ReleaseInfo() };
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithMaximumSize(int size)
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.MaximumSize).Returns(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithSize(int size)
|
||||||
|
{
|
||||||
|
_remoteAlbum.Release.Size = size * 1024 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_when_maximum_size_is_set_to_zero()
|
||||||
|
{
|
||||||
|
WithMaximumSize(0);
|
||||||
|
WithSize(1000);
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_when_size_is_smaller_than_maximum_size()
|
||||||
|
{
|
||||||
|
WithMaximumSize(2000);
|
||||||
|
WithSize(1999);
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_when_size_is_equals_to_maximum_size()
|
||||||
|
{
|
||||||
|
WithMaximumSize(2000);
|
||||||
|
WithSize(2000);
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_false_when_size_is_bigger_than_maximum_size()
|
||||||
|
{
|
||||||
|
WithMaximumSize(2000);
|
||||||
|
WithSize(2001);
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_when_size_is_zero()
|
||||||
|
{
|
||||||
|
WithMaximumSize(2000);
|
||||||
|
WithSize(0);
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_remoteAlbum, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -118,6 +118,7 @@
|
||||||
<Compile Include="Datastore\SqliteSchemaDumperTests\SqliteSchemaDumperFixture.cs" />
|
<Compile Include="Datastore\SqliteSchemaDumperTests\SqliteSchemaDumperFixture.cs" />
|
||||||
<Compile Include="DecisionEngineTests\AcceptableSizeSpecificationFixture.cs" />
|
<Compile Include="DecisionEngineTests\AcceptableSizeSpecificationFixture.cs" />
|
||||||
<Compile Include="DecisionEngineTests\BlockedIndexerSpecificationFixture.cs" />
|
<Compile Include="DecisionEngineTests\BlockedIndexerSpecificationFixture.cs" />
|
||||||
|
<Compile Include="DecisionEngineTests\MaximumSizeSpecificationFixture.cs" />
|
||||||
<Compile Include="DecisionEngineTests\ProtocolSpecificationFixture.cs" />
|
<Compile Include="DecisionEngineTests\ProtocolSpecificationFixture.cs" />
|
||||||
<Compile Include="DecisionEngineTests\CutoffSpecificationFixture.cs" />
|
<Compile Include="DecisionEngineTests\CutoffSpecificationFixture.cs" />
|
||||||
<Compile Include="DecisionEngineTests\DownloadDecisionMakerFixture.cs" />
|
<Compile Include="DecisionEngineTests\DownloadDecisionMakerFixture.cs" />
|
||||||
|
|
|
@ -99,6 +99,13 @@ namespace NzbDrone.Core.Configuration
|
||||||
set { SetValue("RssSyncInterval", value); }
|
set { SetValue("RssSyncInterval", value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int MaximumSize
|
||||||
|
{
|
||||||
|
get { return GetValueInt("MaximumSize", 0);}
|
||||||
|
|
||||||
|
set { SetValue("MaximumSize", value);}
|
||||||
|
}
|
||||||
|
|
||||||
public int MinimumAge
|
public int MinimumAge
|
||||||
{
|
{
|
||||||
get { return GetValueInt("MinimumAge", 0); }
|
get { return GetValueInt("MinimumAge", 0); }
|
||||||
|
|
|
@ -43,6 +43,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
//Indexers
|
//Indexers
|
||||||
int Retention { get; set; }
|
int Retention { get; set; }
|
||||||
int RssSyncInterval { get; set; }
|
int RssSyncInterval { get; set; }
|
||||||
|
int MaximumSize { get; set; }
|
||||||
int MinimumAge { get; set; }
|
int MinimumAge { get; set; }
|
||||||
|
|
||||||
//UI
|
//UI
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||||
|
{
|
||||||
|
public class MaximumSizeSpecification : IDecisionEngineSpecification
|
||||||
|
{
|
||||||
|
private readonly IConfigService _configService;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public MaximumSizeSpecification(IConfigService configService, Logger logger)
|
||||||
|
{
|
||||||
|
_configService = configService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpecificationPriority Priority => SpecificationPriority.Default;
|
||||||
|
public RejectionType Type => RejectionType.Permanent;
|
||||||
|
|
||||||
|
public Decision IsSatisfiedBy(RemoteAlbum subject, SearchCriteriaBase searchCriteria)
|
||||||
|
{
|
||||||
|
var size = subject.Release.Size;
|
||||||
|
var maximumSize = _configService.MaximumSize.Megabytes();
|
||||||
|
|
||||||
|
if (maximumSize == 0)
|
||||||
|
{
|
||||||
|
_logger.Debug("Maximum size is not set.");
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subject.Release.Size == 0)
|
||||||
|
{
|
||||||
|
_logger.Debug("Release has unknown size, skipping size check.");
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug("Checking if release meets maximum size requirements. {0}", size.SizeSuffix());
|
||||||
|
|
||||||
|
if (size > maximumSize)
|
||||||
|
{
|
||||||
|
var message = $"{size.SizeSuffix()} is too big, maximum size is {maximumSize.SizeSuffix()}";
|
||||||
|
|
||||||
|
_logger.Debug(message);
|
||||||
|
return Decision.Reject(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -212,6 +212,7 @@
|
||||||
<Compile Include="DecisionEngine\Specifications\BlockedIndexerSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\BlockedIndexerSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\DiscographySpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\DiscographySpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\CutoffSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\CutoffSpecification.cs" />
|
||||||
|
<Compile Include="DecisionEngine\Specifications\MaximumSizeSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\ProtocolSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\ProtocolSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\LanguageSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\LanguageSpecification.cs" />
|
||||||
<Compile Include="DecisionEngine\Specifications\QueueSpecification.cs" />
|
<Compile Include="DecisionEngine\Specifications\QueueSpecification.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue