Fixed: (Cardigann) Use of the default value for new select settings

Fixes #1929
pull/1931/head
Bogdan 1 year ago
parent 6cb787c17b
commit 8ac68e8946

@ -292,28 +292,35 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
foreach (var setting in _definition.Settings) foreach (var setting in _definition.Settings)
{ {
var name = ".Config." + setting.Name; var name = ".Config." + setting.Name;
var value = Settings.ExtraFieldData.GetValueOrDefault(setting.Name, setting.Default);
if ((setting.Type != "password" && setting.Name != "apikey" && setting.Name != "rsskey") && indexerLogging) object defaultValue = setting.Type switch
{
"select" => setting.Options.OrderBy(x => x.Key).Select(x => x.Key).ToList().IndexOf(setting.Default).ToString().ParseInt64() ?? 0,
_ => setting.Default
};
var value = Settings.ExtraFieldData.GetValueOrDefault(setting.Name, defaultValue);
if (indexerLogging && setting.Type != "password" && setting.Name != "apikey" && setting.Name != "rsskey")
{ {
_logger.Trace($"{name} got value {value.ToJson()}"); _logger.Trace($"{name} got value {value.ToJson()}");
} }
if (setting.Type == "text" || setting.Type == "password") switch (setting.Type)
{ {
case "text":
case "password":
variables[name] = value; variables[name] = value;
} break;
else if (setting.Type == "checkbox") case "checkbox":
{
if (value is string stringValue && bool.TryParse(stringValue, out var result)) if (value is string stringValue && bool.TryParse(stringValue, out var result))
{ {
value = result; value = result;
} }
variables[name] = (bool)value ? ".True" : null; variables[name] = (bool)value ? ".True" : null;
} break;
else if (setting.Type == "select") case "select":
{
if (indexerLogging) if (indexerLogging)
{ {
_logger.Trace($"Setting options: {setting.Options.ToJson()}"); _logger.Trace($"Setting options: {setting.Options.ToJson()}");
@ -328,20 +335,17 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
} }
variables[name] = selected.Key; variables[name] = selected.Key;
} break;
else if (setting.Type == "info") case "info":
{
variables[name] = value; variables[name] = value;
} break;
else if (setting.Type == "cardigannCaptcha") case "cardigannCaptcha":
{ break;
} default:
else
{
throw new NotSupportedException($"Type {setting.Type} is not supported."); throw new NotSupportedException($"Type {setting.Type} is not supported.");
} }
if (setting.Type != "password" && setting.Name != "apikey" && setting.Name != "rsskey" && indexerLogging && variables.ContainsKey(name)) if (indexerLogging && setting.Type != "password" && setting.Name != "apikey" && setting.Name != "rsskey" && variables.ContainsKey(name))
{ {
_logger.Debug($"Setting {setting.Name} to {variables[name].ToJson()}"); _logger.Debug($"Setting {setting.Name} to {variables[name].ToJson()}");
} }

@ -152,25 +152,12 @@ namespace Prowlarr.Api.V1.Indexers
private object MapValue(SettingsField setting, object value) private object MapValue(SettingsField setting, object value)
{ {
if (setting.Type == "select") return setting.Type switch
{
return value.ToString().ParseInt64() ?? 0;
}
else if (setting.Type == "checkbox")
{
if (bool.TryParse(value.ToString(), out var result))
{ {
return result; "select" => value.ToString().ParseInt64() ?? 0,
} "checkbox" => bool.TryParse(value.ToString(), out var result) && result,
else _ => value?.ToString() ?? string.Empty
{ };
return false;
}
}
else
{
return value?.ToString() ?? string.Empty;
}
} }
private Field MapField(SettingsField setting, int order) private Field MapField(SettingsField setting, int order)
@ -196,14 +183,7 @@ namespace Prowlarr.Api.V1.Indexers
} }
else if (setting.Type == "checkbox") else if (setting.Type == "checkbox")
{ {
if (bool.TryParse(setting.Default, out var value)) field.Value = bool.TryParse(setting.Default, out var value) && value;
{
field.Value = value;
}
else
{
field.Value = false;
}
} }
else else
{ {

Loading…
Cancel
Save