Make the hold method configurable in the dashboard
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9a56fc5b48
commit
6b9bf3cd5f
40 files changed
+815
-134
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using Flypaper.Core.Strategies;
|
||||
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
@@ -9,12 +10,14 @@ public static class RuntimeSettingsParser
|
||||
|
||||
private static readonly TimeSpan MinHold = TimeSpan.FromSeconds(1);
|
||||
private static readonly TimeSpan MaxHold = TimeSpan.FromDays(7);
|
||||
private const int MinDelayMs = 10;
|
||||
private const int MaxDelayMs = 30_000;
|
||||
private const int MaxChunkSize = 4096;
|
||||
|
||||
public static RuntimeSettingsParseResult Parse(RuntimeSettingsInput input)
|
||||
{
|
||||
var errors = new Dictionary<string, string>();
|
||||
|
||||
var hold = ParseTimeSpan(input.MaxHoldDuration, nameof(input.MaxHoldDuration), MinHold, MaxHold, errors);
|
||||
var maxConnections = ParseInt(input.MaxConnections, nameof(input.MaxConnections), 1, MaxLimit, errors);
|
||||
var perIp = ParseInt(input.MaxConnectionsPerIp, nameof(input.MaxConnectionsPerIp), 1, MaxLimit, errors);
|
||||
var retention = ParseInt(input.RetentionDays, nameof(input.RetentionDays), 0, MaxRetentionDays, errors);
|
||||
@@ -33,12 +36,55 @@ public static class RuntimeSettingsParser
|
||||
var settings = new RuntimeSettings(
|
||||
maxConnections!.Value,
|
||||
perIp!.Value,
|
||||
hold!.Value,
|
||||
retention!.Value,
|
||||
input.IgnorePrivateNetworks);
|
||||
return new RuntimeSettingsParseResult(settings, errors);
|
||||
}
|
||||
|
||||
public static HoldMethodParseResult ParseHoldMethod(HoldMethodInput input)
|
||||
{
|
||||
var errors = new Dictionary<string, string>();
|
||||
|
||||
DripContent? content = Enum.TryParse<DripContent>(input.Content, ignoreCase: true, out var parsed) && Enum.IsDefined(parsed)
|
||||
? parsed
|
||||
: null;
|
||||
if (content is null)
|
||||
{
|
||||
errors[nameof(input.Content)] = "Bitte eine Methode wählen.";
|
||||
}
|
||||
|
||||
var minDelay = ParseInt(input.MinDelayMs, nameof(input.MinDelayMs), MinDelayMs, MaxDelayMs, errors);
|
||||
var maxDelay = ParseInt(input.MaxDelayMs, nameof(input.MaxDelayMs), MinDelayMs, MaxDelayMs, errors);
|
||||
var minChunk = ParseInt(input.MinChunkSize, nameof(input.MinChunkSize), 1, MaxChunkSize, errors);
|
||||
var maxChunk = ParseInt(input.MaxChunkSize, nameof(input.MaxChunkSize), 1, MaxChunkSize, errors);
|
||||
var hold = ParseTimeSpan(input.MaxHoldDuration, nameof(input.MaxHoldDuration), MinHold, MaxHold, errors);
|
||||
|
||||
if (minDelay > maxDelay)
|
||||
{
|
||||
errors[nameof(input.MaxDelayMs)] = "Darf nicht kleiner sein als das Minimum.";
|
||||
}
|
||||
|
||||
if (minChunk > maxChunk)
|
||||
{
|
||||
errors[nameof(input.MaxChunkSize)] = "Darf nicht kleiner sein als das Minimum.";
|
||||
}
|
||||
|
||||
if (errors.Count > 0)
|
||||
{
|
||||
return new HoldMethodParseResult(null, errors);
|
||||
}
|
||||
|
||||
return new HoldMethodParseResult(
|
||||
new HoldMethodSettings(
|
||||
content!.Value,
|
||||
TimeSpan.FromMilliseconds(minDelay!.Value),
|
||||
TimeSpan.FromMilliseconds(maxDelay!.Value),
|
||||
minChunk!.Value,
|
||||
maxChunk!.Value,
|
||||
hold!.Value),
|
||||
errors);
|
||||
}
|
||||
|
||||
private static TimeSpan? ParseTimeSpan(
|
||||
string? raw,
|
||||
string field,
|
||||
|
||||
Reference in new issue
Block a user