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
@@ -0,0 +1,156 @@
|
||||
@using System.Globalization
|
||||
@using Flypaper.Core
|
||||
@using Flypaper.Core.Settings
|
||||
@using Flypaper.Core.Strategies
|
||||
@using Flypaper.Storage.Settings
|
||||
@using Microsoft.Extensions.Options
|
||||
@inject IOptionsMonitor<DripOptions> Drip
|
||||
@inject IOptionsMonitor<FlypaperOptions> Core
|
||||
@inject RuntimeSettingsStore Store
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<section class="card form" id="hold-method">
|
||||
<header class="section-head">
|
||||
<h2>Haltemethode</h2>
|
||||
@if (_hasOverrides)
|
||||
{
|
||||
<span class="badge">Überschrieben</span>
|
||||
}
|
||||
</header>
|
||||
|
||||
@if (Saved == "saved")
|
||||
{
|
||||
<div class="banner ok">Gespeichert. Gilt ab dem nächsten Fang.</div>
|
||||
}
|
||||
else if (Saved == "reset")
|
||||
{
|
||||
<div class="banner ok">Haltemethode auf Standard zurückgesetzt.</div>
|
||||
}
|
||||
|
||||
<EditForm Model="Model" FormName="hold-method" OnSubmit="SaveAsync" action="/settings" class="form">
|
||||
<label for="drip-content">Inhalt</label>
|
||||
<InputSelect id="drip-content" @bind-Value="Model!.Content">
|
||||
<option value="@DripContent.Html">HTML-Fülltext</option>
|
||||
<option value="@DripContent.Text">Zufallstext (plain text)</option>
|
||||
<option value="@DripContent.Alternating">Wechselnd (pro Fang zufällig)</option>
|
||||
</InputSelect>
|
||||
<FieldError Errors="_errors" Field="@nameof(HoldMethodModel.Content)" />
|
||||
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label for="drip-min-delay">Pause min. <span class="muted">(ms)</span></label>
|
||||
<InputText id="drip-min-delay" @bind-Value="Model!.MinDelayMs" class="mono" inputmode="numeric" data-bandwidth-input />
|
||||
<FieldError Errors="_errors" Field="@nameof(HoldMethodModel.MinDelayMs)" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="drip-max-delay">Pause max. <span class="muted">(ms)</span></label>
|
||||
<InputText id="drip-max-delay" @bind-Value="Model!.MaxDelayMs" class="mono" inputmode="numeric" data-bandwidth-input />
|
||||
<FieldError Errors="_errors" Field="@nameof(HoldMethodModel.MaxDelayMs)" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="drip-min-chunk">Paket min. <span class="muted">(Bytes)</span></label>
|
||||
<InputText id="drip-min-chunk" @bind-Value="Model!.MinChunkSize" class="mono" inputmode="numeric" data-bandwidth-input />
|
||||
<FieldError Errors="_errors" Field="@nameof(HoldMethodModel.MinChunkSize)" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="drip-max-chunk">Paket max. <span class="muted">(Bytes)</span></label>
|
||||
<InputText id="drip-max-chunk" @bind-Value="Model!.MaxChunkSize" class="mono" inputmode="numeric" data-bandwidth-input />
|
||||
<FieldError Errors="_errors" Field="@nameof(HoldMethodModel.MaxChunkSize)" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="hold">Maximale Haltedauer <span class="muted">(hh:mm:ss)</span></label>
|
||||
<InputText id="hold" @bind-Value="Model!.MaxHoldDuration" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(HoldMethodModel.MaxHoldDuration)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="muted">
|
||||
Pause 10 ms bis 30 s, Paket 1 bis 4096 Bytes. Ø ca. <strong id="drip-bandwidth">@Bandwidth</strong> Bytes/s pro gefangener Verbindung.
|
||||
</p>
|
||||
|
||||
<div class="actions">
|
||||
<button type="submit">Speichern</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<EditForm Model="_resetModel" FormName="hold-method-reset" OnSubmit="ResetAsync" action="/settings" class="danger-zone">
|
||||
<div class="actions">
|
||||
<button type="submit" class="secondary" disabled="@(!_hasOverrides)" onclick="return confirm('Haltemethode auf Standard zurücksetzen?')">Auf Standard zurücksetzen</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
</section>
|
||||
|
||||
<script src="@Assets["settings.js"]" defer></script>
|
||||
|
||||
@code {
|
||||
private readonly object _resetModel = new();
|
||||
private IReadOnlyDictionary<string, string> _errors = new Dictionary<string, string>();
|
||||
private bool _hasOverrides;
|
||||
|
||||
[SupplyParameterFromForm(FormName = "hold-method")] private HoldMethodModel? Model { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "hold")] private string? Saved { get; set; }
|
||||
|
||||
private string Bandwidth
|
||||
{
|
||||
get
|
||||
{
|
||||
var ok = int.TryParse(Model?.MinDelayMs, out var minDelay) & int.TryParse(Model?.MaxDelayMs, out var maxDelay)
|
||||
& int.TryParse(Model?.MinChunkSize, out var minChunk) & int.TryParse(Model?.MaxChunkSize, out var maxChunk);
|
||||
if (!ok)
|
||||
{
|
||||
return "–";
|
||||
}
|
||||
|
||||
var bytesPerSecond = HoldMethodSettings.AverageBytesPerSecond(
|
||||
TimeSpan.FromMilliseconds(minDelay), TimeSpan.FromMilliseconds(maxDelay), minChunk, maxChunk);
|
||||
return bytesPerSecond.ToString(bytesPerSecond < 10 ? "0.0" : "N0", CultureInfo.GetCultureInfo("de-DE"));
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Model ??= CurrentValues();
|
||||
_hasOverrides = await Store.HasOverridesAsync(SettingKeys.HoldMethod.ToArray());
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
var result = RuntimeSettingsParser.ParseHoldMethod(new HoldMethodInput(
|
||||
Model!.Content,
|
||||
Model.MinDelayMs,
|
||||
Model.MaxDelayMs,
|
||||
Model.MinChunkSize,
|
||||
Model.MaxChunkSize,
|
||||
Model.MaxHoldDuration));
|
||||
|
||||
if (result.Settings is null)
|
||||
{
|
||||
_errors = result.Errors;
|
||||
return;
|
||||
}
|
||||
|
||||
await Store.SaveAsync(result.Settings);
|
||||
Navigation.NavigateTo("/settings?hold=saved#hold-method");
|
||||
}
|
||||
|
||||
private async Task ResetAsync()
|
||||
{
|
||||
await Store.ResetAsync(SettingKeys.HoldMethod.ToArray());
|
||||
Navigation.NavigateTo("/settings?hold=reset#hold-method");
|
||||
}
|
||||
|
||||
private HoldMethodModel CurrentValues()
|
||||
{
|
||||
var drip = Drip.CurrentValue;
|
||||
return new HoldMethodModel
|
||||
{
|
||||
Content = drip.Content.ToString(),
|
||||
MinDelayMs = ((int)drip.MinDelay.TotalMilliseconds).ToString(CultureInfo.InvariantCulture),
|
||||
MaxDelayMs = ((int)drip.MaxDelay.TotalMilliseconds).ToString(CultureInfo.InvariantCulture),
|
||||
MinChunkSize = drip.MinChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||
MaxChunkSize = drip.MaxChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||
MaxHoldDuration = Core.CurrentValue.MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture)
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user