House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s

- Services, controllers and jobs take their dependencies through primary
  constructors and use them directly; where a method already named a local
  after a dependency, the dependency takes its type's name.
- Every async method takes a CancellationToken last and passes it down to
  MongoDB, HTTP and the job queue. The setup claim is still given back when
  a request is cancelled.
- The federation and media options are read through IOptionsMonitor.
- The Mastodon entities keep sending "" for empty strings, and every model
  field where null means something says so.
- The inbox's 503 with Retry-After, which other servers retry, is the one
  server error left, and says why.
- Arasaka.HouseRules.Analyzers checks all of this in every build, here and in
  PrivaPub.ClientModels as decePubClient builds it.

Checked against GoToSocial in the pasture: 64 passed, 0 failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
thepraandClaude Opus 5.5 committed 2026-11-10 01:24:43 +01:00
1 parent f0a14c737f
commit 0f73f69239
176 files changed
+2789 -3974

No files matched your search

@@ -18,31 +18,20 @@ using PrivaPub.Infrastructure;
namespace PrivaPub.Federation.Controllers
{
[ApiController]
public class WellKnownController : ControllerBase
public class WellKnownController(
ILocalActorService localActors,
IOptionsMonitor<RegistrationOptions> registrations,
Domain.Instance.IInstanceSettings settings) : ControllerBase
{
readonly ILocalActorService _localActors;
readonly DbEntities _dbEntities;
readonly IOptionsMonitor<RegistrationOptions> _registrations;
readonly Domain.Instance.IInstanceSettings _settings;
public WellKnownController(ILocalActorService localActors, DbEntities dbEntities, IOptionsMonitor<RegistrationOptions> registrations,
Domain.Instance.IInstanceSettings settings)
{
_registrations = registrations;
_settings = settings;
_localActors = localActors;
_dbEntities = dbEntities;
}
[HttpGet, Route("/.well-known/webfinger")]
public async Task<IActionResult> WebFinger([FromQuery] string resource, CancellationToken token)
{
if (string.IsNullOrEmpty(resource))
return BadRequest();
// the server itself (FEP-d556): its instance actor
if (resource.TrimEnd('/') == _localActors.BaseAddress)
if (resource.TrimEnd('/') == localActors.BaseAddress)
{
var instance = await _localActors.GetInstanceActor(token);
var instance = await localActors.GetInstanceActor(token);
return Content(new JsonObject
{
["subject"] = resource,
@@ -53,7 +42,7 @@ namespace PrivaPub.Federation.Controllers
}.ToJsonString(), "application/jrd+json; charset=utf-8");
}
LocalActor actor;
var actor = default(LocalActor);
// Mastodon, GoToSocial and Pleroma also take a bare user@domain or @user@domain, so we do too.
var acct = resource.StartsWith("acct:", StringComparison.OrdinalIgnoreCase) ? resource[5..]
: !resource.Contains("://", StringComparison.Ordinal) && resource.Contains('@') ? resource
@@ -61,15 +50,15 @@ namespace PrivaPub.Federation.Controllers
if (acct != default)
{
var parts = acct.TrimStart('@').Split('@');
var domain = new Uri(_localActors.BaseAddress).Authority;
var domain = new Uri(localActors.BaseAddress).Authority;
if (parts.Length != 2 || !parts[1].Equals(domain, StringComparison.OrdinalIgnoreCase))
return NotFound();
actor = await _localActors.FindByUserName(parts[0], token);
if (actor == default && await _localActors.Gone(parts[0], token) != default)
actor = await localActors.FindByUserName(parts[0], token);
if (actor == default && await localActors.Gone(parts[0], token) != default)
return StatusCode(StatusCodes.Status410Gone);
}
else
actor = await _localActors.FindByUri(resource, token);
actor = await localActors.FindByUri(resource, token);
if (actor is not { IsFederated: true })
return NotFound();
@@ -96,18 +85,18 @@ namespace PrivaPub.Federation.Controllers
new JsonObject
{
["rel"] = "http://nodeinfo.diaspora.software/ns/schema/2.1",
["href"] = $"{_localActors.BaseAddress}/nodeinfo/2.1"
["href"] = $"{localActors.BaseAddress}/nodeinfo/2.1"
},
new JsonObject
{
["rel"] = "http://nodeinfo.diaspora.software/ns/schema/2.0",
["href"] = $"{_localActors.BaseAddress}/nodeinfo/2.0"
["href"] = $"{localActors.BaseAddress}/nodeinfo/2.0"
},
// the application actor (FEP-2677)
new JsonObject
{
["rel"] = "https://www.w3.org/ns/activitystreams#Application",
["href"] = (await _localActors.GetInstanceActor(token)).Uri
["href"] = (await localActors.GetInstanceActor(token)).Uri
})
};
return Content(document.ToJsonString(), "application/json; charset=utf-8");
@@ -130,7 +119,7 @@ namespace PrivaPub.Federation.Controllers
["software"] = software,
["protocols"] = new JsonArray("activitypub"),
["services"] = new JsonObject { ["inbound"] = new JsonArray(), ["outbound"] = new JsonArray() },
["openRegistrations"] = _registrations.CurrentValue.IsOpen,
["openRegistrations"] = registrations.CurrentValue.IsOpen,
["usage"] = new JsonObject
{
["users"] = new JsonObject
@@ -144,8 +133,8 @@ namespace PrivaPub.Federation.Controllers
["metadata"] = new JsonObject
{
// the server's name and short description, as its administrator set them (IInstanceSettings)
["nodeName"] = _settings.Current.Title,
["nodeDescription"] = _settings.Current.ShortDescription ?? string.Empty,
["nodeName"] = settings.Current.Title,
["nodeDescription"] = settings.Current.ShortDescription ?? string.Empty,
["federation"] = new JsonObject { ["document"] = "https://git.thepra.dev/thepra/SocialPub/src/branch/master/FEDERATION.md" }
}
};