From cf1c44ed751db659c3fe77a8c35cd33faff0058b Mon Sep 17 00:00:00 2001 From: Qstick Date: Fri, 4 Jun 2021 19:27:21 -0400 Subject: [PATCH] Fixed: Normalize definitions when serving local and remote --- .../IndexerDefinitionUpdateService.cs | 79 ++++++++++--------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/src/NzbDrone.Core/IndexerVersions/IndexerDefinitionUpdateService.cs b/src/NzbDrone.Core/IndexerVersions/IndexerDefinitionUpdateService.cs index af83e6d14..2dcb27bb9 100644 --- a/src/NzbDrone.Core/IndexerVersions/IndexerDefinitionUpdateService.cs +++ b/src/NzbDrone.Core/IndexerVersions/IndexerDefinitionUpdateService.cs @@ -89,7 +89,8 @@ namespace NzbDrone.Core.IndexerVersions { var req = new HttpRequest($"https://indexers.prowlarr.com/master/{DEFINITION_VERSION}/{id}"); var response = _httpClient.Get(req); - return _deserializer.Deserialize(response.Content); + var definition = _deserializer.Deserialize(response.Content); + return CleanIndexerDefinition(definition); } private CardigannDefinition LoadIndexerDef(string fileKey) @@ -118,42 +119,7 @@ namespace NzbDrone.Core.IndexerVersions var definitionString = File.ReadAllText(file.FullName); var definition = _deserializer.Deserialize(definitionString); - //defaults - if (definition.Settings == null) - { - definition.Settings = new List - { - new SettingsField { Name = "username", Label = "Username", Type = "text" }, - new SettingsField { Name = "password", Label = "Password", Type = "password" } - }; - } - - if (definition.Encoding == null) - { - definition.Encoding = "UTF-8"; - } - - if (definition.Login != null && definition.Login.Method == null) - { - definition.Login.Method = "form"; - } - - if (definition.Search.Paths == null) - { - definition.Search.Paths = new List(); - } - - // convert definitions with a single search Path to a Paths entry - if (definition.Search.Path != null) - { - definition.Search.Paths.Add(new SearchPathBlock - { - Path = definition.Search.Path, - Inheritinputs = true - }); - } - - return definition; + return CleanIndexerDefinition(definition); } catch (Exception e) { @@ -165,6 +131,45 @@ namespace NzbDrone.Core.IndexerVersions return GetHttpDefinition(fileKey); } + private CardigannDefinition CleanIndexerDefinition(CardigannDefinition definition) + { + if (definition.Settings == null) + { + definition.Settings = new List + { + new SettingsField { Name = "username", Label = "Username", Type = "text" }, + new SettingsField { Name = "password", Label = "Password", Type = "password" } + }; + } + + if (definition.Encoding == null) + { + definition.Encoding = "UTF-8"; + } + + if (definition.Login != null && definition.Login.Method == null) + { + definition.Login.Method = "form"; + } + + if (definition.Search.Paths == null) + { + definition.Search.Paths = new List(); + } + + // convert definitions with a single search Path to a Paths entry + if (definition.Search.Path != null) + { + definition.Search.Paths.Add(new SearchPathBlock + { + Path = definition.Search.Path, + Inheritinputs = true + }); + } + + return definition; + } + public void Execute(IndexerDefinitionUpdateCommand message) { UpdateLocalDefinitions();