The API's JSON is generated at build time, and no answer is an anonymous object
Build / Build (push) Successful in 36s

Every answer of the Mastodon API and the client API now has its JSON shape generated when the server is built, instead
of worked out by reflection while it runs; the bytes sent are unchanged. The small answers that were anonymous objects
(the instance documents, notification policies, reports, lists, tags, trends, errors and the empty answers) are named
types. A type without generated metadata fails at once in development and on the pasture, and in production is logged
and still answered. Three lists that were sent as lazy sequences (moderation reports, the published domain blocks and
the languages) are now built first.

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 07:28:02 +01:00
1 parent 8a1e4e419b
commit f3fdeaf038
41 files changed
+1333 -266

No files matched your search

@@ -1,4 +1,9 @@
using Microsoft.AspNetCore.RateLimiting;
using EmptyEntity = PrivaPub.Api.Mastodon.Entities.EmptyEntity;
using MediaUploadEntity = PrivaPub.Api.Mastodon.Entities.MediaUploadEntity;
using MediaUploadMetaEntity = PrivaPub.Api.Mastodon.Entities.MediaUploadMetaEntity;
using MediaUploadMetaFocusEntity = PrivaPub.Api.Mastodon.Entities.MediaUploadMetaFocusEntity;
using MediaUploadMetaOriginalEntity = PrivaPub.Api.Mastodon.Entities.MediaUploadMetaOriginalEntity;
using PrivaPub.Infrastructure.Statistics;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -67,7 +72,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
if (attachment.PostId != null || attachment.ScheduledStatusId != null)
return Error(StatusCodes.Status422UnprocessableEntity, "Media attachment is currently used by a status");
await mediaService.Trash(m => m.ID == attachment.ID && m.PostId == null && m.ScheduledStatusId == null, "deleted by its owner", token);
return Json(new { });
return Json(new EmptyEntity());
}
// as on Mastodon, only media not posted yet: a posted one's description and focus change by editing its post (media_attributes)
@@ -147,23 +152,23 @@ namespace PrivaPub.Api.Mastodon.Controllers
object View(MediaAttachment attachment) => View(mediaService, attachment);
internal static object View(IMediaService media, MediaAttachment attachment) => new
internal static object View(IMediaService media, MediaAttachment attachment) => new MediaUploadEntity
{
id = attachment.ID,
type = attachment.Kind,
url = media.Url(attachment.FilePath),
preview_url = media.Url(attachment.PreviewPath ?? attachment.FilePath),
remote_url = default(string),
text_url = default(string),
meta = new
Id = attachment.ID,
Type = attachment.Kind,
Url = media.Url(attachment.FilePath),
PreviewUrl = media.Url(attachment.PreviewPath ?? attachment.FilePath),
RemoteUrl = default(string),
TextUrl = default(string),
Meta = new MediaUploadMetaEntity
{
original = attachment.Width.HasValue && attachment.Height > 0
? new { width = attachment.Width, height = attachment.Height, size = $"{attachment.Width}x{attachment.Height}", aspect = (double)attachment.Width / attachment.Height.Value }
Original = attachment.Width.HasValue && attachment.Height > 0
? new MediaUploadMetaOriginalEntity { Width = attachment.Width, Height = attachment.Height, Size = $"{attachment.Width}x{attachment.Height}", Aspect = (double)attachment.Width / attachment.Height.Value }
: default,
focus = attachment.Focus is { Length: 2 } ? new { x = attachment.Focus[0], y = attachment.Focus[1] } : default
Focus = attachment.Focus is { Length: 2 } ? new MediaUploadMetaFocusEntity { X = attachment.Focus[0], Y = attachment.Focus[1] } : default
},
description = attachment.Description,
blurhash = attachment.Blurhash
Description = attachment.Description,
Blurhash = attachment.Blurhash
};
}
}