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
@@ -6,7 +6,8 @@ namespace Febe.SitoDiProva;
|
||||
/// <summary>
|
||||
/// The JSON the pages fetch, in the site's own synthetic format (LEGGIMI.md). It is what the response tap captures
|
||||
/// and what the readers of <c>lettori.prova.json</c> read. Keys are Italian and the shape is ours: it does not
|
||||
/// imitate Instagram.
|
||||
/// imitate Instagram. One exception: the answer of the search box (<see cref="Search"/>) has the shape of the cleaned
|
||||
/// Instagram sample, so the search of Febe is exercised end to end on the real format (issue #37).
|
||||
/// </summary>
|
||||
public sealed class DataApi(World world, CdnSigner signer, SiteControl control, Func<string> cdnBase, TimeProvider time)
|
||||
{
|
||||
@@ -168,6 +169,87 @@ public sealed class DataApi(World world, CdnSigner signer, SiteControl control,
|
||||
|
||||
public static string Cursor(int offset) => "c" + offset.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>
|
||||
/// The answer of the search box: up to <see cref="SearchSize"/> profiles whose name or display name contains the text
|
||||
/// (accents folded), the ones that start with it first. The shape and keys are those of the cleaned Instagram sample
|
||||
/// «ricerca-profili» (PolarisSearchBoxRefetchableQuery), and only keys present there: no «is_private», no
|
||||
/// «friendship_status», no echo of the text.
|
||||
/// </summary>
|
||||
public JsonObject Search(string text)
|
||||
{
|
||||
var wanted = Fold(text.Trim());
|
||||
var users = new JsonArray();
|
||||
if (wanted.Length > 0)
|
||||
{
|
||||
var found = world.Accounts
|
||||
.Where(a => !a.IsViewer)
|
||||
.Select(a => (Account: a, Name: Fold(a.Username), Display: Fold(a.DisplayName)))
|
||||
.Where(x => x.Name.Contains(wanted, StringComparison.Ordinal) || x.Display.Contains(wanted, StringComparison.Ordinal))
|
||||
.OrderBy(x => x.Name.StartsWith(wanted, StringComparison.Ordinal) || x.Display.StartsWith(wanted, StringComparison.Ordinal) ? 0 : 1)
|
||||
.ThenBy(x => x.Name, StringComparer.Ordinal)
|
||||
.Take(SearchSize)
|
||||
.ToList();
|
||||
var position = 0;
|
||||
foreach (var (account, _, _) in found)
|
||||
{
|
||||
var small = Version(account.PictureKey, 150, 150, video: false)["indirizzo"]!.GetValue<string>();
|
||||
var large = Version(account.PictureKey, 320, 320, video: false)["indirizzo"]!.GetValue<string>();
|
||||
users.Add(new JsonObject
|
||||
{
|
||||
["position"] = position++,
|
||||
["user"] = new JsonObject
|
||||
{
|
||||
["username"] = account.Username,
|
||||
["is_verified"] = false,
|
||||
["full_name"] = account.DisplayName,
|
||||
["pk"] = account.Id,
|
||||
["profile_pic_url"] = small,
|
||||
["hd_profile_pic_url_info"] = new JsonObject { ["url"] = large },
|
||||
["id"] = account.Id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return new JsonObject
|
||||
{
|
||||
["data"] = new JsonObject
|
||||
{
|
||||
["xdt_api__v1__fbsearch__topsearch_connection"] = new JsonObject
|
||||
{
|
||||
["hashtags"] = new JsonArray(),
|
||||
["places"] = new JsonArray(),
|
||||
["users"] = users,
|
||||
},
|
||||
},
|
||||
["extensions"] = new JsonObject { ["is_final"] = true },
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The «ricerche recenti» shown when the search panel opens: the site's own format, never read by Febe.</summary>
|
||||
public JsonObject RecentSearches(IReadOnlyList<string> names) => new()
|
||||
{
|
||||
["recenti"] = new JsonArray([.. names.Select(n => (JsonNode)new JsonObject { ["voce"] = n })]),
|
||||
};
|
||||
|
||||
/// <summary>Profiles in one search answer.</summary>
|
||||
public const int SearchSize = 8;
|
||||
|
||||
private static string Fold(string text)
|
||||
{
|
||||
var decomposed = text.ToLowerInvariant().Normalize(System.Text.NormalizationForm.FormD);
|
||||
var builder = new System.Text.StringBuilder(decomposed.Length);
|
||||
foreach (var c in decomposed)
|
||||
{
|
||||
if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
|
||||
{
|
||||
builder.Append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private static JsonObject Page(int total, int offset, int size)
|
||||
{
|
||||
var more = offset + size < total;
|
||||
|
||||
Reference in new issue
Block a user