Ricerca dei profili con suggerimenti e foto (#37)
«Aggiungi account» ha una sola casella: mentre Alberto scrive compaiono subito i suggerimenti locali, poi i profili di Instagram con la foto, come chiesto in #37. Il browser di Febe scrive nella casella «Cerca» di Instagram con tasti veri da una mappa chiusa (mai Invio, Tab o Esc), controlla prima il fuoco, legge la risposta della pagina e non clicca mai un risultato. La ricerca ha una categoria propria nel Governatore, con tetti larghi che non consumano quelli della raccolta, e si dà il turno con il motore sull'unica pagina; a fine sessione la pagina torna comunque al riposo. Le foto passano dal CDN con un permesso ciascuna e restano solo in memoria. Le risposte di Alberto del 15 novembre (controllo del fuoco, turni, evento requestWillBeSent, niente foto dei seguiti per ora) sono in §6.1 e in docs/decisioni.md. Su Instagram vero la ricerca parte quando i bersagli search-open e search-box saranno raccolti dal vivo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5e417c666d
commit
9941a2fa1f
98 files changed
+8021
-229
No files matched your search
@@ -11,6 +11,12 @@ namespace Febe.Core.Collection.Recipes;
|
||||
/// <param name="Result">What the reader recognized, detached from the body.</param>
|
||||
public sealed record CapturedRead(long Sequence, ResponseDescriptor Response, ReadResult Result);
|
||||
|
||||
/// <summary>
|
||||
/// Where the search answers stood at one moment (issue #37): the last search answer that arrived and the last request
|
||||
/// the page started. Pass it to <see cref="CaptureCollector.SearchSince"/>.
|
||||
/// </summary>
|
||||
public readonly record struct SearchAnswerMark(long Arrival, long Request);
|
||||
|
||||
/// <summary>
|
||||
/// Bridge between the response tap and the recipes (spec §6.2, §6.4): every JSON body the site sends is read by the
|
||||
/// <see cref="ShapeReader"/> as it arrives, and the recipes wait for what they expect after a gesture. Bodies are
|
||||
@@ -23,13 +29,18 @@ public sealed record CapturedRead(long Sequence, ResponseDescriptor Response, Re
|
||||
public sealed class CaptureCollector : IResponseConsumer, IResponseObserver
|
||||
{
|
||||
private const int MaxKept = 2000;
|
||||
private const int MaxSearchKept = 50;
|
||||
|
||||
private readonly ShapeReader _reader;
|
||||
private readonly IClock _clock;
|
||||
private readonly Lock _gate = new();
|
||||
private readonly List<CapturedRead> _reads = [];
|
||||
private readonly List<CapturedRead> _searchReads = [];
|
||||
private readonly Dictionary<string, DateTimeOffset> _pending = new(StringComparer.Ordinal);
|
||||
private long _sequence;
|
||||
private long _searchSequence;
|
||||
private long _lastRequestOrder;
|
||||
private DateTimeOffset? _lastArrivalAt;
|
||||
private string? _viewerId;
|
||||
|
||||
public CaptureCollector(ShapeReader reader, IClock clock)
|
||||
@@ -82,6 +93,46 @@ public sealed class CaptureCollector : IResponseConsumer, IResponseObserver
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Where the search box answers stand now (issue #37): pass it to <see cref="SearchSince"/>. Search answers have
|
||||
/// their own buffer, so recipe windows (<see cref="Mark"/>, <see cref="Since"/>) never see them. Taken right before
|
||||
/// a key, it separates the requests the page started for the texts before that key from the ones after it.
|
||||
/// </summary>
|
||||
public SearchAnswerMark SearchMark()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
return new SearchAnswerMark(_searchSequence, _lastRequestOrder);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search box answers to requests the page started after <paramref name="mark"/>, oldest request first. An answer
|
||||
/// whose request order is unknown counts by its arrival instead.
|
||||
/// </summary>
|
||||
public IReadOnlyList<CapturedRead> SearchSince(SearchAnswerMark mark)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
return [.. _searchReads
|
||||
.Where(r => r.Response.RequestOrder > 0 ? r.Response.RequestOrder > mark.Request : r.Sequence > mark.Arrival)
|
||||
.OrderBy(r => r.Response.RequestOrder)
|
||||
.ThenBy(r => r.Sequence)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>When the body of the last response of the site was read (any kind, unrelated ones included).</summary>
|
||||
public DateTimeOffset? LastArrivalAt
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
return _lastArrivalAt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Data responses whose body has not been read yet.</summary>
|
||||
public int Pending
|
||||
{
|
||||
@@ -178,14 +229,31 @@ public sealed class CaptureCollector : IResponseConsumer, IResponseObserver
|
||||
|
||||
var result = _reader.Read(body);
|
||||
Observe(response, result, body);
|
||||
if (result.ViewerId is { } viewerId)
|
||||
lock (_gate)
|
||||
{
|
||||
lock (_gate)
|
||||
_lastArrivalAt = _clock.Now;
|
||||
if (result.ViewerId is { } viewerId)
|
||||
{
|
||||
_viewerId = viewerId;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.Search is not null)
|
||||
{
|
||||
// A search box answer goes to its own buffer: it never stops, fills or judges a recipe (issue #37).
|
||||
lock (_gate)
|
||||
{
|
||||
var found = new CapturedRead(++_searchSequence, response, result);
|
||||
_searchReads.Add(found);
|
||||
if (_searchReads.Count > MaxSearchKept)
|
||||
{
|
||||
_searchReads.RemoveRange(0, _searchReads.Count - MaxSearchKept);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.Shape == ReadShape.Unrelated)
|
||||
{
|
||||
// Not about contents (promotions, logging): neither data nor an empty page, and not «something new
|
||||
@@ -241,6 +309,17 @@ public sealed class CaptureCollector : IResponseConsumer, IResponseObserver
|
||||
}
|
||||
}
|
||||
|
||||
void IResponseObserver.OnRequestStarted(long order)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (order > _lastRequestOrder)
|
||||
{
|
||||
_lastRequestOrder = order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IResponseObserver.OnBodyDropped(string requestId)
|
||||
{
|
||||
lock (_gate)
|
||||
|
||||
Reference in new issue
Block a user