mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-04 04:18:13 +10:00
- Dnsmasq page: Config (Main config, Managed file, Config set) under Service configuration; remove Paths/Leases (in Effective config DHCP); EffectiveConfigSection collapsible groups; StatusSection flex-wrap - Hosts: HostsFileSection always shows table; 'No host entries' in tbody when empty - Models: reorganize into sub-namespaces (Config, EffectiveConfig, Hosts, Dhcp, Status); move EffectiveConfig/Status/Logs components under Dnsmasq - Test harness: prepare-test-mount.sh runs 'docker compose down' before mount+up so all containers (including DHCP clients) restart; exclude testdata/leases from sync (unit tests only); testdata/README
34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using DnsmasqWebUI.Client.Http.Abstractions;
|
|
using DnsmasqWebUI.Models.Hosts;
|
|
using DnsmasqWebUI.Models.Status;
|
|
using System.Net.Http.Json;
|
|
|
|
namespace DnsmasqWebUI.Client.Http;
|
|
|
|
public sealed class HostsClient : IHostsClient
|
|
{
|
|
private readonly HttpClient _http;
|
|
|
|
public HostsClient(HttpClient http) => _http = http;
|
|
|
|
public async Task<IReadOnlyList<HostEntry>> GetHostsAsync(CancellationToken ct = default)
|
|
{
|
|
var list = await _http.GetFromJsonAsync<List<HostEntry>>("api/hosts", ct);
|
|
return list ?? new List<HostEntry>();
|
|
}
|
|
|
|
public async Task<IReadOnlyList<ReadOnlyHostsFile>> GetReadOnlyHostsAsync(CancellationToken ct = default)
|
|
{
|
|
var list = await _http.GetFromJsonAsync<List<ReadOnlyHostsFile>>("api/hosts/readonly", ct);
|
|
return list ?? new List<ReadOnlyHostsFile>();
|
|
}
|
|
|
|
public async Task<SaveWithReloadResult> SaveHostsAsync(IReadOnlyList<HostEntry> entries, CancellationToken ct = default)
|
|
{
|
|
var response = await _http.PutAsJsonAsync("api/hosts", entries, ct);
|
|
response.EnsureSuccessStatusCode();
|
|
return await response.Content.ReadFromJsonAsync<SaveWithReloadResult>(ct)
|
|
?? throw new InvalidOperationException("Unexpected null from api/hosts.");
|
|
}
|
|
}
|