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,56 +292,60 @@ 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
{ {
_logger.Trace($"{name} got value {value.ToJson()}"); "select" => setting.Options.OrderBy(x => x.Key).Select(x => x.Key).ToList().IndexOf(setting.Default).ToString().ParseInt64() ?? 0,
} _ => setting.Default
};
if (setting.Type == "text" || setting.Type == "password") var value = Settings.ExtraFieldData.GetValueOrDefault(setting.Name, defaultValue);
if (indexerLogging && setting.Type != "password" && setting.Name != "apikey" && setting.Name != "rsskey")
{ {
variables[name] = value; _logger.Trace($"{name} got value {value.ToJson()}");
} }
else if (setting.Type == "checkbox")
{
if (value is string stringValue && bool.TryParse(stringValue, out var result))
{
value = result;
}
variables[name] = (bool)value ? ".True" : null; switch (setting.Type)
}
else if (setting.Type == "select")
{ {
if (indexerLogging) case "text":
{ case "password":
_logger.Trace($"Setting options: {setting.Options.ToJson()}"); variables[name] = value;
} break;
case "checkbox":
if (value is string stringValue && bool.TryParse(stringValue, out var result))
{
value = result;
}
variables[name] = (bool)value ? ".True" : null;
break;
case "select":
if (indexerLogging)
{
_logger.Trace($"Setting options: {setting.Options.ToJson()}");
}
var sorted = setting.Options.OrderBy(x => x.Key).ToList(); var sorted = setting.Options.OrderBy(x => x.Key).ToList();
var selected = sorted[(int)(long)value]; var selected = sorted[(int)(long)value];
if (indexerLogging) if (indexerLogging)
{ {
_logger.Debug($"Selected option: {selected.ToJson()}"); _logger.Debug($"Selected option: {selected.ToJson()}");
} }
variables[name] = selected.Key; variables[name] = selected.Key;
} break;
else if (setting.Type == "info") case "info":
{ variables[name] = value;
variables[name] = value; break;
} case "cardigannCaptcha":
else if (setting.Type == "cardigannCaptcha") break;
{ default:
} throw new NotSupportedException($"Type {setting.Type} is not supported.");
else
{
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; "select" => value.ToString().ParseInt64() ?? 0,
} "checkbox" => bool.TryParse(value.ToString(), out var result) && result,
else if (setting.Type == "checkbox") _ => value?.ToString() ?? string.Empty
{ };
if (bool.TryParse(value.ToString(), out var result))
{
return result;
}
else
{
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