Raccolta (M0/M2): sito di prova completo, lettori per forma, ricette su browser vero, coda degli scaricamenti, sonda con ripulitura e verifica; documenti delle ipotesi e delle prove dal vivo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
74 files changed
+12689
-13
No files matched your search
@@ -15,7 +15,14 @@ namespace Febe.Browser.Targets;
|
||||
/// <param name="HrefPattern">Link shape on the path, e.g. «/{username}/», «/stories/**»: {name} or * is one segment, ** the rest.</param>
|
||||
/// <param name="Index">Which of the visible matches, in document order (0 = first, -1 = last).</param>
|
||||
/// <param name="Hypothesis">Hypothesis of spec §6.6 the target depends on (e.g. «H11»), when not yet confirmed.</param>
|
||||
public sealed record TargetSpec(string Id, IReadOnlyList<string> Roles, string? NamePattern, string? HrefPattern, int Index, string? Hypothesis);
|
||||
public sealed record TargetSpec(string Id, IReadOnlyList<string> Roles, string? NamePattern, string? HrefPattern, int Index, string? Hypothesis)
|
||||
{
|
||||
/// <summary>
|
||||
/// False for a placeholder of a skeleton map (role, name and href written but empty, e.g. the first
|
||||
/// <c>bersagli.instagram.json</c>): looking it up gives <see cref="TargetStatus.NotConfigured"/> without touching the page.
|
||||
/// </summary>
|
||||
public bool IsConfigured => Roles.Count > 0 || NamePattern is not null || HrefPattern is not null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The target map of one site (<c>bersagli.instagram.json</c>, <c>bersagli.prova.json</c>), editable without
|
||||
@@ -62,6 +69,14 @@ public sealed partial class TargetMap
|
||||
|
||||
public static TargetMap Load(string path) => Parse(File.ReadAllText(path), path);
|
||||
|
||||
/// <summary>A map shipped with Febe.Core (<c>bersagli.prova.json</c>, <c>bersagli.instagram.json</c>).</summary>
|
||||
public static TargetMap LoadEmbedded(string fileName) =>
|
||||
Parse(Febe.Core.Collection.SiteMap.ReadEmbeddedText(fileName), fileName);
|
||||
|
||||
/// <summary>Loads <paramref name="path"/> when it exists, otherwise the embedded file with the same name.</summary>
|
||||
public static TargetMap LoadOrEmbedded(string? path, string embeddedName) =>
|
||||
!string.IsNullOrEmpty(path) && File.Exists(path) ? Load(path) : LoadEmbedded(embeddedName);
|
||||
|
||||
public static TargetMap Parse(string json, string? source = null)
|
||||
{
|
||||
var name = source ?? "bersagli";
|
||||
@@ -92,9 +107,12 @@ public sealed partial class TargetMap
|
||||
var roles = (dto.Role ?? string.Empty).Split('|', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Select(r => r.ToLowerInvariant())
|
||||
.ToArray();
|
||||
if (roles.Length == 0 && string.IsNullOrWhiteSpace(dto.Name) && string.IsNullOrWhiteSpace(dto.Href))
|
||||
// A skeleton entry writes the three keys empty on purpose (still to be filled from the M0 samples);
|
||||
// an entry that names none of them is a mistake.
|
||||
var placeholder = dto.Role is not null && dto.Name is not null && dto.Href is not null;
|
||||
if (roles.Length == 0 && string.IsNullOrWhiteSpace(dto.Name) && string.IsNullOrWhiteSpace(dto.Href) && !placeholder)
|
||||
{
|
||||
throw new InvalidDataException($"{where}: serve almeno uno fra «role», «name» e «href».");
|
||||
throw new InvalidDataException($"{where}: serve almeno uno fra «role», «name» e «href» (vuoti tutti e tre per una voce ancora da compilare).");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(dto.Name))
|
||||
@@ -196,6 +214,9 @@ internal sealed class TargetMapFile
|
||||
|
||||
public string? Note { get; set; }
|
||||
|
||||
/// <summary>Page addresses: read by <c>Febe.Core.Collection.SiteMap</c>, accepted and ignored here.</summary>
|
||||
public Dictionary<string, JsonElement>? Pages { get; set; }
|
||||
|
||||
public Dictionary<string, TargetDto>? Targets { get; set; }
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user