@page "/hosts/export" @using RackPeek.Domain.UseCases.Hosts @inject HostsFileExportUseCase HostsUseCase
Hosts File Export
Include Tags
Only include resources with these tags (optional)
Domain Suffix
Appends .domain to host names (optional)
@if (_warnings.Any()) {
Warnings
}
Generated Hosts File
@code { private string _includeTagsRaw = string.Empty; private string? _domainSuffix = "home.local"; private bool _includeLocalhost = true; private string _hostsText = string.Empty; private List _warnings = new(); private async Task GenerateExport() { try { _warnings.Clear(); _hostsText = string.Empty; var options = new HostsExportOptions { IncludeTags = ParseCsv(_includeTagsRaw), DomainSuffix = string.IsNullOrWhiteSpace(_domainSuffix) ? null : _domainSuffix, IncludeLocalhostDefaults = _includeLocalhost }; var result = await HostsUseCase.ExecuteAsync(options); if (result is null) { _warnings.Add("Hosts export returned null."); return; } _hostsText = result.HostsText; _warnings = result.Warnings.ToList(); } catch (Exception ex) { _warnings.Clear(); _warnings.Add($"Unexpected error: {ex.Message}"); } } private static IReadOnlyList ParseCsv(string raw) { if (string.IsNullOrWhiteSpace(raw)) return []; return raw.Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .Where(x => !string.IsNullOrWhiteSpace(x)) .ToArray(); } }