Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 10s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 10s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m12s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 3m4s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m17s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 10m36s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Version every /api route to /api/v1 (251 controller routes + ~24 Location
headers + the scanner callback URL + the Startup request-log literal),
uniform across the machine API, auth, scanner and scripted-build surfaces.
Add ApiVersionRewriteMiddleware: a legacy unversioned /api/* request is
rewritten (NOT redirected) to /api/v1/* in-pipeline — method, body, auth
headers and query survive — carrying RFC 8594 Deprecation/Sunset headers,
so curl / the future MCP server / bookmarks keep working. An already-
versioned path passes through; a future /api/v2 is never forced to v1.
Standardize the route convention (leading-slash absolute route per method,
no class-[Route] — except the two Scanner/Scripted controllers whose ~all
actions share a parametrized {id} prefix), enforced by ApiRouteVersioningTests
(^/api/v\d+/ over the whole Controllers.Api surface; browser-nav
/auth/oidc/login is out of scope).
Regenerate v1.json (160 paths, all /api/v1)/endpoint-index/v1.d.ts; sweep 945
SPA request literals + the test mocks (regex + positional URL parsers). /api/v1
is additive-only after freeze; the legacy-rewrite shim sunsets in ~2 releases
(owner decision) with removal tracked as a Phase-3 follow-up.
Docs: decisions.md 2026-07-13, api-conventions §1/§9, rest-api/spa-conventions/
blazor-route-parity/e2e-local/domain-model.
fixes #286
refs #197
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
83 lines
3.1 KiB
C#
83 lines
3.1 KiB
C#
using System.ComponentModel;
|
|
using ErsatzTV.Application.Artworks;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Api.Artwork;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Extensions;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace ErsatzTV.Controllers.Api;
|
|
|
|
[ApiController]
|
|
public class ArtworkUploadController(IMediator mediator) : ControllerBase
|
|
{
|
|
[HttpPost("/api/v1/artwork/uploads", Name = "UploadArtwork")]
|
|
[Consumes("multipart/form-data")]
|
|
[Tags("Artwork")]
|
|
[EndpointSummary("Upload channel logo or watermark artwork")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(ArtworkUploadResponseModel), StatusCodes.Status201Created)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
|
public async Task<IActionResult> Upload(
|
|
IFormFile file,
|
|
[FromForm][Description("Artwork target: 'logo' (default) or 'watermark'")] string target,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
if (file is null || file.Length == 0)
|
|
{
|
|
return BaseError.New("A non-empty image file is required").ToErrorResult();
|
|
}
|
|
|
|
long maxBytes = (long)SystemEnvironment.MaximumUploadMb * 1024 * 1024;
|
|
if (file.Length > maxBytes)
|
|
{
|
|
return BaseError.New($"Image exceeds the maximum allowed size of {SystemEnvironment.MaximumUploadMb} MB")
|
|
.ToErrorResult();
|
|
}
|
|
|
|
if (!TryParseTarget(target, out ArtworkKind artworkKind))
|
|
{
|
|
return BaseError.New($"Unknown upload target '{target}'; expected 'logo' or 'watermark'").ToErrorResult();
|
|
}
|
|
|
|
await using Stream stream = file.OpenReadStream();
|
|
Either<BaseError, ArtworkUploadResponseModel> result = await mediator.Send(
|
|
new UploadArtwork(stream, artworkKind),
|
|
cancellationToken);
|
|
|
|
return result.ToCreatedResult(
|
|
value => LocationFor(artworkKind, value.Path),
|
|
value => value);
|
|
}
|
|
|
|
// "logo" (default) and "watermark" are the two channel-artwork surfaces the API exposes today.
|
|
private static bool TryParseTarget(string target, out ArtworkKind artworkKind)
|
|
{
|
|
switch ((target ?? string.Empty).Trim().ToLowerInvariant())
|
|
{
|
|
case "":
|
|
case "logo":
|
|
artworkKind = ArtworkKind.Logo;
|
|
return true;
|
|
case "watermark":
|
|
artworkKind = ArtworkKind.Watermark;
|
|
return true;
|
|
default:
|
|
artworkKind = ArtworkKind.Logo;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// The serve routes (GetImage / GetWatermark) sniff the content type from the stored file, so the
|
|
// Location no longer carries a ?contentType= (issue #283 — that reflection was the XSS sink).
|
|
private static string LocationFor(ArtworkKind artworkKind, string path) =>
|
|
artworkKind switch
|
|
{
|
|
// logo paths already carry the servable prefix ("iptv/logos/{file}")
|
|
ArtworkKind.Logo => $"/{path}",
|
|
_ => $"/artwork/watermarks/{path}"
|
|
};
|
|
}
|