mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-22 01:42:08 +10:00
DHCP: read-only hosts from other configs, combobox inputs, polling, UI fixes
- Static hosts: read dhcp-host from all config files; show external as read-only with Source column; IsEditable + SourcePath on DhcpHostEntry; reject save if managed entry duplicates MAC from another file (400 + message) - Lease field: single input + datalist (type or select), remove Other dropdown - MAC field: single input + datalist from current leases, TryFillFromLeaseByMac - Add host: default Name=*, suggest next free IP from DHCP range - Leases: configurable refresh polling; Settings modal for interval (client-side) - DhcpHostsClient: surface 400 error body message on save failure - App title config (ApplicationOptions), nav/layout/error/hosts tweaks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using DnsmasqWebUI.Client.Http.Abstractions;
|
||||
using DnsmasqWebUI.Models;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace DnsmasqWebUI.Client.Http;
|
||||
|
||||
@@ -19,8 +20,25 @@ public sealed class DhcpHostsClient : IDhcpHostsClient
|
||||
public async Task<SaveWithReloadResult> SaveDhcpHostsAsync(IReadOnlyList<DhcpHostEntry> entries, CancellationToken ct = default)
|
||||
{
|
||||
var response = await _http.PutAsJsonAsync("api/dhcp/hosts", entries, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var body = await response.Content.ReadAsStringAsync(ct);
|
||||
var msg = response.ReasonPhrase ?? response.StatusCode.ToString();
|
||||
if (!string.IsNullOrEmpty(body) && body.TrimStart().StartsWith("{"))
|
||||
{
|
||||
try
|
||||
{
|
||||
var err = System.Text.Json.JsonSerializer.Deserialize<JsonError>(body);
|
||||
if (!string.IsNullOrEmpty(err?.Error))
|
||||
msg = err.Error;
|
||||
}
|
||||
catch { /* use msg as-is */ }
|
||||
}
|
||||
throw new HttpRequestException(msg);
|
||||
}
|
||||
return await response.Content.ReadFromJsonAsync<SaveWithReloadResult>(ct)
|
||||
?? throw new InvalidOperationException("Unexpected null from api/dhcp/hosts.");
|
||||
}
|
||||
|
||||
private sealed class JsonError { [JsonPropertyName("error")] public string? Error { get; set; } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user