[backend/controllers] Fixup media types

This commit is contained in:
Laura Hausmann 2024-02-18 02:58:58 +01:00
parent 8f0af87d00
commit a96ae9d1ea
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
19 changed files with 46 additions and 43 deletions

View file

@ -1,4 +1,3 @@
using System.Net.Mime;
using System.Text;
using Iceshrimp.Backend.Controllers.Attributes;
using Iceshrimp.Backend.Controllers.Schemas;
@ -17,12 +16,12 @@ namespace Iceshrimp.Backend.Controllers;
[ApiController]
[Tags("ActivityPub")]
[UseNewtonsoftJson]
[Produces("application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")]
public class ActivityPubController : Controller
{
[HttpGet("/notes/{id}")]
[AuthorizedFetch]
[MediaTypeRouteFilter("application/activity+json", "application/ld+json")]
[Produces("application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ASNote))]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(ErrorResponse))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ErrorResponse))]
@ -45,7 +44,6 @@ public class ActivityPubController : Controller
[HttpGet("/users/{id}")]
[AuthorizedFetch]
[MediaTypeRouteFilter("application/activity+json", "application/ld+json")]
[Produces("application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ASActor))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ErrorResponse))]
public async Task<IActionResult> GetUser(
@ -63,7 +61,6 @@ public class ActivityPubController : Controller
[HttpGet("/@{acct}")]
[AuthorizedFetch]
[MediaTypeRouteFilter("application/activity+json", "application/ld+json")]
[Produces("application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ASActor))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ErrorResponse))]
public async Task<IActionResult> GetUserByUsername(
@ -93,7 +90,7 @@ public class ActivityPubController : Controller
[AuthorizedFetch(true)]
[EnableRequestBuffering(1024 * 1024)]
[Produces("text/plain")]
[Consumes(MediaTypeNames.Application.Json)]
[Consumes("application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")]
public async Task<IActionResult> Inbox(string? id, [FromServices] QueueService queues)
{
using var reader = new StreamReader(Request.Body, Encoding.UTF8, true, 1024, true);

View file

@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Schemas;
using Iceshrimp.Backend.Core.Database;
using Iceshrimp.Backend.Core.Database.Tables;
@ -16,6 +17,7 @@ namespace Iceshrimp.Backend.Controllers;
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(ErrorResponse))]
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameterInConstructor",
Justification = "We only have a DatabaseContext in our DI pool, not the base type")]
[Produces(MediaTypeNames.Application.Json)]
public class AdminController(DatabaseContext db) : Controller
{
[HttpPost("invites/generate")]

View file

@ -15,7 +15,7 @@ namespace Iceshrimp.Backend.Controllers;
[ApiController]
[Tags("Authentication")]
[EnableRateLimiting("sliding")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
[Route("/api/iceshrimp/v1/auth")]
public class AuthController(DatabaseContext db, UserService userSvc) : Controller
{

View file

@ -1,11 +1,12 @@
using System.Net;
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Schemas;
using Iceshrimp.Backend.Core.Middleware;
using Microsoft.AspNetCore.Mvc;
namespace Iceshrimp.Backend.Controllers;
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
public class FallbackController : Controller
{
[ProducesResponseType(StatusCodes.Status501NotImplemented, Type = typeof(ErrorResponse))]

View file

@ -1,4 +1,5 @@
using System.IO.Hashing;
using System.Net.Mime;
using System.Text;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
@ -12,6 +13,8 @@ namespace Iceshrimp.Backend.Controllers;
[ApiController]
[EnableCors("drive")]
[Route("/identicon/{id}")]
[Produces(MediaTypeNames.Image.Png)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(object))]
public class IdenticonController : Controller
{
[HttpGet]

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Renderers;
@ -21,7 +22,7 @@ namespace Iceshrimp.Backend.Controllers.Mastodon;
[EnableCors("mastodon")]
[Authenticate]
[EnableRateLimiting("sliding")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
public class AccountController(
DatabaseContext db,
UserRenderer userRenderer,
@ -273,7 +274,6 @@ public class AccountController(
[HttpGet("{id}/statuses")]
[Authorize("read:statuses")]
[LinkPagination(20, 40)]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<StatusEntity>))]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(MastodonErrorResponse))]
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas;
using Iceshrimp.Backend.Core.Database;
@ -15,12 +16,11 @@ namespace Iceshrimp.Backend.Controllers.Mastodon;
[MastodonApiController]
[EnableRateLimiting("sliding")]
[EnableCors("mastodon")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
public class AuthController(DatabaseContext db) : Controller
{
[HttpGet("/api/v1/apps/verify_credentials")]
[Authenticate]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AuthSchemas.VerifyAppCredentialsResponse))]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(MastodonErrorResponse))]
public IActionResult VerifyAppCredentials()
@ -39,7 +39,6 @@ public class AuthController(DatabaseContext db) : Controller
[HttpPost("/api/v1/apps")]
[EnableRateLimiting("strict")]
[ConsumesHybrid]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AuthSchemas.RegisterAppResponse))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))]
public async Task<IActionResult> RegisterApp([FromHybrid] AuthSchemas.RegisterAppRequest request)
@ -90,7 +89,6 @@ public class AuthController(DatabaseContext db) : Controller
[HttpPost("/oauth/token")]
[ConsumesHybrid]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AuthSchemas.OauthTokenResponse))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))]
public async Task<IActionResult> GetOauthToken([FromHybrid] AuthSchemas.OauthTokenRequest request)
@ -128,7 +126,6 @@ public class AuthController(DatabaseContext db) : Controller
[HttpPost("/oauth/revoke")]
[ConsumesHybrid]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(object))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))]
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas;
using Iceshrimp.Backend.Core.Configuration;
@ -13,11 +14,10 @@ namespace Iceshrimp.Backend.Controllers.Mastodon;
[MastodonApiController]
[EnableCors("mastodon")]
[EnableRateLimiting("sliding")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
public class InstanceController(DatabaseContext db) : Controller
{
[HttpGet("/api/v1/instance")]
[Produces("application/json")]
public async Task<IActionResult> GetInstanceInfo([FromServices] IOptionsSnapshot<Config> config)
{
var userCount = await db.Users.LongCountAsync(p => p.Host == null);

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities;
@ -14,7 +15,7 @@ namespace Iceshrimp.Backend.Controllers.Mastodon;
[Authorize("write:media")]
[EnableCors("mastodon")]
[EnableRateLimiting("sliding")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AttachmentEntity))]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(MastodonErrorResponse))]
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Renderers;
@ -18,13 +19,12 @@ namespace Iceshrimp.Backend.Controllers.Mastodon;
[Authenticate]
[EnableCors("mastodon")]
[EnableRateLimiting("sliding")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
public class NotificationController(DatabaseContext db, NotificationRenderer notificationRenderer) : Controller
{
[HttpGet]
[Authorize("read:notifications")]
[LinkPagination(40, 80)]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<NotificationEntity>))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
public async Task<IActionResult> GetNotifications(MastodonPaginationQuery query)

View file

@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Net.Mime;
using System.Text.RegularExpressions;
using Iceshrimp.Backend.Controllers.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
@ -20,7 +21,7 @@ namespace Iceshrimp.Backend.Controllers.Mastodon;
[Authenticate]
[EnableCors("mastodon")]
[EnableRateLimiting("sliding")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
public class SearchController(
DatabaseContext db,
NoteRenderer noteRenderer,
@ -32,7 +33,6 @@ public class SearchController(
[HttpGet("/api/v2/search")]
[Authorize("read:search")]
[LinkPagination(20, 40)]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SearchSchemas.SearchResponse))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
public async Task<IActionResult> Search(SearchSchemas.SearchRequest search, MastodonPaginationQuery pagination)

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Renderers;
using Iceshrimp.Backend.Controllers.Mastodon.Schemas;
@ -19,7 +20,7 @@ namespace Iceshrimp.Backend.Controllers.Mastodon;
[Authenticate]
[EnableCors("mastodon")]
[EnableRateLimiting("sliding")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
public class StatusController(
DatabaseContext db,
NoteRenderer noteRenderer,
@ -29,7 +30,6 @@ public class StatusController(
{
[HttpGet("{id}")]
[Authenticate("read:statuses")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusEntity))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
public async Task<IActionResult> GetNote(string id)
@ -48,7 +48,6 @@ public class StatusController(
[HttpGet("{id}/context")]
[Authenticate("read:statuses")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusEntity))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
public async Task<IActionResult> GetStatusContext(string id)
@ -80,7 +79,6 @@ public class StatusController(
[HttpPost("{id}/favourite")]
[Authorize("write:favourites")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusEntity))]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(MastodonErrorResponse))]
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]
@ -100,7 +98,6 @@ public class StatusController(
[HttpPost("{id}/unfavourite")]
[Authorize("write:favourites")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusEntity))]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(MastodonErrorResponse))]
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]
@ -120,7 +117,6 @@ public class StatusController(
[HttpPost]
[Authorize("write:statuses")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusEntity))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))]
public async Task<IActionResult> PostNote([FromHybrid] StatusSchemas.PostStatusRequest request)
@ -183,7 +179,6 @@ public class StatusController(
[HttpPut("{id}")]
[Authorize("write:statuses")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusEntity))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))]
public async Task<IActionResult> EditNote(string id, [FromHybrid] StatusSchemas.EditStatusRequest request)

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
using Iceshrimp.Backend.Controllers.Mastodon.Renderers;
@ -20,14 +21,13 @@ namespace Iceshrimp.Backend.Controllers.Mastodon;
[LinkPagination(20, 40)]
[EnableRateLimiting("sliding")]
[EnableCors("mastodon")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(MastodonErrorResponse))]
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(MastodonErrorResponse))]
public class TimelineController(DatabaseContext db, NoteRenderer noteRenderer, IDistributedCache cache) : Controller
{
[Authorize("read:statuses")]
[HttpGet("home")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<StatusEntity>))]
public async Task<IActionResult> GetHomeTimeline(MastodonPaginationQuery query)
{
@ -50,7 +50,6 @@ public class TimelineController(DatabaseContext db, NoteRenderer noteRenderer, I
[Authorize("read:statuses")]
[HttpGet("public")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<StatusEntity>))]
public async Task<IActionResult> GetPublicTimeline(MastodonPaginationQuery query)
{

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Core.Configuration;
using Iceshrimp.Backend.Core.Database;
using Iceshrimp.Backend.Core.Federation.WebFinger;
@ -12,11 +13,11 @@ namespace Iceshrimp.Backend.Controllers;
[Tags("Federation")]
[Route("/nodeinfo")]
[EnableCors("well-known")]
[Produces(MediaTypeNames.Application.Json)]
public class NodeInfoController(IOptions<Config.InstanceSection> config, DatabaseContext db) : Controller
{
[HttpGet("2.1")]
[HttpGet("2.0")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WebFingerResponse))]
public async Task<IActionResult> GetNodeInfo()
{

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Renderers;
using Iceshrimp.Backend.Controllers.Schemas;
using Iceshrimp.Backend.Core.Database;
@ -12,13 +13,14 @@ using Microsoft.EntityFrameworkCore;
namespace Iceshrimp.Backend.Controllers;
[ApiController]
[Produces("application/json")]
[EnableRateLimiting("sliding")]
[Route("/api/iceshrimp/v1/note")]
[Produces(MediaTypeNames.Application.Json)]
public class NoteController(DatabaseContext db, NoteService noteSvc) : Controller
{
[HttpGet("{id}")]
[Authenticate]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(NoteResponse))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ErrorResponse))]
public async Task<IActionResult> GetNote(string id)
@ -36,10 +38,11 @@ public class NoteController(DatabaseContext db, NoteService noteSvc) : Controlle
[HttpPost]
[Authenticate, Authorize]
[Consumes(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(NoteResponse))]
[ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(ErrorResponse))]
[ProducesResponseType(StatusCodes.Status403Forbidden, Type = typeof(ErrorResponse))]
public async Task<IActionResult> CreateNote([FromBody] NoteCreateRequest request)
public async Task<IActionResult> CreateNote(NoteCreateRequest request)
{
var user = HttpContext.GetUserOrFail();

View file

@ -4,7 +4,7 @@ namespace Iceshrimp.Backend.Controllers.Schemas;
public class NoteCreateRequest
{
[J("text")] public required string Text;
[J("cw")] public string? Cw;
[J("replyId")] public string? ReplyId;
[J("text")] public required string Text { get; set; }
[J("cw")] public string? Cw { get; set; }
[J("replyId")] public string? ReplyId { get; set; }
}

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Renderers;
using Iceshrimp.Backend.Controllers.Schemas;
using Iceshrimp.Backend.Core.Database;
@ -11,9 +12,9 @@ using Microsoft.Extensions.Caching.Distributed;
namespace Iceshrimp.Backend.Controllers;
[ApiController]
[Produces("application/json")]
[EnableRateLimiting("sliding")]
[Route("/api/iceshrimp/v1/timeline")]
[Produces(MediaTypeNames.Application.Json)]
public class TimelineController(DatabaseContext db, IDistributedCache cache) : Controller
{
[HttpGet("home")]

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Attributes;
using Iceshrimp.Backend.Controllers.Renderers;
using Iceshrimp.Backend.Controllers.Schemas;
@ -11,9 +12,9 @@ using Microsoft.EntityFrameworkCore;
namespace Iceshrimp.Backend.Controllers;
[ApiController]
[Produces("application/json")]
[EnableRateLimiting("sliding")]
[Route("/api/iceshrimp/v1/user/{id}")]
[Produces(MediaTypeNames.Application.Json)]
public class UserController(DatabaseContext db) : Controller
{
[HttpGet]

View file

@ -1,3 +1,4 @@
using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Schemas;
using Iceshrimp.Backend.Core.Configuration;
using Iceshrimp.Backend.Core.Database;
@ -17,7 +18,7 @@ namespace Iceshrimp.Backend.Controllers;
public class WellKnownController(IOptions<Config.InstanceSection> config, DatabaseContext db) : Controller
{
[HttpGet("webfinger")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WebFingerResponse))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ErrorResponse))]
public async Task<IActionResult> WebFinger([FromQuery] string resource)
@ -76,7 +77,7 @@ public class WellKnownController(IOptions<Config.InstanceSection> config, Databa
}
[HttpGet("nodeinfo")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(NodeInfoIndexResponse))]
public IActionResult NodeInfo()
{
@ -102,11 +103,12 @@ public class WellKnownController(IOptions<Config.InstanceSection> config, Databa
[HttpGet("host-meta")]
[Produces("application/xrd+xml")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(object))]
public IActionResult HostMeta()
{
//TODO: use a proper xml serializer for this
return
Content($$"""<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" type="application/xrd+xml" template="https://{{config.Value.WebDomain}}/.well-known/webfinger?resource={uri}"/></XRD>""");
Content($$"""<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" type="application/xrd+xml" template="https://{{config.Value.WebDomain}}/.well-known/webfinger?resource={uri}"/></XRD>""",
"application/xrd+xml");
}
}