CDN-fronted servers grouped per CDN, and servers through time
Build / Build (push) Successful in 26s
Deploy / decepub.thepra.dev (push) Successful in 1m21s

A post whose server is behind a CDN has no place of its own: the globe
groups such posts per CDN in labels on a ring above the Arctic, and
hovering one draws its arc to the CDN's group and a ring where the
server was before the CDN. The card's CDN chip names the CDN, its
domain, how PrivaPub found it (published ranges, response headers or
network), the place before the CDN and the CDN's servers week by week
(/api/privapub/v1/cdns/:domain); the author's tooltip lists the server's
changes of place and CDN week by week (/instances/:host/history). Both
are read on the first hover and kept for the session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
thepraandClaude Opus 5.5 committed 2026-10-04 11:44:51 +02:00
1 parent 5ec70b3357
commit 620cbef219
12 files changed
+386 -41

No files matched your search

+42 -1
View File
@@ -13,7 +13,8 @@ namespace decePubClient.Services
/// What PrivaPub knows about the servers the feed shows (/api/privapub/v1/instances, up to 40 at once), cached in
/// memory and localStorage for a day, and where each feed item is drawn. A post is placed, best first: at its own
/// place (Pixelfed), at its event's venue, at the reader for a located post, at its author's server (0.1°), or at a
/// point in the server's country when PrivaPub publishes only that. A CDN-fronted server has no place.
/// point in the server's country when PrivaPub located it only to a country. A CDN-fronted server has no place: its
/// posts join their CDN's group. A server's weekly history and a CDN's page are read on demand, once per session.
/// </summary>
public class InstanceService(IHttpService httpService, ILocalStorageService localStorage, AppConfiguration appConfiguration, ILoggingService logger)
{
@@ -23,6 +24,8 @@ namespace decePubClient.Services
static readonly TimeSpan UnknownLifetime = TimeSpan.FromHours(1);
readonly Dictionary<string, ServerInfo> servers = new(StringComparer.OrdinalIgnoreCase);
readonly Dictionary<string, List<InstanceWeek>> histories = new(StringComparer.OrdinalIgnoreCase);
readonly Dictionary<string, CdnDetail> cdns = new(StringComparer.OrdinalIgnoreCase);
bool loaded;
string selfHost;
@@ -71,6 +74,41 @@ namespace decePubClient.Services
await Save(cancellationToken);
}
public List<InstanceWeek> KnownHistory(string host) => host is not null ? histories.GetValueOrDefault(host) : null;
public CdnDetail KnownCdn(string key) => key is not null ? cdns.GetValueOrDefault(key) : null;
/// <summary>The server's weekly snapshots, newest first; empty when PrivaPub has none.</summary>
public async Task<List<InstanceWeek>> History(string host, CancellationToken cancellationToken = default)
{
if (host is null)
return [];
if (KnownHistory(host) is { } known)
return known;
using var response = await httpService.GetAnon(APIs.PrivaPub.GET_M_InstanceHistory(host), [$"weeks=52"], cancellationToken: cancellationToken);
var history = response.IsSuccessStatusCode ? await response.MastodonReadFromJsonAsync<List<InstanceWeek>>(cancellationToken) ?? [] : [];
histories[host] = history;
return history;
}
/// <summary>A CDN's servers and its weeks, or null when PrivaPub does not know it.</summary>
public async Task<CdnDetail> Cdn(string key, CancellationToken cancellationToken = default)
{
if (key is null)
return null;
if (KnownCdn(key) is { } known)
return known;
using var response = await httpService.GetAnon(APIs.PrivaPub.GET_M_Cdn(key), [$"weeks=12"], cancellationToken: cancellationToken);
if (!response.IsSuccessStatusCode)
return null;
var cdn = await response.MastodonReadFromJsonAsync<CdnDetail>(cancellationToken);
if (cdn is not null)
cdns[key] = cdn;
return cdn;
}
/// <summary>Places each post; nearYou is the reader's position, for located posts.</summary>
public void Locate(IEnumerable<FeedPost> posts, (double Latitude, double Longitude)? nearYou = default)
{
@@ -90,6 +128,9 @@ namespace decePubClient.Services
return new(reader.Latitude, reader.Longitude, LocationSource.NearYou, null, post.RangeKm ?? 5);
var geo = Known(post.Host)?.Geo;
if (geo?.Cdn is { Length: > 0 } cdn)
return new(0, 0, LocationSource.Cdn, cdn, 0, geo.CdnDomain ?? cdn.ToLowerInvariant(), geo.BeforeCdn);
if (geo is { Latitude: { } latitude, Longitude: { } longitude })
return new(latitude, longitude, LocationSource.Server, JoinLabel(geo.City, CountryName(geo.Country)), 11);