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

Fixes #1929
pull/1931/head
Bogdan 12 months ago
parent 6cb787c17b
commit 8ac68e8946

@ -292,56 +292,60 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann
foreach (var setting in _definition.Settings)
{
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;
}
else if (setting.Type == "select")
switch (setting.Type)
{
if (indexerLogging)
{
_logger.Trace($"Setting options: {setting.Options.ToJson()}");
}
case "text":
case "password":
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 selected = sorted[(int)(long)value];
var sorted = setting.Options.OrderBy(x => x.Key).ToList();
var selected = sorted[(int)(long)value];
if (indexerLogging)
{
_logger.Debug($"Selected option: {selected.ToJson()}");
}
if (indexerLogging)
{
_logger.Debug($"Selected option: {selected.ToJson()}");
}
variables[name] = selected.Key;
}
else if (setting.Type == "info")
{
variables[name] = value;
}
else if (setting.Type == "cardigannCaptcha")
{
}
else
{
throw new NotSupportedException($"Type {setting.Type} is not supported.");
variables[name] = selected.Key;
break;
case "info":
variables[name] = value;
break;
case "cardigannCaptcha":
break;
default:
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()}");
}

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

Loading…
Cancel
Save