From 8b1dd783003f3d4430ca1052e459b0cb249ca07e Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 29 Jul 2023 12:08:48 +0300 Subject: [PATCH] Fixed: (Apps) Ensure populated capabilities for Torznab/Newznab definitions --- src/NzbDrone.Core/Applications/ApplicationService.cs | 6 ++++-- .../Indexers/Definitions/Newznab/Newznab.cs | 10 ++++------ .../Definitions/Newznab/NewznabCapabilitiesProvider.cs | 3 +-- .../Indexers/Definitions/Torznab/Torznab.cs | 10 ++++------ 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/NzbDrone.Core/Applications/ApplicationService.cs b/src/NzbDrone.Core/Applications/ApplicationService.cs index 3434c8aa4..5d9e868cf 100644 --- a/src/NzbDrone.Core/Applications/ApplicationService.cs +++ b/src/NzbDrone.Core/Applications/ApplicationService.cs @@ -67,10 +67,11 @@ public void HandleAsync(ProviderUpdatedEvent message) public void HandleAsync(ProviderAddedEvent message) { var enabledApps = _applicationsFactory.SyncEnabled(); + var indexer = _indexerFactory.GetInstance((IndexerDefinition)message.Definition); foreach (var app in enabledApps) { - if (ShouldHandleIndexer(app.Definition, message.Definition)) + if (ShouldHandleIndexer(app.Definition, indexer.Definition)) { ExecuteAction(a => a.AddIndexer((IndexerDefinition)message.Definition), app); } @@ -92,8 +93,9 @@ public void HandleAsync(ProviderUpdatedEvent message) var enabledApps = _applicationsFactory.SyncEnabled() .Where(n => ((ApplicationDefinition)n.Definition).SyncLevel == ApplicationSyncLevel.FullSync) .ToList(); + var indexer = _indexerFactory.GetInstance((IndexerDefinition)message.Definition); - SyncIndexers(enabledApps, new List { (IndexerDefinition)message.Definition }); + SyncIndexers(enabledApps, new List { (IndexerDefinition)indexer.Definition }); } public void HandleAsync(ApiKeyChangedEvent message) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/Newznab.cs index 29d5b757f..67202834e 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/Newznab.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/Newznab.cs @@ -43,14 +43,12 @@ public override IParseIndexerResponse GetParser() public string[] GetBaseUrlFromSettings() { - var baseUrl = ""; - - if (Definition == null || Settings == null || Settings.Categories == null) + if (Definition == null || Settings?.Categories == null) { - return new string[] { baseUrl }; + return new[] { "" }; } - return new string[] { Settings.BaseUrl }; + return new[] { Settings.BaseUrl }; } protected override NewznabSettings GetDefaultBaseUrl(NewznabSettings settings) @@ -62,7 +60,7 @@ public IndexerCapabilities GetCapabilitiesFromSettings() { var caps = new IndexerCapabilities(); - if (Definition == null || Settings == null || Settings.Categories == null) + if (Definition == null || Settings?.Categories == null) { return caps; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesProvider.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesProvider.cs index acdecca56..1e9056f83 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesProvider.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabCapabilitiesProvider.cs @@ -34,9 +34,8 @@ public NewznabCapabilitiesProvider(ICacheManager cacheManager, IIndexerHttpClien public IndexerCapabilities GetCapabilities(NewznabSettings indexerSettings, ProviderDefinition definition) { var key = indexerSettings.ToJson(); - var capabilities = _capabilitiesCache.Get(key, () => FetchCapabilities(indexerSettings, definition), TimeSpan.FromDays(7)); - return capabilities; + return _capabilitiesCache.Get(key, () => FetchCapabilities(indexerSettings, definition), TimeSpan.FromDays(7)); } private IndexerCapabilities FetchCapabilities(NewznabSettings indexerSettings, ProviderDefinition definition) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Torznab/Torznab.cs b/src/NzbDrone.Core/Indexers/Definitions/Torznab/Torznab.cs index 8d9941ed0..ee4b824fe 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Torznab/Torznab.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Torznab/Torznab.cs @@ -45,14 +45,12 @@ public override IParseIndexerResponse GetParser() public string[] GetBaseUrlFromSettings() { - var baseUrl = ""; - - if (Definition == null || Settings == null || Settings.Categories == null) + if (Definition == null || Settings?.Categories == null) { - return new string[] { baseUrl }; + return new[] { "" }; } - return new string[] { Settings.BaseUrl }; + return new[] { Settings.BaseUrl }; } protected override TorznabSettings GetDefaultBaseUrl(TorznabSettings settings) @@ -64,7 +62,7 @@ public IndexerCapabilities GetCapabilitiesFromSettings() { var caps = new IndexerCapabilities(); - if (Definition == null || Settings == null || Settings.Categories == null) + if (Definition == null || Settings?.Categories == null) { return caps; }