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

@@ -26,23 +26,15 @@ namespace PrivaPub.Controllers.ClientToServer
[ApiController,
Route("clientapi/admin/emoji"),
Authorize(Policy = Policies.IsAdmin)]
public class EmojiAdminController : ControllerBase
public class EmojiAdminController(
IModerationLog log,
IStringLocalizer<GenericRes> localizer,
IMediaService media,
ILocalActorService localActors) : ControllerBase
{
// a picture up to a megabyte reaches EmojiImage, which refuses one over 256 KB with its reason
const long MaxRequestBytes = 1024 * 1024;
readonly IModerationLog _log;
readonly IStringLocalizer _localizer;
readonly IMediaService _media;
readonly ILocalActorService _localActors;
public EmojiAdminController(IModerationLog log, IStringLocalizer<GenericRes> localizer, IMediaService media, ILocalActorService localActors)
{
_log = log;
_localizer = localizer;
_media = media;
_localActors = localActors;
}
// the token says administrator; the database has the last word
async Task<RootUser> Administrator(CancellationToken token)
@@ -51,7 +43,7 @@ namespace PrivaPub.Controllers.ClientToServer
return root is { IsBanned: false, DeletedAt: null } && root.Policies.Contains(Policies.IsAdmin) ? root : default;
}
IActionResult Refused(int status, string message) => StatusCode(status, new WebResult().Invalidate(_localizer[message], status));
IActionResult Refused(int status, string message) => StatusCode(status, new WebResult().Invalidate(localizer[message], status));
[HttpGet, Route("list")]
public async Task<IActionResult> List(CancellationToken token)
@@ -73,7 +65,7 @@ namespace PrivaPub.Controllers.ClientToServer
var existing = await DB.Default.Find<LocalEmoji>().Match(e => e.Key == key).ExecuteFirstAsync(token);
if (existing != default && (existing.DeletedAt == default || existing.Shortcode != form.Shortcode))
return Refused(StatusCodes.Status409Conflict, "This shortcode is taken.");
var outcome = await _media.EmojiImage(form.Shortcode, await Picture(token), token);
var outcome = await media.EmojiImage(form.Shortcode, await Picture(token), token);
if (!outcome.Ok)
return StatusCode(outcome.Status, new WebResult().Invalidate(outcome.Error, outcome.Status));
@@ -100,12 +92,12 @@ namespace PrivaPub.Controllers.ClientToServer
.ModifiedCount > 0;
if (!saved)
{
await _media.Trash(m => m.ID == outcome.Attachment.ID, "emoji not saved", token);
await media.Trash(m => m.ID == outcome.Attachment.ID, "emoji not saved", token);
return Refused(StatusCodes.Status409Conflict, "This shortcode is taken.");
}
await LocalEmojis.Reload(CancellationToken.None);
var notes = new[] { existing != default ? "added again" : default, emoji.Disabled ? "disabled" : default, Animated(emoji) }.Where(n => n != default).ToList();
await _log.Write(admin.ID, AdminActions.EmojiInsert, AdminTargets.Emoji, emoji.ID, $":{emoji.Shortcode}:",
await log.Write(admin.ID, AdminActions.EmojiInsert, AdminTargets.Emoji, emoji.ID, $":{emoji.Shortcode}:",
note: notes.Count > 0 ? string.Join(", ", notes) : default, token: token);
return Ok(View(emoji));
}
@@ -139,7 +131,7 @@ namespace PrivaPub.Controllers.ClientToServer
MediaOutcome outcome = default;
if (image != default)
{
outcome = await _media.EmojiImage(emoji.Shortcode, image, token);
outcome = await media.EmojiImage(emoji.Shortcode, image, token);
if (!outcome.Ok)
return StatusCode(outcome.Status, new WebResult().Invalidate(outcome.Error, outcome.Status));
Picture(emoji, outcome.Attachment, now);
@@ -151,14 +143,14 @@ namespace PrivaPub.Controllers.ClientToServer
if ((await DB.Default.Update<LocalEmoji>().Match(e => e.ID == emoji.ID && e.DeletedAt == null).ModifyWith(emoji).ExecuteAsync(token)).ModifiedCount == 0)
{
if (outcome != default)
await _media.Trash(m => m.ID == outcome.Attachment.ID, "emoji not saved", token);
await media.Trash(m => m.ID == outcome.Attachment.ID, "emoji not saved", token);
return NotFound();//deleted meanwhile
}
if (outcome != default)
{
var use = LocalEmojis.ServerUse(emoji.Shortcode);
if (previous.MediaId != default)
await _media.Trash(m => m.ID == previous.MediaId && m.ServerUse == use, "emoji image replaced", token);
await media.Trash(m => m.ID == previous.MediaId && m.ServerUse == use, "emoji image replaced", token);
// the reactions made with it show the picture it has now
if (previous.Url != default)
{
@@ -169,7 +161,7 @@ namespace PrivaPub.Controllers.ClientToServer
}
}
await LocalEmojis.Reload(CancellationToken.None);
await _log.Write(admin.ID, AdminActions.EmojiUpdate, AdminTargets.Emoji, emoji.ID, $":{emoji.Shortcode}:", note: string.Join(", ", changed), token: token);
await log.Write(admin.ID, AdminActions.EmojiUpdate, AdminTargets.Emoji, emoji.ID, $":{emoji.Shortcode}:", note: string.Join(", ", changed), token: token);
return Ok(View(emoji));
}
@@ -189,9 +181,9 @@ namespace PrivaPub.Controllers.ClientToServer
.Modify(e => e.DeletedAt, now).Modify(e => e.UpdatedAt, now).ExecuteAsync(token)).ModifiedCount == 0)
return NotFound();
var use = LocalEmojis.ServerUse(emoji.Shortcode);
await _media.Trash(m => m.ID == emoji.MediaId && m.ServerUse == use, "emoji deleted", token);
await media.Trash(m => m.ID == emoji.MediaId && m.ServerUse == use, "emoji deleted", token);
await LocalEmojis.Reload(CancellationToken.None);
await _log.Write(admin.ID, AdminActions.EmojiDelete, AdminTargets.Emoji, emoji.ID, $":{emoji.Shortcode}:", token: token);
await log.Write(admin.ID, AdminActions.EmojiDelete, AdminTargets.Emoji, emoji.ID, $":{emoji.Shortcode}:", token: token);
return Ok();
}
@@ -211,8 +203,8 @@ namespace PrivaPub.Controllers.ClientToServer
void Picture(LocalEmoji emoji, Models.Media.MediaAttachment attachment, DateTime now)
{
emoji.MediaId = attachment.ID;
emoji.Url = _media.Url(attachment.FilePath);
emoji.StaticUrl = attachment.PreviewPath == default ? emoji.Url : _media.Url(attachment.PreviewPath);
emoji.Url = media.Url(attachment.FilePath);
emoji.StaticUrl = attachment.PreviewPath == default ? emoji.Url : media.Url(attachment.PreviewPath);
emoji.ContentType = attachment.ContentType;
emoji.Width = attachment.Width;
emoji.Height = attachment.Height;
@@ -237,7 +229,7 @@ namespace PrivaPub.Controllers.ClientToServer
Width = emoji.Width,
Height = emoji.Height,
Size = emoji.Size,
Uri = LocalEmojis.Uri(_localActors.BaseAddress, emoji.Shortcode),
Uri = LocalEmojis.Uri(localActors.BaseAddress, emoji.Shortcode),
CreatedAt = emoji.CreatedAt,
UpdatedAt = emoji.UpdatedAt,
ImageUpdatedAt = emoji.ImageUpdatedAt