23 lines
971 B
C#
23 lines
971 B
C#
using PrivaPub.Models.Jobs;
|
|||
|
|
|
||
|
|
namespace PrivaPub.Domain.Statistics
|
||
|
|
{
|
||
|
|
public sealed record PublicLocation(string Country, string City, double? Latitude, double? Longitude, string Network, string Cdn);
|
||
|
|
|
||
|
|
public static class PublicGeo
|
||
|
|
{
|
||
|
|
//owner decision: a CDN-fronted server shows only its CDN (the address is an edge), a server reporting at least
|
||
|
|
//minUsers users its city, coordinates and network, any other only its country
|
||
|
|
public static PublicLocation Project(RemoteInstance instance, int minUsers)
|
||
|
|
{
|
||
|
|
var geo = instance?.Geo;
|
||
|
|
if (geo == default)
|
||
|
|
return default;
|
||
|
|
if (geo.Cdn != default)
|
||
|
|
return new PublicLocation(default, default, default, default, default, geo.Cdn);
|
||
|
|
if (instance.UsersTotal >= minUsers)
|
||
|
|
return new PublicLocation(geo.Country, geo.City, geo.Latitude, geo.Longitude, geo.AsnOrg, default);
|
||
|
|
return geo.Country == default ? default : new PublicLocation(geo.Country, default, default, default, default, default);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|