Add REST endpoints backing the SPA media detail pages and image browser:
- GET /api/movies/{id}, /api/shows/{id}, /api/seasons/{id}, /api/artists/{id}
wrapping the existing detail queries; 404 on None.
- GET /api/media-items/{id}/info wrapping GetMediaItemInfo; UnableToLocateMediaItem
-> 404, other errors -> 422.
- GET /api/images/folders?parentId= and PUT /api/images/folders/{id}/duration
(validates null-or-positive -> 400; existence guard via new ImageFolderExists
query -> 404).
- Extend GetLibraryBrowseItems parentId drill-in to Episode (episodes of a season,
episode-number order) and MusicVideo (an artist's music videos, album/track order),
alongside the existing TelevisionSeason branch.
Response DTOs live in ErsatzTV.Core/Api/* and never expose Application VMs. Artwork
values are rooted for the SPA via a shared ErsatzTV.Core/Api/ApiArtwork helper
(mirrors the #180/#181 browse-handler logic; handles jellyfin/emby proxy prefixes,
http passthrough, empty). Regenerated OpenAPI v1.json + web v1.d.ts. New controllers
registered in ApiControllerSecurityTests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
67 lines
2.5 KiB
C#
67 lines
2.5 KiB
C#
#nullable enable
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Emby;
|
|
using ErsatzTV.Core.Jellyfin;
|
|
using Flurl;
|
|
|
|
namespace ErsatzTV.Core.Api;
|
|
|
|
/// <summary>
|
|
/// Roots an artwork value (as produced by the Application view-model mappers) into a directly-usable
|
|
/// <c><img src></c> URL for the React SPA. The Blazor pages prefix "artwork/{folder}/" themselves and
|
|
/// resolve relative to <c><base href="/"></c>, but the SPA renders the value raw from under <c>/app/</c>,
|
|
/// so the API must root the URL itself (issue #180/#181). Mirrors the projection helper in
|
|
/// GetLibraryBrowseItemsHandler so detail endpoints stay consistent with the browse grid.
|
|
/// </summary>
|
|
public static class ApiArtwork
|
|
{
|
|
public static string Root(string? artwork, ArtworkKind artworkKind)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(artwork))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
// Absolute URLs are already usable as-is (matches Blazor's GetPosterUrl guard).
|
|
if (artwork.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
|
|
artwork.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return artwork;
|
|
}
|
|
|
|
string folder = artworkKind switch
|
|
{
|
|
ArtworkKind.Thumbnail => "thumbnails",
|
|
ArtworkKind.FanArt => "fanart",
|
|
_ => "posters"
|
|
};
|
|
|
|
// Some mappers (e.g. Artists) leave the raw jellyfin://emby:// scheme in the value; convert it here so
|
|
// the SPA gets a working proxy URL even when the source mapper didn't pre-convert. Movie/TV mappers
|
|
// already produce a relative "jellyfin/{id}?..." path, which falls through to the plain prefix below.
|
|
if (artwork.StartsWith("jellyfin://", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
Url url = JellyfinUrl.RelativeProxyForArtwork(artwork);
|
|
if (artworkKind is ArtworkKind.Poster or ArtworkKind.Thumbnail)
|
|
{
|
|
url.SetQueryParam("fillHeight", 440);
|
|
}
|
|
|
|
return $"/artwork/{folder}/{url}";
|
|
}
|
|
|
|
if (artwork.StartsWith("emby://", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
Url url = EmbyUrl.RelativeProxyForArtwork(artwork);
|
|
if (artworkKind is ArtworkKind.Poster or ArtworkKind.Thumbnail)
|
|
{
|
|
url.SetQueryParam("maxHeight", 440);
|
|
}
|
|
|
|
return $"/artwork/{folder}/{url}";
|
|
}
|
|
|
|
return $"/artwork/{folder}/{artwork}";
|
|
}
|
|
}
|