UploadChannelTitleIcon.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Security.Claims;
  2. using MediatR;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Web.Api.Common;
  5. using Web.Api.Extensions;
  6. namespace Web.Api.Endpoints.ChannelTitle;
  7. /// <summary>채널 칭호 아이콘 업로드 (이미지 전용 — gif, jpeg, png, webp / 최대 20MB)</summary>
  8. internal sealed class UploadChannelTitleIcon : IEndpoint
  9. {
  10. public void MapEndpoint(IEndpointRouteBuilder app)
  11. {
  12. app.MapPost("api/channel-titles/icon/upload", async (
  13. IFormFile file,
  14. [FromForm] int channelID,
  15. ClaimsPrincipal user,
  16. ISender sender,
  17. CancellationToken ct
  18. ) => {
  19. var memberID = user.GetMemberID();
  20. if (memberID is null)
  21. {
  22. return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token");
  23. }
  24. var result = await sender.Send(new Application.Features.Api.ChannelTitle.UploadIcon.Command(
  25. channelID,
  26. memberID.Value,
  27. file
  28. ), ct);
  29. return result.Match(
  30. url => ApiResponse.Ok(new { url }),
  31. CustomResults.Problem
  32. );
  33. })
  34. .WithTags("ChannelTitle")
  35. .RequireAuthorization()
  36. .DisableAntiforgery();
  37. }
  38. }