58 lines
2.4 KiB
Plaintext
58 lines
2.4 KiB
Plaintext
@namespace Heimdall.Web.Components.Settings
|
||||
|
|
@inject HeimdallApiClient Api
|
|||
|
|
@inject ISnackbar Snackbar
|
|||
|
|
|
|||
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-lg);">
|
|||
|
|
<MudText Typo="Typo.h6" Class="mb-2"><i class="fas fa-arrows-rotate mr-2"></i>Mises à jour</MudText>
|
|||
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-3">
|
|||
|
|
Source globale des versions et des manifestes d’images Heimdall. L’URL doit être une adresse HTTPS absolue.
|
|||
|
|
</MudText>
|
|||
|
|
<MudTextField T="string" Label="API de publication" Variant="Variant.Outlined"
|
|||
|
|
Value="@_url" ValueChanged="SaveUrlAsync"
|
|||
|
|
Placeholder="https://forge.example/api/v1/repos/owner/repo/releases/latest" />
|
|||
|
|
</MudPaper>
|
|||
|
|
|
|||
|
|
@code {
|
|||
|
|
private const string SettingKey = "updates.releaseapiurl";
|
|||
|
|
private List<AppSettingItem> _settings = [];
|
|||
|
|
private string _url = string.Empty;
|
|||
|
|
|
|||
|
|
protected override async Task OnInitializedAsync()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
_settings = await Api.GetSettingsAsync();
|
|||
|
|
_url = _settings.FirstOrDefault(s => s.Key.Equals(SettingKey, StringComparison.OrdinalIgnoreCase))?.Value ?? string.Empty;
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
_settings = [];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private async Task SaveUrlAsync(string value)
|
|||
|
|
{
|
|||
|
|
value = value?.Trim() ?? string.Empty;
|
|||
|
|
if (value.Length > 0 && (!Uri.TryCreate(value, UriKind.Absolute, out var uri) || uri.Scheme != Uri.UriSchemeHttps))
|
|||
|
|
{
|
|||
|
|
Snackbar.Add("L’URL doit être une adresse HTTPS absolue.", Severity.Warning);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var existing = _settings.FirstOrDefault(s => s.Key.Equals(SettingKey, StringComparison.OrdinalIgnoreCase));
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (existing is null)
|
|||
|
|
await Api.CreateSettingAsync(new CreateAppSettingRequest(SettingKey, value, "updates", "API de publication Heimdall", "string", null, false));
|
|||
|
|
else
|
|||
|
|
await Api.UpdateSettingAsync(existing.Key, new UpdateAppSettingRequest(value, existing.Description, "updates", "string", null, false));
|
|||
|
|
_url = value;
|
|||
|
|
_settings = await Api.GetSettingsAsync();
|
|||
|
|
Snackbar.Add("Source des mises à jour enregistrée.", Severity.Success);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
Snackbar.Add($"Impossible d’enregistrer la source des mises à jour : {ex.Message}", Severity.Error);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|