House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s
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:
1 parent
f0a14c737f
commit
0f73f69239
176 files changed
+2789
-3974
No files matched your search
+24
-53
@@ -41,18 +41,12 @@ namespace PrivaPub.Web.Pages
|
||||
}
|
||||
}
|
||||
|
||||
public class ProfileModel : PublicPageModel
|
||||
public class ProfileModel(
|
||||
ILocalActorService localActors,
|
||||
DbEntities dbEntities) : PublicPageModel
|
||||
{
|
||||
const int PageSize = 20;
|
||||
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly DbEntities _dbEntities;
|
||||
|
||||
public ProfileModel(ILocalActorService localActors, DbEntities dbEntities)
|
||||
{
|
||||
_localActors = localActors;
|
||||
_dbEntities = dbEntities;
|
||||
}
|
||||
|
||||
public LocalActor Actor { get; private set; }
|
||||
public string BiographyHtml { get; private set; }
|
||||
@@ -60,7 +54,7 @@ namespace PrivaPub.Web.Pages
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(string user, CancellationToken token)
|
||||
{
|
||||
Actor = await _localActors.FindByUserName(user, token);
|
||||
Actor = await localActors.FindByUserName(user, token);
|
||||
if (Actor is not { IsFederated: true, IsCircle: false, Suspended: false } || Actor.IsServerActor)
|
||||
return NotFound();
|
||||
if (WantsActivityJson())
|
||||
@@ -69,8 +63,8 @@ namespace PrivaPub.Web.Pages
|
||||
Harden();
|
||||
BiographyHtml = ActivityPubRenderer.Html(Actor.Summary);
|
||||
var posts = await (Actor.Kind == LocalActorKind.Group
|
||||
? _dbEntities.Posts.Match(p => p.GroupId == Actor.Id)
|
||||
: _dbEntities.Posts.Match(p => p.GroupUserId == Actor.Id && !p.IsFederatedCopy))
|
||||
? dbEntities.Posts.Match(p => p.GroupId == Actor.Id)
|
||||
: dbEntities.Posts.Match(p => p.GroupUserId == Actor.Id && !p.IsFederatedCopy))
|
||||
.Match(VisibilityPolicy.IsPublic)
|
||||
.Match(p => p.ReblogOfPostId == null)
|
||||
.Sort(p => p.ID, Order.Descending)
|
||||
@@ -83,7 +77,7 @@ namespace PrivaPub.Web.Pages
|
||||
if (post.IsFederatedCopy)
|
||||
continue;
|
||||
if (!authors.TryGetValue(post.GroupUserId, out var author))
|
||||
authors[post.GroupUserId] = author = await _localActors.FindById(LocalActorKind.Person, post.GroupUserId, token);
|
||||
authors[post.GroupUserId] = author = await localActors.FindById(LocalActorKind.Person, post.GroupUserId, token);
|
||||
if (author is { Suspended: false })
|
||||
views.Add(PostView.From(post, author));
|
||||
}
|
||||
@@ -93,18 +87,12 @@ namespace PrivaPub.Web.Pages
|
||||
}
|
||||
|
||||
// The hashtag links our posts carry (/tags/{tag}): this server's public posts with that tag, as a page like a profile's.
|
||||
public class TagModel : PublicPageModel
|
||||
public class TagModel(
|
||||
ILocalActorService localActors,
|
||||
DbEntities dbEntities) : PublicPageModel
|
||||
{
|
||||
const int PageSize = 20;
|
||||
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly DbEntities _dbEntities;
|
||||
|
||||
public TagModel(ILocalActorService localActors, DbEntities dbEntities)
|
||||
{
|
||||
_localActors = localActors;
|
||||
_dbEntities = dbEntities;
|
||||
}
|
||||
|
||||
public string Tag { get; private set; }
|
||||
public IReadOnlyList<PostView> Posts { get; private set; } = Array.Empty<PostView>();
|
||||
@@ -115,7 +103,7 @@ namespace PrivaPub.Web.Pages
|
||||
if (string.IsNullOrEmpty(Tag) || Tag.Length > 100)
|
||||
return NotFound();
|
||||
Harden();
|
||||
var posts = await _dbEntities.Posts
|
||||
var posts = await dbEntities.Posts
|
||||
.Match(p => p.Tags.Contains(Tag) && !p.IsFederatedCopy && p.ReblogOfPostId == null && p.Visibility == PostVisibility.Public)
|
||||
.Match(VisibilityPolicy.IsPublic)
|
||||
.Match(VisibilityPolicy.IsListed)
|
||||
@@ -127,7 +115,7 @@ namespace PrivaPub.Web.Pages
|
||||
foreach (var post in posts)
|
||||
{
|
||||
if (!authors.TryGetValue(post.GroupUserId, out var author))
|
||||
authors[post.GroupUserId] = author = await _localActors.FindById(LocalActorKind.Person, post.GroupUserId, token);
|
||||
authors[post.GroupUserId] = author = await localActors.FindById(LocalActorKind.Person, post.GroupUserId, token);
|
||||
if (author is { IsFederated: true, Suspended: false })
|
||||
views.Add(PostView.From(post, author));
|
||||
}
|
||||
@@ -136,27 +124,20 @@ namespace PrivaPub.Web.Pages
|
||||
}
|
||||
}
|
||||
|
||||
public class StatusModel : PublicPageModel
|
||||
public class StatusModel(
|
||||
ILocalActorService localActors,
|
||||
DbEntities dbEntities) : PublicPageModel
|
||||
{
|
||||
readonly ILocalActorService _localActors;
|
||||
readonly DbEntities _dbEntities;
|
||||
|
||||
public StatusModel(ILocalActorService localActors, DbEntities dbEntities)
|
||||
{
|
||||
_localActors = localActors;
|
||||
_dbEntities = dbEntities;
|
||||
}
|
||||
|
||||
public LocalActor Actor { get; private set; }
|
||||
public PostView Post { get; private set; }
|
||||
public string ObjectUri { get; private set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(string user, string id, CancellationToken token)
|
||||
{
|
||||
Actor = await _localActors.FindByUserName(user, token);
|
||||
Actor = await localActors.FindByUserName(user, token);
|
||||
if (Actor is not { IsFederated: true, Kind: LocalActorKind.Person, Suspended: false })
|
||||
return NotFound();
|
||||
var post = await _dbEntities.Posts
|
||||
var post = await dbEntities.Posts
|
||||
.Match(p => p.ID == id && p.GroupUserId == Actor.Id && !p.IsFederatedCopy && p.ReblogOfPostId == null)
|
||||
.Match(VisibilityPolicy.IsPublic)
|
||||
.ExecuteFirstAsync(token);
|
||||
@@ -172,24 +153,14 @@ namespace PrivaPub.Web.Pages
|
||||
}
|
||||
}
|
||||
|
||||
public class StargazingModel : PublicPageModel
|
||||
public class StargazingModel(
|
||||
Microsoft.Extensions.Options.IOptionsMonitor<Infrastructure.Statistics.StatisticsOptions> options,
|
||||
Microsoft.Extensions.Options.IOptionsMonitor<Models.AppConfiguration> app,
|
||||
Infrastructure.Geo.IGeoLocator geo) : PublicPageModel
|
||||
{
|
||||
readonly Microsoft.Extensions.Options.IOptionsMonitor<Infrastructure.Statistics.StatisticsOptions> _options;
|
||||
readonly Microsoft.Extensions.Options.IOptionsMonitor<Models.AppConfiguration> _app;
|
||||
|
||||
readonly Infrastructure.Geo.IGeoLocator _geo;
|
||||
|
||||
public StargazingModel(Microsoft.Extensions.Options.IOptionsMonitor<Infrastructure.Statistics.StatisticsOptions> options,
|
||||
Microsoft.Extensions.Options.IOptionsMonitor<Models.AppConfiguration> app, Infrastructure.Geo.IGeoLocator geo)
|
||||
{
|
||||
_options = options;
|
||||
_app = app;
|
||||
_geo = geo;
|
||||
}
|
||||
|
||||
public bool CrawlerEnabled => _options.CurrentValue.Crawler.Enabled;
|
||||
public string GeoSource => _geo.Source;
|
||||
public string UserAgent => Federation.Crawler.Stargazer.UserAgent(_app.CurrentValue.BackendBaseAddress);
|
||||
public bool CrawlerEnabled => options.CurrentValue.Crawler.Enabled;
|
||||
public string GeoSource => geo.Source;
|
||||
public string UserAgent => Federation.Crawler.Stargazer.UserAgent(app.CurrentValue.BackendBaseAddress);
|
||||
|
||||
public void OnGet() => Harden();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user