Rifiniture (M8): avvisi su striscia, notifiche di Windows e Telegram con controllo dello spazio su disco; «Esporta l'elenco» della libreria; avvisi e ricette sospese in Attività; guida per il wiki in docs/guida
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
50 files changed
+3980
-28
No files matched your search
@@ -1,5 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Core.Alerts;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Engine;
|
||||
using Febe.Core.Storage;
|
||||
@@ -24,6 +26,9 @@ public static class ActivityApi
|
||||
endpoints.MapGet("/api/engine/incidents", async (IIncidentHistory history, IClock clock, CancellationToken ct) =>
|
||||
ApiHttp.Json(await IncidentsAsync(history, clock, ct).ConfigureAwait(false), FebeJsonContext.Default.IncidentListDto));
|
||||
|
||||
endpoints.MapGet("/api/alerts", async (IFebeStorage storage, IClock clock, CancellationToken ct) =>
|
||||
ApiHttp.Json(await AlertsAsync(storage, clock, ct).ConfigureAwait(false), FebeJsonContext.Default.AlertListDto));
|
||||
|
||||
endpoints.MapGet("/api/browser/preview", async (IBrowserPreview preview, CancellationToken ct) =>
|
||||
{
|
||||
var frame = await preview.GetLatestAsync(ct).ConfigureAwait(false);
|
||||
@@ -78,6 +83,37 @@ public static class ActivityApi
|
||||
return new IncidentListDto(dtos, throttles, advice);
|
||||
}
|
||||
|
||||
/// <summary>The alerts of the last <see cref="HistoryDays"/> days (at most 50), from the timeline.</summary>
|
||||
public static async Task<AlertListDto> AlertsAsync(IFebeStorage storage, IClock clock, CancellationToken ct)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(storage);
|
||||
ArgumentNullException.ThrowIfNull(clock);
|
||||
var now = clock.Now;
|
||||
var zone = clock.LocalZone;
|
||||
var events = await storage.Events.ListAsync(
|
||||
new EventQuery { From = now - TimeSpan.FromDays(HistoryDays), Codes = AlertCatalog.Codes, Limit = 50 },
|
||||
ct).ConfigureAwait(false);
|
||||
var items = events.Select(e =>
|
||||
{
|
||||
var kind = AlertCatalog.KindOf(e.Code);
|
||||
return new AlertItemDto(
|
||||
e.Id,
|
||||
ApiMapping.Local(e.At, now, zone),
|
||||
kind is { } k ? JsonNamingPolicy.CamelCase.ConvertName(k.ToString()) : "deliveryFailed",
|
||||
e.Severity switch
|
||||
{
|
||||
EventSeverity.Error => "error",
|
||||
EventSeverity.Warning => "warning",
|
||||
EventSeverity.Success => "success",
|
||||
_ => "info",
|
||||
},
|
||||
kind is { } known ? AlertCatalog.Title(known) : "Avviso non inviato",
|
||||
kind is { } alert ? AlertCatalog.FromEvent(alert, e, zone).Message : e.Message,
|
||||
e.AccountId);
|
||||
}).ToList();
|
||||
return new AlertListDto(items, HistoryDays);
|
||||
}
|
||||
|
||||
public static string Level(SignalLevel level) => level switch
|
||||
{
|
||||
SignalLevel.Throttle => "throttle",
|
||||
|
||||
@@ -39,6 +39,22 @@ public static class EngineApi
|
||||
return ApiHttp.Json(new ResumeDto(result.Resumed, result.Message), FebeJsonContext.Default.ResumeDto);
|
||||
});
|
||||
|
||||
// «Riattiva» a recipe suspended after three unknown formats (or targets not found) in a row.
|
||||
endpoints.MapPost("/api/engine/recipes/{recipe}/resume", async (string recipe, IEngineControl control, CancellationToken ct) =>
|
||||
{
|
||||
if (!Enum.TryParse<RecipeKind>(recipe, ignoreCase: true, out var kind) || !Enum.IsDefined(kind))
|
||||
{
|
||||
throw new BadRequestException("Ricetta sconosciuta.");
|
||||
}
|
||||
|
||||
var resumed = await control.ResumeRecipeAsync(kind, ct).ConfigureAwait(false);
|
||||
return ApiHttp.Json(
|
||||
new ResumeDto(resumed, resumed
|
||||
? "Ricetta riattivata: riprende alla prossima sessione. Se il formato è ancora sconosciuto, si sospende di nuovo dopo tre volte."
|
||||
: "Questa ricetta non era sospesa."),
|
||||
FebeJsonContext.Default.ResumeDto);
|
||||
});
|
||||
|
||||
// «Apri il browser» on Windows: the window of the browser comes to the front.
|
||||
endpoints.MapPost("/api/browser/show", async (IBrowserWindow browser, BrowserUseTracker tracker, IClock clock, CancellationToken ct) =>
|
||||
{
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Febe.Web.Api;
|
||||
[JsonSerializable(typeof(BeginDrivingRequest))]
|
||||
[JsonSerializable(typeof(FinishDto))]
|
||||
[JsonSerializable(typeof(IncidentListDto))]
|
||||
[JsonSerializable(typeof(AlertListDto))]
|
||||
[JsonSerializable(typeof(BrowserPreviewDto))]
|
||||
[JsonSerializable(typeof(DuplicateCountsDto))]
|
||||
[JsonSerializable(typeof(GeneralSettingsDto))]
|
||||
|
||||
@@ -32,6 +32,16 @@ public sealed record IncidentDto(
|
||||
/// <param name="Advice">«Tre rallentamenti in sette giorni»: the proposal of spec §7.6, or null.</param>
|
||||
public sealed record IncidentListDto(IReadOnlyList<IncidentDto> Items, int ThrottlesLastWeek, string? Advice);
|
||||
|
||||
/// <summary>
|
||||
/// A line of the «Avvisi» list of Attività (spec §13.3): an alert or a failed delivery. <see cref="Kind"/>:
|
||||
/// verification, disconnection, throttleStop, throttleEnd, backfillDone, unknownFormat, recipeSuspended, diskLow,
|
||||
/// deliveryFailed. <see cref="Level"/>: error, warning, success, info.
|
||||
/// </summary>
|
||||
public sealed record AlertItemDto(long Id, LocalTimeDto At, string Kind, string Level, string Title, string Message, long? AccountId);
|
||||
|
||||
/// <summary><c>GET /api/alerts</c>: the alerts of the last <see cref="Days"/> days, newest first.</summary>
|
||||
public sealed record AlertListDto(IReadOnlyList<AlertItemDto> Items, int Days);
|
||||
|
||||
/// <summary>The preview of Febe's browser: <see cref="Frame"/> is the address of the JPEG (with a version), or null.</summary>
|
||||
public sealed record BrowserPreviewDto(bool HasFrame, string? Url, long? At, string? Frame);
|
||||
|
||||
|
||||
@@ -152,9 +152,9 @@ public static class SettingsApi
|
||||
}
|
||||
|
||||
var token = body.RemoveTelegramToken ? null : string.IsNullOrWhiteSpace(body.TelegramToken) ? stored.TelegramToken : body.TelegramToken.Trim();
|
||||
if (token is not null && (token.Length > 200 || token.Any(char.IsWhiteSpace)))
|
||||
if (token is not null && !TelegramClient.IsValidToken(token))
|
||||
{
|
||||
throw new BadRequestException("Il gettone del bot non è valido: copialo per intero dal messaggio di BotFather, senza spazi.");
|
||||
throw new BadRequestException("Il gettone del bot non è valido: copialo per intero dal messaggio di BotFather (cifre, due punti, poi una lunga serie di lettere), senza spazi.");
|
||||
}
|
||||
|
||||
var e = body.Events;
|
||||
@@ -186,7 +186,7 @@ public static class SettingsApi
|
||||
throw new BadRequestException("Scrivi il gettone del bot e l'identificativo della chat, salva, poi invia la prova.");
|
||||
}
|
||||
|
||||
var sender = d.Services.GetService(typeof(IAlertTestSender)) as IAlertTestSender ?? new TelegramNotAvailableYet();
|
||||
var sender = d.Services.GetService(typeof(IAlertTestSender)) as IAlertTestSender ?? new NoTelegramSender();
|
||||
var result = await sender.SendTelegramTestAsync(settings, ct).ConfigureAwait(false);
|
||||
return ApiHttp.Json(new AlertTestDto(result.Sent, result.Message), FebeJsonContext.Default.AlertTestDto);
|
||||
});
|
||||
@@ -522,7 +522,7 @@ public static class SettingsApi
|
||||
SystemApi.Capabilities(context, d.Options, d.Shell, d.Browser, d.Clock).Notifications,
|
||||
settings.TelegramChatId,
|
||||
!string.IsNullOrWhiteSpace(settings.TelegramToken),
|
||||
sender is not null and not TelegramNotAvailableYet);
|
||||
sender is not null and not NoTelegramSender);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- Dati
|
||||
|
||||
Reference in new issue
Block a user