From 80e5ac4aa916a500ce9bff5e6005d5324822217d Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 12 Sep 2023 15:25:48 +0300 Subject: [PATCH] New: Add custom filter by protocol for indexer stats --- .../src/Store/Actions/indexerStatsActions.js | 10 +++++++++ .../Indexers/IndexerStatsController.cs | 21 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/frontend/src/Store/Actions/indexerStatsActions.js b/frontend/src/Store/Actions/indexerStatsActions.js index dc928d9b5..fe13c6db4 100644 --- a/frontend/src/Store/Actions/indexerStatsActions.js +++ b/frontend/src/Store/Actions/indexerStatsActions.js @@ -61,6 +61,12 @@ export const defaultState = { type: filterBuilderTypes.CONTAINS, valueType: filterBuilderValueTypes.INDEXER }, + { + name: 'protocols', + label: () => translate('Protocols'), + type: filterBuilderTypes.EXACT, + valueType: filterBuilderValueTypes.PROTOCOL + }, { name: 'tags', label: () => translate('Tags'), @@ -112,6 +118,10 @@ export const actionHandlers = handleThunks({ requestParams.indexers = selectedFilter.value.join(','); } + if (selectedFilter.key === 'protocols') { + requestParams.protocols = selectedFilter.value.join(','); + } + if (selectedFilter.key === 'tags') { requestParams.tags = selectedFilter.value.join(','); } diff --git a/src/Prowlarr.Api.V1/Indexers/IndexerStatsController.cs b/src/Prowlarr.Api.V1/Indexers/IndexerStatsController.cs index 1b9b1ec91..cd513c2e0 100644 --- a/src/Prowlarr.Api.V1/Indexers/IndexerStatsController.cs +++ b/src/Prowlarr.Api.V1/Indexers/IndexerStatsController.cs @@ -26,13 +26,30 @@ namespace Prowlarr.Api.V1.Indexers [HttpGet] [Produces("application/json")] - public IndexerStatsResource GetAll(DateTime? startDate, DateTime? endDate, string indexers, string tags) + public IndexerStatsResource GetAll(DateTime? startDate, DateTime? endDate, string indexers, string protocols, string tags) { var statsStartDate = startDate ?? DateTime.MinValue; var statsEndDate = endDate ?? DateTime.Now; var parsedIndexers = new List(); var parsedTags = new List(); - var indexerIds = _indexerFactory.All().Select(i => i.Id).ToList(); + + var allIndexers = _indexerFactory.All().Select(_indexerFactory.GetInstance).ToList(); + + if (protocols.IsNotNullOrWhiteSpace()) + { + var parsedProtocols = protocols.Split(',') + .Select(protocol => + { + Enum.TryParse(protocol, true, out DownloadProtocol downloadProtocol); + + return downloadProtocol; + }) + .ToHashSet(); + + allIndexers = allIndexers.Where(i => parsedProtocols.Contains(i.Protocol)).ToList(); + } + + var indexerIds = allIndexers.Select(i => i.Definition.Id).ToList(); if (tags.IsNotNullOrWhiteSpace()) {