mirror of
https://github.com/Jackett/Jackett
synced 2025-03-03 10:26:05 +00:00
api: filter indexers by state
This commit is contained in:
parent
d8b8128cf8
commit
1b96a009c4
3 changed files with 52 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using Jackett.Common.Extensions;
|
||||
using Jackett.Common.Indexers;
|
||||
|
||||
namespace Jackett.Common.Models.DTO
|
||||
|
@ -40,6 +41,9 @@ namespace Jackett.Common.Models.DTO
|
|||
[DataMember]
|
||||
public bool potatoenabled { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public IndexerState state => last_error.IsNotNullOrWhiteSpace() ? IndexerState.Error : IndexerState.Success;
|
||||
|
||||
[DataMember]
|
||||
public IEnumerable<Capability> caps { get; private set; }
|
||||
|
||||
|
@ -67,4 +71,12 @@ namespace Jackett.Common.Models.DTO
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public enum IndexerState
|
||||
{
|
||||
Unknown,
|
||||
Error,
|
||||
Success
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using Jackett.Common.Indexers;
|
||||
using Jackett.Common.Models;
|
||||
using Jackett.Common.Models.DTO;
|
||||
using Jackett.Common.Services.Interfaces;
|
||||
using Jackett.Common.Utils;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -105,19 +106,36 @@ namespace Jackett.Server.Controllers
|
|||
}
|
||||
catch
|
||||
{
|
||||
var baseIndexer = CurrentIndexer as BaseIndexer;
|
||||
if (null != baseIndexer)
|
||||
if (CurrentIndexer is BaseIndexer baseIndexer)
|
||||
{
|
||||
baseIndexer.ResetBaseConfig();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("")]
|
||||
public IEnumerable<Common.Models.DTO.Indexer> Indexers([FromQuery(Name = "configured")] bool configured)
|
||||
public IEnumerable<Common.Models.DTO.Indexer> Indexers([FromQuery(Name = "configured")] bool configured, [FromQuery(Name = "state")] FilterIndexerState filterState)
|
||||
{
|
||||
var dto = IndexerService.GetAllIndexers().Select(i => new Common.Models.DTO.Indexer(i));
|
||||
dto = configured ? dto.Where(i => i.configured) : dto;
|
||||
|
||||
if (configured)
|
||||
{
|
||||
dto = dto.Where(i => i.configured);
|
||||
}
|
||||
|
||||
switch (filterState)
|
||||
{
|
||||
case FilterIndexerState.Success:
|
||||
dto = dto.Where(i => i.state == IndexerState.Success);
|
||||
break;
|
||||
case FilterIndexerState.Error:
|
||||
dto = dto.Where(i => i.state == IndexerState.Error);
|
||||
break;
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
@ -177,4 +195,11 @@ namespace Jackett.Server.Controllers
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public enum FilterIndexerState
|
||||
{
|
||||
All,
|
||||
Error,
|
||||
Success
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,16 +61,23 @@ namespace Jackett.Server
|
|||
config => config.Filters.Add(
|
||||
new AuthorizeFilter(
|
||||
new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build())))
|
||||
.AddJsonOptions(options => options.SerializerSettings.ContractResolver =
|
||||
new DefaultContractResolver()); //Web app uses Pascal Case JSON);
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
// Web app uses Pascal Case JSON)
|
||||
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter(new CamelCaseNamingStrategy()));
|
||||
});
|
||||
#else
|
||||
|
||||
services.AddControllers(
|
||||
config => config.Filters.Add(
|
||||
new AuthorizeFilter(
|
||||
new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build())))
|
||||
.AddNewtonsoftJson(
|
||||
options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
|
||||
.AddNewtonsoftJson(options =>
|
||||
{
|
||||
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter(new CamelCaseNamingStrategy()));
|
||||
});
|
||||
#endif
|
||||
|
||||
var runtimeSettings = new RuntimeSettings();
|
||||
|
|
Loading…
Reference in a new issue