mirror of
https://github.com/Jackett/Jackett
synced 2025-01-04 22:41:49 +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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using Jackett.Common.Extensions;
|
||||||
using Jackett.Common.Indexers;
|
using Jackett.Common.Indexers;
|
||||||
|
|
||||||
namespace Jackett.Common.Models.DTO
|
namespace Jackett.Common.Models.DTO
|
||||||
|
@ -40,6 +41,9 @@ namespace Jackett.Common.Models.DTO
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public bool potatoenabled { get; private set; }
|
public bool potatoenabled { get; private set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public IndexerState state => last_error.IsNotNullOrWhiteSpace() ? IndexerState.Error : IndexerState.Success;
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public IEnumerable<Capability> caps { get; private set; }
|
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 System.Threading.Tasks;
|
||||||
using Jackett.Common.Indexers;
|
using Jackett.Common.Indexers;
|
||||||
using Jackett.Common.Models;
|
using Jackett.Common.Models;
|
||||||
|
using Jackett.Common.Models.DTO;
|
||||||
using Jackett.Common.Services.Interfaces;
|
using Jackett.Common.Services.Interfaces;
|
||||||
using Jackett.Common.Utils;
|
using Jackett.Common.Utils;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
@ -105,19 +106,36 @@ namespace Jackett.Server.Controllers
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
var baseIndexer = CurrentIndexer as BaseIndexer;
|
if (CurrentIndexer is BaseIndexer baseIndexer)
|
||||||
if (null != baseIndexer)
|
{
|
||||||
baseIndexer.ResetBaseConfig();
|
baseIndexer.ResetBaseConfig();
|
||||||
|
}
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("")]
|
[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));
|
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;
|
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(
|
config => config.Filters.Add(
|
||||||
new AuthorizeFilter(
|
new AuthorizeFilter(
|
||||||
new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build())))
|
new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build())))
|
||||||
.AddJsonOptions(options => options.SerializerSettings.ContractResolver =
|
.AddJsonOptions(options =>
|
||||||
new DefaultContractResolver()); //Web app uses Pascal Case JSON);
|
{
|
||||||
|
// Web app uses Pascal Case JSON)
|
||||||
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||||
|
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter(new CamelCaseNamingStrategy()));
|
||||||
|
});
|
||||||
#else
|
#else
|
||||||
|
|
||||||
services.AddControllers(
|
services.AddControllers(
|
||||||
config => config.Filters.Add(
|
config => config.Filters.Add(
|
||||||
new AuthorizeFilter(
|
new AuthorizeFilter(
|
||||||
new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build())))
|
new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build())))
|
||||||
.AddNewtonsoftJson(
|
.AddNewtonsoftJson(options =>
|
||||||
options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
|
{
|
||||||
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||||
|
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter(new CamelCaseNamingStrategy()));
|
||||||
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var runtimeSettings = new RuntimeSettings();
|
var runtimeSettings = new RuntimeSettings();
|
||||||
|
|
Loading…
Reference in a new issue