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>
118 lines
5.9 KiB
C#
118 lines
5.9 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using ErsatzTV.Application.FFmpegProfiles;
|
|
using ErsatzTV.Controllers.Api.Requests;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Api.FFmpegProfiles;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Extensions;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace ErsatzTV.Controllers.Api;
|
|
|
|
[ApiController]
|
|
public class FFmpegProfileController(IMediator mediator) : ControllerBase
|
|
{
|
|
[HttpGet("/api/v1/ffmpeg/profiles", Name = "GetFFmpegProfiles")]
|
|
[Tags("FFmpeg Profiles")]
|
|
[EndpointSummary("Get all FFmpeg profiles")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(List<FFmpegFullProfileResponseModel>), StatusCodes.Status200OK)]
|
|
public async Task<List<FFmpegFullProfileResponseModel>> GetAll(CancellationToken cancellationToken) =>
|
|
await mediator.Send(new GetAllFFmpegProfilesForApi(), cancellationToken);
|
|
|
|
[HttpGet("/api/v1/ffmpeg/hardware-acceleration-kinds", Name = "GetSupportedHardwareAccelerationKinds")]
|
|
[Tags("FFmpeg Profiles")]
|
|
[EndpointSummary("Get supported hardware acceleration kinds")]
|
|
[EndpointDescription(
|
|
"Returns the hardware-acceleration kinds available on this host (probed from the configured " +
|
|
"FFmpeg binary). Always includes None; falls back to just None when FFmpeg is unavailable.")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(List<HardwareAccelerationKind>), StatusCodes.Status200OK)]
|
|
public async Task<List<HardwareAccelerationKind>> GetHardwareAccelerationKinds(CancellationToken cancellationToken) =>
|
|
// returns the enum values directly; the API serializes enums as their string names
|
|
await mediator.Send(new GetSupportedHardwareAccelerationKinds(), cancellationToken);
|
|
|
|
[HttpGet("/api/v1/ffmpeg/profiles/{id:int}", Name = "GetFFmpegProfileById")]
|
|
[Tags("FFmpeg Profiles")]
|
|
[EndpointSummary("Get an FFmpeg profile by id")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(FFmpegFullProfileResponseModel), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> GetById(int id, CancellationToken cancellationToken)
|
|
{
|
|
Option<FFmpegFullProfileResponseModel> result =
|
|
await mediator.Send(new GetFFmpegFullProfileByIdForApi(id), cancellationToken);
|
|
return result.ToGetResult();
|
|
}
|
|
|
|
[HttpPost("/api/v1/ffmpeg/profiles", Name = "CreateFFmpegProfile")]
|
|
[Tags("FFmpeg Profiles")]
|
|
[EndpointSummary("Create an FFmpeg profile")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(FFmpegFullProfileResponseModel), StatusCodes.Status201Created)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
|
public async Task<IActionResult> AddOne(
|
|
[Required] [FromBody]
|
|
CreateFFmpegProfileRequest request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
Either<BaseError, CreateFFmpegProfileResult> result = await mediator.Send(request.ToCommand(), cancellationToken);
|
|
return await result.Match(
|
|
Left: error => Task.FromResult(error.ToErrorResult()),
|
|
Right: async created =>
|
|
{
|
|
Option<FFmpegFullProfileResponseModel> profile =
|
|
await mediator.Send(new GetFFmpegFullProfileByIdForApi(created.FFmpegProfileId), cancellationToken);
|
|
return profile.Match(
|
|
Some: vm => (IActionResult)new CreatedResult($"/api/v1/ffmpeg/profiles/{vm.Id}", vm),
|
|
None: () => ApiResults.NotFoundProblem());
|
|
});
|
|
}
|
|
|
|
[HttpPut("/api/v1/ffmpeg/profiles/{id:int}", Name = "UpdateFFmpegProfile")]
|
|
[Tags("FFmpeg Profiles")]
|
|
[EndpointSummary("Update an FFmpeg profile")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(FFmpegFullProfileResponseModel), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
|
public async Task<IActionResult> UpdateOne(
|
|
int id,
|
|
[Required] [FromBody]
|
|
UpdateFFmpegProfileRequest request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
Either<BaseError, UpdateFFmpegProfileResult> result =
|
|
await mediator.Send(request.ToCommand(id), cancellationToken);
|
|
return await result.Match(
|
|
Left: error => Task.FromResult(error.ToErrorResult()),
|
|
Right: async updated =>
|
|
{
|
|
Option<FFmpegFullProfileResponseModel> profile =
|
|
await mediator.Send(new GetFFmpegFullProfileByIdForApi(updated.FFmpegProfileId), cancellationToken);
|
|
return profile.Match(
|
|
Some: vm => (IActionResult)new OkObjectResult(vm),
|
|
None: () => ApiResults.NotFoundProblem());
|
|
});
|
|
}
|
|
|
|
[HttpDelete("/api/v1/ffmpeg/profiles/{id:int}", Name = "DeleteFFmpegProfile")]
|
|
[Tags("FFmpeg Profiles")]
|
|
[EndpointSummary("Delete an FFmpeg profile")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
|
public async Task<IActionResult> DeleteProfileAsync(int id, CancellationToken cancellationToken)
|
|
{
|
|
Either<BaseError, Unit> result = await mediator.Send(new DeleteFFmpegProfile(id), cancellationToken);
|
|
return result.ToDeletedResult();
|
|
}
|
|
}
|