All 384 routes, the Mastodon API, the client API and the frozen federation paths, are read from one class with one nested class per controller. Their values are unchanged, checked one by one against the old literals; decePubClient keeps its own APIs class. 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
0f73f69239
commit
739a1603ca
47 files changed
+952
-373
No files matched your search
@@ -33,10 +33,10 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
IFeedFollows feedFollows) : MastodonController
|
||||
{
|
||||
// Mastodon 4.4: a token with the profile scope alone may read it too
|
||||
[HttpGet("/api/v1/accounts/verify_credentials"), Scope("read:accounts|profile")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_VerifyCredentials), Scope("read:accounts|profile")]
|
||||
public async Task<IActionResult> VerifyCredentials(CancellationToken token) => Json(await mapper.Local(Me, withSource: true, token));
|
||||
|
||||
[HttpPatch("/api/v1/accounts/update_credentials"), Scope("write:accounts"), EnableRateLimiting(RateLimiting.Uploads), RequestSizeLimit(20 * 1024 * 1024),
|
||||
[HttpPatch(ApiPaths.Accounts.PATCH_UpdateCredentials), Scope("write:accounts"), EnableRateLimiting(RateLimiting.Uploads), RequestSizeLimit(20 * 1024 * 1024),
|
||||
RequestFormLimits(MultipartBodyLengthLimit = 20 * 1024 * 1024)]
|
||||
public async Task<IActionResult> UpdateCredentials([FromServices] IMediaService media, CancellationToken token)
|
||||
{
|
||||
@@ -113,10 +113,10 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
}
|
||||
|
||||
// Mastodon's: the picture goes (to the trash), the profile shows the default again, and followers are told
|
||||
[HttpDelete("/api/v1/profile/avatar"), Scope("write:accounts")]
|
||||
[HttpDelete(ApiPaths.Accounts.DELETE_DeleteAvatar), Scope("write:accounts")]
|
||||
public Task<IActionResult> DeleteAvatar([FromServices] IMediaService media, CancellationToken token) => DeletePicture(media, "avatar", token);
|
||||
|
||||
[HttpDelete("/api/v1/profile/header"), Scope("write:accounts")]
|
||||
[HttpDelete(ApiPaths.Accounts.DELETE_DeleteHeader), Scope("write:accounts")]
|
||||
public Task<IActionResult> DeleteHeader([FromServices] IMediaService media, CancellationToken token) => DeletePicture(media, "header", token);
|
||||
|
||||
async Task<IActionResult> DeletePicture(IMediaService media, string kind, CancellationToken token)
|
||||
@@ -134,7 +134,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await mapper.Local(actor, withSource: true, token));
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/accounts/lookup"), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[HttpGet(ApiPaths.Accounts.GET_Lookup), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<IActionResult> Lookup(CancellationToken token)
|
||||
{
|
||||
var acct = Params.Get("acct")?.Trim().TrimStart('@');
|
||||
@@ -154,7 +154,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return foreign == default ? NotFoundError() : Json(mapper.Foreign(foreign));
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/accounts/relationships"), Scope("read:follows")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_Relationships), Scope("read:follows")]
|
||||
public async Task<IActionResult> Relationships(CancellationToken token)
|
||||
{
|
||||
var relationships = new List<Relationship>();
|
||||
@@ -163,14 +163,14 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(relationships);
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/accounts/search"), Scope("read:accounts")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_Search), Scope("read:accounts")]
|
||||
public async Task<IActionResult> Search([FromServices] AccountSearch search, CancellationToken token) =>
|
||||
Json(Params.Bool("following") == true && MyId != default
|
||||
? await search.Followed(MyId, Params.Get("q"), Limit(), token)
|
||||
: await search.Find(Params.Get("q"), Params.Bool("resolve") == true && MyId != default, Limit(), token));
|
||||
|
||||
// Mastodon 4.3: several accounts at once (at most 40), those that exist, in no promised order
|
||||
[HttpGet("/api/v1/accounts"), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[HttpGet(ApiPaths.Accounts.GET_Many), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<IActionResult> Many(CancellationToken token)
|
||||
{
|
||||
var accounts = new List<object>();
|
||||
@@ -180,14 +180,14 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(accounts);
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/accounts/{id}"), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[HttpGet(ApiPaths.Accounts.GET_M_Get), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<IActionResult> Get(string id, CancellationToken token)
|
||||
{
|
||||
var account = await mapper.Account(id, token);
|
||||
return account == default ? NotFoundError() : Json(account);
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/accounts/{id}/statuses"), Scope("read:statuses", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[HttpGet(ApiPaths.Accounts.GET_M_Statuses), Scope("read:statuses", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<IActionResult> Statuses(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -240,7 +240,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(statuses);
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/accounts/{id}/followers"), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[HttpGet(ApiPaths.Accounts.GET_M_Followers), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<IActionResult> Followers(string id, CancellationToken token)
|
||||
{
|
||||
var (local, _) = await Find(id, token);
|
||||
@@ -252,7 +252,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await AccountsFor(followers.Select(f => f.ActorURI), token));
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/accounts/{id}/following"), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[HttpGet(ApiPaths.Accounts.GET_M_Following), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<IActionResult> Following(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -269,7 +269,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
}
|
||||
|
||||
// PrivaPub's own: the feeds the persona reads (a feed's timeline is /api/v1/timelines/feed/:id)
|
||||
[HttpGet("/api/v1/feeds"), Scope("read:follows")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_Feeds), Scope("read:follows")]
|
||||
public async Task<IActionResult> Feeds(CancellationToken token)
|
||||
{
|
||||
var read = await DB.Default.Find<FeedSubscription>().Match(s => s.AvatarId == MyId).Sort(s => s.ID, MongoDB.Entities.Order.Descending).ExecuteAsync(token);
|
||||
@@ -277,7 +277,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(read.Select(s => accounts.GetValueOrDefault(s.FeedAccountId)).Where(a => a != default).ToList());
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/accounts/{id}/follow"), Scope("write:follows")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Follow), Scope("write:follows")]
|
||||
public async Task<IActionResult> Follow(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -297,7 +297,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return following == default ? Error(StatusCodes.Status403Forbidden, "This action is not allowed") : Json(await Relationship(id, token));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/accounts/{id}/unfollow"), Scope("write:follows")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Unfollow), Scope("write:follows")]
|
||||
public async Task<IActionResult> Unfollow(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -310,7 +310,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await Relationship(id, token));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/accounts/{id}/remove_from_followers"), Scope("write:follows")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_RemoveFromFollowers), Scope("write:follows")]
|
||||
public async Task<IActionResult> RemoveFromFollowers(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -321,7 +321,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await Relationship(id, token));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/accounts/{id}/block"), Scope("write:blocks")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Block), Scope("write:blocks")]
|
||||
public async Task<IActionResult> Block(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -331,7 +331,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await Relationship(id, token));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/accounts/{id}/unblock"), Scope("write:blocks")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Unblock), Scope("write:blocks")]
|
||||
public async Task<IActionResult> Unblock(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -341,7 +341,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await Relationship(id, token));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/accounts/{id}/mute"), Scope("write:mutes")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Mute), Scope("write:mutes")]
|
||||
public async Task<IActionResult> Mute(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -352,7 +352,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await Relationship(id, token));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/accounts/{id}/unmute"), Scope("write:mutes")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Unmute), Scope("write:mutes")]
|
||||
public async Task<IActionResult> Unmute(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -362,7 +362,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await Relationship(id, token));
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/blocks"), Scope("read:blocks")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_Blocks), Scope("read:blocks")]
|
||||
public async Task<IActionResult> Blocks(CancellationToken token)
|
||||
{
|
||||
var blocks = await Page.From(Params, Limit(40, 80)).Fetch(DB.Default.Find<Block>().Match(b => b.AvatarId == MyId), b => b.ID, token);
|
||||
@@ -371,7 +371,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(blocks.Select(b => accounts.GetValueOrDefault(b.TargetAccountId)).Where(a => a != default).ToList());
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/mutes"), Scope("read:mutes")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_Mutes), Scope("read:mutes")]
|
||||
public async Task<IActionResult> Mutes(CancellationToken token)
|
||||
{
|
||||
var mutes = await Page.From(Params, Limit(40, 80)).Fetch(DB.Default.Find<Mute>().Match(m => m.AvatarId == MyId), m => m.ID, token);
|
||||
@@ -380,14 +380,14 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(mutes.Select(m => accounts.GetValueOrDefault(m.TargetAccountId)).Where(a => a != default).ToList());
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/domain_blocks"), Scope("read:blocks")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_DomainBlocks), Scope("read:blocks")]
|
||||
public async Task<IActionResult> DomainBlocks(CancellationToken token) =>
|
||||
Json((await DB.Default.Find<AccountDomainBlock>().Match(b => b.AvatarId == MyId).Sort(b => b.Domain, Order.Ascending).ExecuteAsync(token)).Select(b => b.Domain).ToList());
|
||||
|
||||
// Mastodon's preview of a server block: how many of the accounts the persona follows, and of those following it, the
|
||||
// block would take away, counted as BlockDomain takes them (an account on the server or a subdomain, or whose handle
|
||||
// is)
|
||||
[HttpGet("/api/v1/domain_blocks/preview"), Scope("write:blocks")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_PreviewDomainBlock), Scope("write:blocks")]
|
||||
public async Task<IActionResult> PreviewDomainBlock(CancellationToken token)
|
||||
{
|
||||
var domain = Params.Get("domain")?.Trim().ToLowerInvariant();
|
||||
@@ -406,21 +406,21 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/domain_blocks"), Scope("write:blocks")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_BlockDomain), Scope("write:blocks")]
|
||||
public async Task<IActionResult> BlockDomain(CancellationToken token)
|
||||
{
|
||||
await relationshipService.BlockDomain(Me, Params.Get("domain"), token);
|
||||
return Json(new { });
|
||||
}
|
||||
|
||||
[HttpDelete("/api/v1/domain_blocks"), Scope("write:blocks")]
|
||||
[HttpDelete(ApiPaths.Accounts.DELETE_UnblockDomain), Scope("write:blocks")]
|
||||
public async Task<IActionResult> UnblockDomain(CancellationToken token)
|
||||
{
|
||||
await relationshipService.UnblockDomain(Me, Params.Get("domain"), token);
|
||||
return Json(new { });
|
||||
}
|
||||
|
||||
[HttpGet("/api/v1/follow_requests"), Scope("read:follows")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_FollowRequests), Scope("read:follows")]
|
||||
public async Task<IActionResult> FollowRequests(CancellationToken token)
|
||||
{
|
||||
var requests = await dbEntities.Followers.Match(f => f.LocalActorId == Me.Id && f.LocalActorKind == LocalActorKind.Person && !f.IsAccepted)
|
||||
@@ -428,24 +428,24 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await AccountsFor(requests.Select(r => r.ActorURI), token));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/follow_requests/{id}/authorize"), Scope("write:follows")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Authorize), Scope("write:follows")]
|
||||
public async Task<IActionResult> Authorize(string id, CancellationToken token) =>
|
||||
await followService.Decide(Me, id, accept: true, token) ? Json(await Relationship(id, token)) : NotFoundError();
|
||||
|
||||
[HttpPost("/api/v1/follow_requests/{id}/reject"), Scope("write:follows")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Reject), Scope("write:follows")]
|
||||
public async Task<IActionResult> Reject(string id, CancellationToken token) =>
|
||||
await followService.Decide(Me, id, accept: false, token) ? Json(await Relationship(id, token)) : NotFoundError();
|
||||
|
||||
// Familiar followers stay empty by design: which of the accounts the persona follows also follow another account would
|
||||
// tell who follows whom among the personas here (and their followers lists are never shown, hide_collections), so
|
||||
// every account answers none
|
||||
[HttpGet("/api/v1/accounts/familiar_followers"), Scope("read:follows")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_FamiliarFollowers), Scope("read:follows")]
|
||||
public IActionResult FamiliarFollowers() => Json(Params.List("id").Select(id => new { id, accounts = Array.Empty<Account>() }).ToList());
|
||||
|
||||
// Endorsements (R8): Mastodon's account pins under their old names (pin, unpin) and 4.4's (endorse, unendorse). Only an
|
||||
// account the persona follows may be endorsed, as Mastodon requires; they are the persona's alone, never federated as
|
||||
// featured accounts and never listed to anyone else (the owner's default: endorsements stay private)
|
||||
[HttpPost("/api/v1/accounts/{id}/pin"), HttpPost("/api/v1/accounts/{id}/endorse"), Scope("write:accounts")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Endorse), HttpPost(ApiPaths.Accounts.POST_M_EndorseV1), Scope("write:accounts")]
|
||||
public async Task<IActionResult> Endorse(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -469,7 +469,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
return Json(await Relationship(id, token));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/accounts/{id}/unpin"), HttpPost("/api/v1/accounts/{id}/unendorse"), Scope("write:accounts")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Unendorse), HttpPost(ApiPaths.Accounts.POST_M_UnendorseV1), Scope("write:accounts")]
|
||||
public async Task<IActionResult> Unendorse(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -481,12 +481,12 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
}
|
||||
|
||||
// the persona's own endorsements, newest first, those it still follows
|
||||
[HttpGet("/api/v1/endorsements"), Scope("read:accounts")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_Endorsements), Scope("read:accounts")]
|
||||
public Task<IActionResult> Endorsements(CancellationToken token) => EndorsementsOf("/api/v1/endorsements", token);
|
||||
|
||||
// Mastodon 4.4: an account's endorsements. Only the persona's own are answered, to the persona itself: endorsements
|
||||
// stay private, so every other account answers none
|
||||
[HttpGet("/api/v1/accounts/{id}/endorsements"), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[HttpGet(ApiPaths.Accounts.GET_M_EndorsementsOfAccount), Scope("read:accounts", requiresUser: false), Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<IActionResult> EndorsementsOfAccount(string id, CancellationToken token) =>
|
||||
MyId != default && id == MyId ? await EndorsementsOf($"/api/v1/accounts/{id}/endorsements", token) : Json(Array.Empty<Account>());
|
||||
|
||||
@@ -503,7 +503,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
|
||||
// A private note on an account (R8): the persona's own (PersonaNote, never its login's), shown only to it in the
|
||||
// relationship's `note`, never federated; an empty comment takes it away
|
||||
[HttpPost("/api/v1/accounts/{id}/note"), Scope("write:accounts")]
|
||||
[HttpPost(ApiPaths.Accounts.POST_M_Note), Scope("write:accounts")]
|
||||
public async Task<IActionResult> Note(string id, CancellationToken token)
|
||||
{
|
||||
var (local, remote) = await Find(id, token);
|
||||
@@ -526,7 +526,7 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
|
||||
// Mastodon's preferences: posting defaults (update_credentials' source) and reading ones (R8: AvatarSettings, set
|
||||
// through /clientapi/avatar/private/preferences, since Mastodon's API sets none)
|
||||
[HttpGet("/api/v1/preferences"), Scope("read:accounts")]
|
||||
[HttpGet(ApiPaths.Accounts.GET_Preferences), Scope("read:accounts")]
|
||||
public IActionResult Preferences() => Json(new Dictionary<string, object>
|
||||
{
|
||||
["posting:default:visibility"] = Me.Settings.DefaultVisibility ?? "public",
|
||||
|
||||
Reference in new issue
Block a user