Ossatura del progetto: soluzione, contratti, specifica, mockup, carattere e icone
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
123 files changed
+3763
-1
No files matched your search
@@ -0,0 +1,116 @@
|
||||
namespace Febe.Core.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Categories of counted actions toward the site (spec §7.4). Each has an hourly and a daily budget,
|
||||
/// except <see cref="DataDownload"/>, which has a daily byte budget.
|
||||
/// </summary>
|
||||
public enum ActionKind
|
||||
{
|
||||
/// <summary>Opening the home page (Giro dei seguiti).</summary>
|
||||
Home,
|
||||
|
||||
/// <summary>Opening a profile page.</summary>
|
||||
ProfileOpen,
|
||||
|
||||
/// <summary>One story shown in the viewer (stories and highlight items).</summary>
|
||||
StoryView,
|
||||
|
||||
/// <summary>One page of history loaded by scrolling (Storico, Taggati, Reel).</summary>
|
||||
BackfillPage,
|
||||
|
||||
/// <summary>Opening a single post page.</summary>
|
||||
SinglePost,
|
||||
|
||||
/// <summary>One page of the list of profiles Alberto follows.</summary>
|
||||
FollowingListPage,
|
||||
|
||||
/// <summary>Bytes downloaded from the CDN (daily byte budget).</summary>
|
||||
DataDownload,
|
||||
}
|
||||
|
||||
/// <summary>Why the Governor refused an action. Shown in the interface.</summary>
|
||||
public enum DenialReason
|
||||
{
|
||||
None,
|
||||
BreakerOpen,
|
||||
OutsideActiveWindow,
|
||||
NoSession,
|
||||
HourlyBudgetReached,
|
||||
DailyBudgetReached,
|
||||
MinimumSpacing,
|
||||
AccountLimitReached,
|
||||
UserIsDriving,
|
||||
Paused,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Governor's answer to a request: either a permission or a motivated refusal (spec §7.4).
|
||||
/// </summary>
|
||||
public sealed record Permit(bool Granted, ActionKind Kind, long? AccountId, DenialReason Reason, string? Message, DateTimeOffset? RetryAfter)
|
||||
{
|
||||
public static Permit Grant(ActionKind kind, long? accountId) =>
|
||||
new(true, kind, accountId, DenialReason.None, null, null);
|
||||
|
||||
public static Permit Deny(ActionKind kind, long? accountId, DenialReason reason, string message, DateTimeOffset? retryAfter = null) =>
|
||||
new(false, kind, accountId, reason, message, retryAfter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The single point through which every engine action toward the site passes (spec §2 rule 7, §7.4).
|
||||
/// No code path may load an Instagram page or perform a gesture on it without a granted permit.
|
||||
/// </summary>
|
||||
public interface IGovernor
|
||||
{
|
||||
Task<Permit> RequestAsync(ActionKind kind, long? accountId, CancellationToken ct);
|
||||
}
|
||||
|
||||
/// <summary>Severity levels of stop signals (spec §7.6).</summary>
|
||||
public enum SignalLevel
|
||||
{
|
||||
/// <summary>Rallentamento: timed stop (1h, 6h, 24h), then halved budgets for 48 hours.</summary>
|
||||
Throttle,
|
||||
|
||||
/// <summary>Verifica: stops everything until Alberto resumes by hand.</summary>
|
||||
Challenge,
|
||||
|
||||
/// <summary>Disconnessione: as Challenge; never tries to log back in.</summary>
|
||||
Disconnect,
|
||||
}
|
||||
|
||||
/// <summary>A stop signal reported by recipes or by the response capture.</summary>
|
||||
/// <param name="Level">Severity.</param>
|
||||
/// <param name="Code">Stable identifier of the signal, e.g. "http-429" or "challenge-url" (from segnali.json).</param>
|
||||
/// <param name="Url">Address where it was seen, without query string (never secrets).</param>
|
||||
/// <param name="At">When it was seen.</param>
|
||||
public sealed record Signal(SignalLevel Level, string Code, string? Url, DateTimeOffset At);
|
||||
|
||||
/// <summary>State of the circuit breaker (Interruttore).</summary>
|
||||
public enum BreakerStatus
|
||||
{
|
||||
/// <summary>Normal operation.</summary>
|
||||
Closed,
|
||||
|
||||
/// <summary>Timed stop after a throttle signal; reopens by itself at <see cref="BreakerState.Until"/>.</summary>
|
||||
Throttled,
|
||||
|
||||
/// <summary>Stopped after a challenge: needs Alberto and «Riprendi».</summary>
|
||||
Challenge,
|
||||
|
||||
/// <summary>Stopped after a disconnection: needs Alberto and «Riprendi».</summary>
|
||||
Disconnected,
|
||||
}
|
||||
|
||||
public sealed record BreakerState(BreakerStatus Status, DateTimeOffset? Until, Signal? LastSignal, DateTimeOffset? HalvedBudgetsUntil)
|
||||
{
|
||||
public static readonly BreakerState Normal = new(BreakerStatus.Closed, null, null, null);
|
||||
|
||||
public bool AllowsSiteActions => Status == BreakerStatus.Closed;
|
||||
}
|
||||
|
||||
/// <summary>The circuit breaker (spec §7.6). Every stop is persisted as an incident.</summary>
|
||||
public interface ICircuitBreaker
|
||||
{
|
||||
BreakerState State { get; }
|
||||
|
||||
void Report(Signal signal);
|
||||
}
|
||||
Reference in new issue
Block a user