mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Adds the music library browsing and editing pages to the web client.
This commit is contained in:
1 parent
c7aab63552
commit
5a2c6c2bd8
215 files changed
+60042
-3
No files matched your search
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.DeleteMusicAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/api-delete-album</c> route.
|
||||
/// </summary>
|
||||
public class DeleteMusicAlbumEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteMusicAlbumEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public DeleteMusicAlbumEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.DELETE);
|
||||
Routes(WebRoutes.Music.DELETE_ALBUM);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the music album identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The album is identified by the {artistId} and {albumId} route values; all ids are normalized to Guids before they are substituted
|
||||
// into the upstream URL, so that a crafted value can never escape its URL segment, and an unparseable id is reported by the API as a
|
||||
// missing id.
|
||||
string routeArtistId = HttpContext.Request.RouteValues["artistId"]?.ToString() ?? string.Empty;
|
||||
string artistId = Guid.TryParse(routeArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
string routeAlbumId = HttpContext.Request.RouteValues["albumId"]?.ToString() ?? string.Empty;
|
||||
string albumId = Guid.TryParse(routeAlbumId, out Guid parsedAlbumId) ? parsedAlbumId.ToString() : Guid.Empty.ToString();
|
||||
string queryLibraryId = HttpContext.Request.Query["libraryId"].ToString();
|
||||
string libraryId = Guid.TryParse(queryLibraryId, out Guid parsedLibraryId) ? parsedLibraryId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
await _apiHttpClient.DeleteAsync(ApiRoutes.Music.DELETE_ALBUM.Replace("{libraryId}", libraryId).Replace("{artistId}", artistId).Replace("{albumId}", albumId), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.DeleteMusicAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="DeleteMusicAlbumEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteMusicAlbumEndpointSummary : Summary<DeleteMusicAlbumEndpoint>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteMusicAlbumEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public DeleteMusicAlbumEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes a music album.";
|
||||
Description = "Deletes the music album identified by the route, together with its tracks.";
|
||||
|
||||
Response(200, "The music album was deleted.");
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Antiforgery;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.EditMusicAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}</c> route.
|
||||
/// </summary>
|
||||
public class EditMusicAlbumViewEndpoint : BaseEndpoint<GetMusicAlbumViewRequest, IResult>
|
||||
{
|
||||
// The resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it with the configured ResourcesPath.
|
||||
private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Library.AudioLibrary.MusicLibrary.Albums.Item";
|
||||
private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web";
|
||||
// The page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope.
|
||||
private const string VIEW_PAGE_KEY = "library/audio-library/music-library/albums/item";
|
||||
|
||||
private static readonly JsonSerializerOptions s_camelCaseJsonOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly IUrlService _urlService;
|
||||
private readonly ThemePageRenderer _themePageRenderer;
|
||||
private readonly IAntiforgery _antiforgery;
|
||||
private readonly IStringLocalizer _localizer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EditMusicAlbumViewEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
/// <param name="urlService">Injected service for generating URLs from action and controller names, with localization.</param>
|
||||
/// <param name="themePageRenderer">Injected service for rendering themed pages.</param>
|
||||
/// <param name="antiforgery">Injected service for anti-forgery token handling.</param>
|
||||
/// <param name="stringLocalizerFactory">Injected factory used to create the localizer of the view resources.</param>
|
||||
public EditMusicAlbumViewEndpoint(IApiHttpClient apiHttpClient, IUrlService urlService, ThemePageRenderer themePageRenderer, IAntiforgery antiforgery, IStringLocalizerFactory stringLocalizerFactory)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_urlService = urlService;
|
||||
_themePageRenderer = themePageRenderer;
|
||||
_antiforgery = antiforgery;
|
||||
_localizer = stringLocalizerFactory.Create(VIEW_RESOURCE_BASE_NAME, VIEW_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.ALBUM);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the music album details and editing view, rendered by the active theme with a fallback to the Razor view.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the album to view.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMusicAlbumViewRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The view needs the full details of the album to show its current values, so they are fetched from the API up front; the route
|
||||
// values are normalized to Guids before they are substituted into the upstream URL, so that a crafted route value can never escape
|
||||
// its URL segment, and an unparseable id is reported by the API as a missing album id.
|
||||
request = request with { ArtistId = Guid.TryParse(request.ArtistId, out Guid artistId) ? artistId.ToString() : Guid.Empty.ToString() };
|
||||
request = request with { AlbumId = Guid.TryParse(request.AlbumId, out Guid albumId) ? albumId.ToString() : Guid.Empty.ToString() };
|
||||
MusicAlbumDto album = await _apiHttpClient.GetAsync<MusicAlbumDto>(ApiRoutes.Music.GET_ALBUM.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{artistId}", request.ArtistId).Replace("{albumId}", request.AlbumId), cancellationToken).ConfigureAwait(false);
|
||||
string title = album.Metadata?.Title ?? string.Empty;
|
||||
|
||||
// The themed view is a regular page that submits its own requests, so a fresh anti-forgery token must be issued for it.
|
||||
AntiforgeryTokenSet antiforgeryTokens = _antiforgery.GetAndStoreTokens(HttpContext);
|
||||
|
||||
ThemePageDto pageModel = new()
|
||||
{
|
||||
PageKey = VIEW_PAGE_KEY,
|
||||
Title = title,
|
||||
Description = string.Empty,
|
||||
PageData = new Dictionary<string, object?>
|
||||
{
|
||||
["artistId"] = album.ArtistId.ToString(),
|
||||
["albumId"] = album.Id.ToString(),
|
||||
["libraryId"] = album.LibraryId.ToString(),
|
||||
["antiforgeryToken"] = antiforgeryTokens.RequestToken,
|
||||
["saveUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.SAVE_ALBUM, new { artistId = default(Guid), albumId = default(Guid) }) ?? string.Empty,
|
||||
["deleteUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.DELETE_ALBUM, new { artistId = default(Guid), albumId = default(Guid) }) ?? string.Empty,
|
||||
["tracksUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.GET_ALBUM_TRACKS, new { artistId = default(Guid), albumId = default(Guid) }) ?? string.Empty,
|
||||
["trackUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.TRACK, new { artistId = default(Guid), albumId = default(Guid), trackId = default(Guid) }) ?? string.Empty,
|
||||
["coverUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.UPDATE_ALBUM_COVER, new { artistId = default(Guid), albumId = default(Guid) }) ?? string.Empty,
|
||||
["backUrl"] = (_urlService.GetAbsoluteUrl(WebRoutes.Music.ARTIST, new { artistId = album.ArtistId }) ?? string.Empty) + "?libraryId=" + album.LibraryId,
|
||||
["albumJson"] = JsonSerializer.Serialize(album, s_camelCaseJsonOptions),
|
||||
["strings"] = ThemePageDataFactory.CreateLocalizedStrings(_localizer),
|
||||
["stringsJson"] = JsonSerializer.Serialize(ThemePageDataFactory.CreateLocalizedStrings(_localizer), s_camelCaseJsonOptions)
|
||||
}
|
||||
};
|
||||
|
||||
Result<ThemePageRenderResultDto> sectionResult = await _themePageRenderer.RenderAsync(pageModel, requestedThemeId: null, cancellationToken).ConfigureAwait(false);
|
||||
if (sectionResult.IsFailure)
|
||||
{
|
||||
Dictionary<string, object?> viewData = new()
|
||||
{
|
||||
["Title"] = title
|
||||
};
|
||||
return View("/Core/Views/Library/AudioLibrary/MusicLibrary/Albums/Item.cshtml", album, viewData);
|
||||
}
|
||||
|
||||
return View(
|
||||
"/Core/Views/Shared/_ThemedView.cshtml",
|
||||
new ThemeViewDto(sectionResult.Value.Content, sectionResult.Value.Script),
|
||||
new Dictionary<string, object?> { ["Title"] = title });
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Albums;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.EditMusicAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="EditMusicAlbumViewEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class EditMusicAlbumViewEndpointSummary : Summary<EditMusicAlbumViewEndpoint, GetMusicAlbumViewRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EditMusicAlbumViewEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public EditMusicAlbumViewEndpointSummary()
|
||||
{
|
||||
Summary = "Renders the music album details and editing view.";
|
||||
Description = "Renders the view for displaying and editing the music album identified by the route.";
|
||||
|
||||
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album belongs to. Required.");
|
||||
RequestParam(r => r.AlbumId, "The unique identifier of the album to display. Required.");
|
||||
RequestParam(r => r.LibraryId, "The unique identifier of the media library the album belongs to. Required.");
|
||||
|
||||
Response(200, "The view for displaying and editing the music album is rendered.");
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetArtistAlbums;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/api-get-albums</c> route.
|
||||
/// </summary>
|
||||
public class GetArtistAlbumsEndpoint : BaseEndpoint<GetArtistAlbumsLiteRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetArtistAlbumsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetArtistAlbumsEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.GET_ARTIST_ALBUMS);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the lightweight details of the albums of a music artist.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the parameters used to retrieve the albums.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetArtistAlbumsLiteRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
PaginatedMusicAlbumLiteDto response = await _apiHttpClient.GetAsync<PaginatedMusicAlbumLiteDto>(BuildItemsEndpoint(request), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the lightweight details of the albums of a music artist.
|
||||
/// </summary>
|
||||
/// <param name="query">The request containing the parameters used to retrieve the albums.</param>
|
||||
/// <returns>The API endpoint to which the retrieval request is sent.</returns>
|
||||
private static string BuildItemsEndpoint(GetArtistAlbumsLiteRequest query)
|
||||
{
|
||||
// The route value is normalized to a Guid before it is substituted into the upstream URL, so that a crafted route value can never
|
||||
// escape its URL segment, and an unparseable id is reported by the API as a missing artist id.
|
||||
string artistId = Guid.TryParse(query.ArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
StringBuilder endpoint = new(ApiRoutes.Music.GET_ARTIST_ALBUMS_LITE.Replace("{libraryId}", query.LibraryId.ToString()).Replace("{artistId}", artistId));
|
||||
List<string> parameters = [];
|
||||
if (query.CurrentPage is not null)
|
||||
parameters.Add($"currentPage={query.CurrentPage}");
|
||||
if (query.PerPage is not null)
|
||||
parameters.Add($"perPage={query.PerPage}");
|
||||
if (parameters.Count > 0)
|
||||
endpoint.Append('?').Append(string.Join('&', parameters));
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Albums;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetArtistAlbums;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetArtistAlbumsEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, GetArtistAlbumsLiteRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetArtistAlbumsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetArtistAlbumsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the lightweight details of the albums of a music artist.";
|
||||
Description = "Retrieves the lightweight read models of the albums of the music artist identified by the route.";
|
||||
|
||||
RequestParam(r => r.ArtistId, "The unique identifier of the artist whose albums are retrieved. Required.");
|
||||
RequestParam(r => r.LibraryId, "The Id of the media library the artist belongs to. Required.");
|
||||
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
|
||||
RequestParam(r => r.PerPage, "The maximum number of albums to retrieve per page. Optional.");
|
||||
|
||||
ExampleRequest = new GetArtistAlbumsLiteRequest(
|
||||
ArtistId: Guid.NewGuid().ToString(),
|
||||
LibraryId: Guid.NewGuid(),
|
||||
CurrentPage: 1,
|
||||
PerPage: 10
|
||||
);
|
||||
|
||||
Response(200, "The lightweight details of the albums of the music artist are retrieved.");
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetMusicAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/api-get-album</c> route.
|
||||
/// </summary>
|
||||
public class GetMusicAlbumEndpoint : BaseEndpoint<GetMusicAlbumViewRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicAlbumEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetMusicAlbumEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.GET_ALBUM);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the full details of the music album identified by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the album to retrieve.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMusicAlbumViewRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The route values are normalized to Guids before they are substituted into the upstream URL, so that a crafted route value can never
|
||||
// escape its URL segment, and an unparseable id is reported by the API as a missing album id.
|
||||
request = request with { ArtistId = Guid.TryParse(request.ArtistId, out Guid artistId) ? artistId.ToString() : Guid.Empty.ToString() };
|
||||
request = request with { AlbumId = Guid.TryParse(request.AlbumId, out Guid albumId) ? albumId.ToString() : Guid.Empty.ToString() };
|
||||
|
||||
MusicAlbumDto album = await _apiHttpClient.GetAsync<MusicAlbumDto>(ApiRoutes.Music.GET_ALBUM.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{artistId}", request.ArtistId).Replace("{albumId}", request.AlbumId), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(album);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Albums;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetMusicAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetMusicAlbumEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetMusicAlbumEndpointSummary : Summary<GetMusicAlbumEndpoint, GetMusicAlbumViewRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicAlbumEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetMusicAlbumEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the full details of a music album.";
|
||||
Description = "Retrieves the full details of the music album identified by the route.";
|
||||
|
||||
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album belongs to. Required.");
|
||||
RequestParam(r => r.AlbumId, "The unique identifier of the album to retrieve. Required.");
|
||||
RequestParam(r => r.LibraryId, "The unique identifier of the media library the album belongs to. Required.");
|
||||
|
||||
Response(200, "The full details of the music album are retrieved.");
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.SaveMusicAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/api-save-album</c> route.
|
||||
/// </summary>
|
||||
public class SaveMusicAlbumEndpoint : BaseEndpoint<UpdateMusicAlbumRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SaveMusicAlbumEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public SaveMusicAlbumEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.PUT);
|
||||
Routes(WebRoutes.Music.SAVE_ALBUM);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the music album described by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the edited details of the album.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(UpdateMusicAlbumRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The album is identified by the {artistId} and {albumId} route values, not by any id posted in the body, so that a mismatched id can
|
||||
// never redirect the update to another album; all ids are normalized to Guids before they are substituted into the upstream URL, so
|
||||
// that a crafted value can never escape its URL segment, and an unparseable id is reported by the API as a missing id.
|
||||
string routeArtistId = HttpContext.Request.RouteValues["artistId"]?.ToString() ?? string.Empty;
|
||||
string artistId = Guid.TryParse(routeArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
string routeAlbumId = HttpContext.Request.RouteValues["albumId"]?.ToString() ?? string.Empty;
|
||||
string albumId = Guid.TryParse(routeAlbumId, out Guid parsedAlbumId) ? parsedAlbumId.ToString() : Guid.Empty.ToString();
|
||||
string queryLibraryId = HttpContext.Request.Query["libraryId"].ToString();
|
||||
string libraryId = Guid.TryParse(queryLibraryId, out Guid parsedLibraryId) ? parsedLibraryId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
MusicAlbumDto album = await _apiHttpClient.PutAsync<MusicAlbumDto, UpdateMusicAlbumRequest>(
|
||||
ApiRoutes.Music.UPDATE_ALBUM.Replace("{libraryId}", libraryId).Replace("{artistId}", artistId).Replace("{albumId}", albumId), request, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(album);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Albums;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.SaveMusicAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="SaveMusicAlbumEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SaveMusicAlbumEndpointSummary : Summary<SaveMusicAlbumEndpoint, UpdateMusicAlbumRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SaveMusicAlbumEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public SaveMusicAlbumEndpointSummary()
|
||||
{
|
||||
Summary = "Updates a music album.";
|
||||
Description = "Updates the music album identified by the route, together with the tracks of the album.";
|
||||
|
||||
Response(200, "The music album was updated.");
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.UpdateAlbumCover;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/api-update-cover</c> route.
|
||||
/// </summary>
|
||||
public class UpdateAlbumCoverEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateAlbumCoverEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public UpdateAlbumCoverEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.PUT);
|
||||
Routes(WebRoutes.Music.UPDATE_ALBUM_COVER);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the cover image of the album with the image uploaded in the multipart form of the request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The endpoint takes no typed request, because its body is a multipart file, so the album id is read from the {albumId} route value and the
|
||||
// owning library from the {libraryId} query string; all the ids are normalized to Guids before they are substituted into the upstream URL, so
|
||||
// that a crafted value can never escape its URL segment, and an unparseable id is reported by the API as a missing id. A missing file is
|
||||
// forwarded as a multipart form without any file, so that the upstream API reports it with its own validation error.
|
||||
Guid artistId = Guid.TryParse(HttpContext.Request.RouteValues["artistId"]?.ToString(), out Guid parsedArtistId) ? parsedArtistId : Guid.Empty;
|
||||
Guid albumId = Guid.TryParse(HttpContext.Request.RouteValues["albumId"]?.ToString(), out Guid parsedAlbumId) ? parsedAlbumId : Guid.Empty;
|
||||
string libraryId = Guid.TryParse(HttpContext.Request.Query["libraryId"].ToString(), out Guid parsedLibraryId) ? parsedLibraryId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
IFormFile? cover = null;
|
||||
if (HttpContext.Request.HasFormContentType)
|
||||
{
|
||||
try
|
||||
{
|
||||
cover = HttpContext.Request.Form.Files.Count > 0 ? HttpContext.Request.Form.Files[0] : null;
|
||||
}
|
||||
catch (InvalidDataException)
|
||||
{
|
||||
cover = null;
|
||||
}
|
||||
}
|
||||
|
||||
// The cover stream must stay open while the file is streamed to the API, and is disposed when the request completes.
|
||||
Stream? coverStream = cover?.OpenReadStream();
|
||||
try
|
||||
{
|
||||
UpdateMusicCoverDto response = await _apiHttpClient.PutMultipartAsync<UpdateMusicCoverDto>(
|
||||
ApiRoutes.Music.UPDATE_ALBUM_COVER.Replace("{libraryId}", libraryId).Replace("{artistId}", artistId.ToString()).Replace("{albumId}", albumId.ToString()), coverStream, cover?.FileName, "cover", cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response.CoverPath);
|
||||
}
|
||||
finally
|
||||
{
|
||||
coverStream?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.UpdateAlbumCover;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="UpdateAlbumCoverEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateAlbumCoverEndpointSummary : Summary<UpdateAlbumCoverEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateAlbumCoverEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public UpdateAlbumCoverEndpointSummary()
|
||||
{
|
||||
Summary = "Updates the cover image of an album.";
|
||||
Description = "Updates the cover image of the album identified by the route, with the image uploaded in the multipart form of the request.";
|
||||
|
||||
Response(200, "The relative path of the stored cover image is returned.", example: new SuccessResponse<string>(true, default));
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.DeleteMusicArtist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/api-delete-artist</c> route.
|
||||
/// </summary>
|
||||
public class DeleteMusicArtistEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteMusicArtistEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public DeleteMusicArtistEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.DELETE);
|
||||
Routes(WebRoutes.Music.DELETE_ARTIST);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the music artist identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The artist is identified by the {artistId} route value; both ids are normalized to Guids before they are substituted into the
|
||||
// upstream URL, so that a crafted value can never escape its URL segment, and an unparseable id is reported by the API as a missing id.
|
||||
string routeArtistId = HttpContext.Request.RouteValues["artistId"]?.ToString() ?? string.Empty;
|
||||
string artistId = Guid.TryParse(routeArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
string queryLibraryId = HttpContext.Request.Query["libraryId"].ToString();
|
||||
string libraryId = Guid.TryParse(queryLibraryId, out Guid parsedLibraryId) ? parsedLibraryId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
await _apiHttpClient.DeleteAsync(ApiRoutes.Music.DELETE_ARTIST.Replace("{libraryId}", libraryId).Replace("{artistId}", artistId), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.DeleteMusicArtist;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="DeleteMusicArtistEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteMusicArtistEndpointSummary : Summary<DeleteMusicArtistEndpoint>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteMusicArtistEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public DeleteMusicArtistEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes a music artist.";
|
||||
Description = "Deletes the music artist identified by the route, together with its albums and tracks.";
|
||||
|
||||
Response(200, "The music artist was deleted.");
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Antiforgery;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.EditMusicArtist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}</c> route.
|
||||
/// </summary>
|
||||
public class EditMusicArtistViewEndpoint : BaseEndpoint<GetMusicArtistViewRequest, IResult>
|
||||
{
|
||||
// The resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it with the configured ResourcesPath.
|
||||
private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Library.AudioLibrary.MusicLibrary.Artists.Item";
|
||||
private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web";
|
||||
// The page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope.
|
||||
private const string VIEW_PAGE_KEY = "library/audio-library/music-library/artists/item";
|
||||
|
||||
private static readonly JsonSerializerOptions s_camelCaseJsonOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly IUrlService _urlService;
|
||||
private readonly ThemePageRenderer _themePageRenderer;
|
||||
private readonly IAntiforgery _antiforgery;
|
||||
private readonly IStringLocalizer _localizer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EditMusicArtistViewEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
/// <param name="urlService">Injected service for generating URLs from action and controller names, with localization.</param>
|
||||
/// <param name="themePageRenderer">Injected service for rendering themed pages.</param>
|
||||
/// <param name="antiforgery">Injected service for anti-forgery token handling.</param>
|
||||
/// <param name="stringLocalizerFactory">Injected factory used to create the localizer of the view resources.</param>
|
||||
public EditMusicArtistViewEndpoint(IApiHttpClient apiHttpClient, IUrlService urlService, ThemePageRenderer themePageRenderer, IAntiforgery antiforgery, IStringLocalizerFactory stringLocalizerFactory)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_urlService = urlService;
|
||||
_themePageRenderer = themePageRenderer;
|
||||
_antiforgery = antiforgery;
|
||||
_localizer = stringLocalizerFactory.Create(VIEW_RESOURCE_BASE_NAME, VIEW_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.ARTIST);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the music artist details and editing view, rendered by the active theme with a fallback to the Razor view.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the artist to view.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMusicArtistViewRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The view needs the full details of the artist to show its current values, so they are fetched from the API up front; the route
|
||||
// value is normalized to a Guid before it is substituted into the upstream URL, so that a crafted route value can never escape
|
||||
// its URL segment, and an unparseable id is reported by the API as a missing artist id.
|
||||
request = request with { ArtistId = Guid.TryParse(request.ArtistId, out Guid artistId) ? artistId.ToString() : Guid.Empty.ToString() };
|
||||
MusicArtistDto artist = await _apiHttpClient.GetAsync<MusicArtistDto>(ApiRoutes.Music.GET_ARTIST.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{artistId}", request.ArtistId), cancellationToken).ConfigureAwait(false);
|
||||
string title = artist.Metadata?.Name ?? string.Empty;
|
||||
|
||||
// The themed view is a regular page that submits its own requests, so a fresh anti-forgery token must be issued for it.
|
||||
AntiforgeryTokenSet antiforgeryTokens = _antiforgery.GetAndStoreTokens(HttpContext);
|
||||
|
||||
ThemePageDto pageModel = new()
|
||||
{
|
||||
PageKey = VIEW_PAGE_KEY,
|
||||
Title = title,
|
||||
Description = string.Empty,
|
||||
PageData = new Dictionary<string, object?>
|
||||
{
|
||||
["artistId"] = artist.Id.ToString(),
|
||||
["libraryId"] = artist.LibraryId.ToString(),
|
||||
["antiforgeryToken"] = antiforgeryTokens.RequestToken,
|
||||
["saveUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.SAVE_ARTIST, new { artistId = default(Guid) }) ?? string.Empty,
|
||||
["deleteUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.DELETE_ARTIST, new { artistId = default(Guid) }) ?? string.Empty,
|
||||
["albumsUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.GET_ARTIST_ALBUMS, new { artistId = default(Guid) }) ?? string.Empty,
|
||||
["albumUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.ALBUM, new { artistId = default(Guid), albumId = default(Guid) }) ?? string.Empty,
|
||||
["deleteAlbumUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.DELETE_ALBUM, new { artistId = default(Guid), albumId = default(Guid) }) ?? string.Empty,
|
||||
["coverUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.UPDATE_ARTIST_COVER, new { artistId = default(Guid) }) ?? string.Empty,
|
||||
["backUrl"] = (_urlService.GetAbsoluteUrl(WebRoutes.Music.ARTISTS_INDEX) ?? string.Empty) + "?libraryId=" + artist.LibraryId,
|
||||
["artistJson"] = JsonSerializer.Serialize(artist, s_camelCaseJsonOptions),
|
||||
["strings"] = ThemePageDataFactory.CreateLocalizedStrings(_localizer),
|
||||
["stringsJson"] = JsonSerializer.Serialize(ThemePageDataFactory.CreateLocalizedStrings(_localizer), s_camelCaseJsonOptions)
|
||||
}
|
||||
};
|
||||
|
||||
Result<ThemePageRenderResultDto> sectionResult = await _themePageRenderer.RenderAsync(pageModel, requestedThemeId: null, cancellationToken).ConfigureAwait(false);
|
||||
if (sectionResult.IsFailure)
|
||||
{
|
||||
Dictionary<string, object?> viewData = new()
|
||||
{
|
||||
["Title"] = title
|
||||
};
|
||||
return View("/Core/Views/Library/AudioLibrary/MusicLibrary/Artists/Item.cshtml", artist, viewData);
|
||||
}
|
||||
|
||||
return View(
|
||||
"/Core/Views/Shared/_ThemedView.cshtml",
|
||||
new ThemeViewDto(sectionResult.Value.Content, sectionResult.Value.Script),
|
||||
new Dictionary<string, object?> { ["Title"] = title });
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.EditMusicArtist;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="EditMusicArtistViewEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class EditMusicArtistViewEndpointSummary : Summary<EditMusicArtistViewEndpoint, GetMusicArtistViewRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EditMusicArtistViewEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public EditMusicArtistViewEndpointSummary()
|
||||
{
|
||||
Summary = "Renders the music artist details and editing view.";
|
||||
Description = "Renders the view for displaying and editing the music artist identified by the route.";
|
||||
|
||||
RequestParam(r => r.ArtistId, "The unique identifier of the artist to display. Required.");
|
||||
RequestParam(r => r.LibraryId, "The unique identifier of the media library the artist belongs to. Required.");
|
||||
|
||||
Response(200, "The view for displaying and editing the music artist is rendered.");
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetMusicArtist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/api-get-artist</c> route.
|
||||
/// </summary>
|
||||
public class GetMusicArtistEndpoint : BaseEndpoint<GetMusicArtistViewRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicArtistEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetMusicArtistEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.GET_ARTIST);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the full details of the music artist identified by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the artist to retrieve.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMusicArtistViewRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The route value is normalized to a Guid before it is substituted into the upstream URL, so that a crafted route value can never
|
||||
// escape its URL segment, and an unparseable id is reported by the API as a missing artist id.
|
||||
request = request with { ArtistId = Guid.TryParse(request.ArtistId, out Guid artistId) ? artistId.ToString() : Guid.Empty.ToString() };
|
||||
|
||||
MusicArtistDto artist = await _apiHttpClient.GetAsync<MusicArtistDto>(ApiRoutes.Music.GET_ARTIST.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{artistId}", request.ArtistId), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(artist);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetMusicArtist;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetMusicArtistEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetMusicArtistEndpointSummary : Summary<GetMusicArtistEndpoint, GetMusicArtistViewRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicArtistEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetMusicArtistEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the full details of a music artist.";
|
||||
Description = "Retrieves the full details of the music artist identified by the route.";
|
||||
|
||||
RequestParam(r => r.ArtistId, "The unique identifier of the artist to retrieve. Required.");
|
||||
RequestParam(r => r.LibraryId, "The unique identifier of the media library the artist belongs to. Required.");
|
||||
|
||||
Response(200, "The full details of the music artist are retrieved.");
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetMusicArtists;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/api-get-artists</c> route.
|
||||
/// </summary>
|
||||
public class GetMusicArtistsEndpoint : BaseEndpoint<GetMusicArtistsLiteRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicArtistsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetMusicArtistsEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.GET_ARTISTS);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the lightweight details of the music artists of a media library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the parameters used to retrieve the artists.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMusicArtistsLiteRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
PaginatedMusicArtistLiteDto response = await _apiHttpClient.GetAsync<PaginatedMusicArtistLiteDto>(BuildItemsEndpoint(request), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the lightweight details of the music artists of a media library.
|
||||
/// </summary>
|
||||
/// <param name="query">The request containing the parameters used to retrieve the artists.</param>
|
||||
/// <returns>The API endpoint to which the retrieval request is sent.</returns>
|
||||
private static string BuildItemsEndpoint(GetMusicArtistsLiteRequest query)
|
||||
{
|
||||
StringBuilder endpoint = new(ApiRoutes.Music.GET_ARTISTS_LITE.Replace("{libraryId}", query.LibraryId.ToString()));
|
||||
List<string> parameters = [];
|
||||
if (query.CurrentPage is not null)
|
||||
parameters.Add($"currentPage={query.CurrentPage}");
|
||||
if (query.PerPage is not null)
|
||||
parameters.Add($"perPage={query.PerPage}");
|
||||
if (!string.IsNullOrWhiteSpace(query.SearchTerm))
|
||||
parameters.Add($"searchTerm={Uri.EscapeDataString(query.SearchTerm)}");
|
||||
if (!string.IsNullOrWhiteSpace(query.FilterAlphaKey))
|
||||
parameters.Add($"filterAlphaKey={Uri.EscapeDataString(query.FilterAlphaKey)}");
|
||||
parameters.Add($"shouldIgnoreThePrefixForAlphaPicker={query.ShouldIgnoreThePrefixForAlphaPicker}");
|
||||
if (!string.IsNullOrWhiteSpace(query.SortBy))
|
||||
parameters.Add($"sortBy={Uri.EscapeDataString(query.SortBy)}");
|
||||
if (query.SortOrder is not null)
|
||||
parameters.Add($"sortOrder={query.SortOrder}");
|
||||
if (parameters.Count > 0)
|
||||
endpoint.Append('?').Append(string.Join('&', parameters));
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetMusicArtists;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetMusicArtistsEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetMusicArtistsEndpointSummary : Summary<GetMusicArtistsEndpoint, GetMusicArtistsLiteRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicArtistsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetMusicArtistsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the lightweight details of the music artists of a media library.";
|
||||
Description = "Retrieves the lightweight read models of the music artists of the media library identified by the route.";
|
||||
|
||||
RequestParam(r => r.LibraryId, "The Id of the media library whose artists are retrieved. Required.");
|
||||
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
|
||||
RequestParam(r => r.PerPage, "The maximum number of artists to retrieve per page. Optional.");
|
||||
RequestParam(r => r.SearchTerm, "The search term used to filter the artists by name. Optional.");
|
||||
RequestParam(r => r.FilterAlphaKey, "The alpha key used to filter the results by the first character of their name, for the alpha picker. Optional.");
|
||||
RequestParam(r => r.ShouldIgnoreThePrefixForAlphaPicker, "Whether the leading \"The \" prefix of a name is ignored when computing the alpha key, or not. Optional.");
|
||||
RequestParam(r => r.SortBy, "The name of the field by which to sort the results. Optional.");
|
||||
RequestParam(r => r.SortOrder, "The direction in which to sort the results. Optional.");
|
||||
|
||||
ExampleRequest = new GetMusicArtistsLiteRequest(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
CurrentPage: 1,
|
||||
PerPage: 10,
|
||||
SearchTerm: "queen",
|
||||
FilterAlphaKey: null,
|
||||
ShouldIgnoreThePrefixForAlphaPicker: false,
|
||||
SortBy: null,
|
||||
SortOrder: null
|
||||
);
|
||||
|
||||
Response(200, "The lightweight details of the music artists of the media library are retrieved.");
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Antiforgery;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.Index;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists</c> route.
|
||||
/// </summary>
|
||||
public class MusicArtistsIndexViewEndpoint : BaseEndpoint<GetMusicArtistsViewRequest, IResult>
|
||||
{
|
||||
// The resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it
|
||||
// with the configured ResourcesPath, so "Lumina.Presentation.Web.Views.X" resolves to the embedded
|
||||
// "Lumina.Presentation.Web.Core.Resources.Views.X" resource; including "Core" here would insert it twice.
|
||||
private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Library.AudioLibrary.MusicLibrary.Artists.Index";
|
||||
private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web";
|
||||
// The page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope.
|
||||
private const string VIEW_PAGE_KEY = "library/audio-library/music-library/artists/index";
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly IUrlService _urlService;
|
||||
private readonly ThemePageRenderer _themePageRenderer;
|
||||
private readonly IAntiforgery _antiforgery;
|
||||
private readonly IStringLocalizer _localizer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MusicArtistsIndexViewEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
/// <param name="urlService">Injected service for generating URLs from action and controller names, with localization.</param>
|
||||
/// <param name="themePageRenderer">Injected service for rendering themed pages.</param>
|
||||
/// <param name="antiforgery">Injected service for anti-forgery token handling.</param>
|
||||
/// <param name="stringLocalizerFactory">Injected factory used to create the localizer of the view resources.</param>
|
||||
public MusicArtistsIndexViewEndpoint(IApiHttpClient apiHttpClient, IUrlService urlService, ThemePageRenderer themePageRenderer, IAntiforgery antiforgery, IStringLocalizerFactory stringLocalizerFactory)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_urlService = urlService;
|
||||
_themePageRenderer = themePageRenderer;
|
||||
_antiforgery = antiforgery;
|
||||
_localizer = stringLocalizerFactory.Create(VIEW_RESOURCE_BASE_NAME, VIEW_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.ARTISTS_INDEX);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the music artists browsing view, rendered by the active theme with a fallback to the Razor view.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the media library whose artists are browsed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMusicArtistsViewRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.LibraryId is null)
|
||||
return Results.Redirect(_urlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED)!);
|
||||
LibraryDto library = await _apiHttpClient.GetAsync<LibraryDto>(ApiRoutes.Libraries.GET_LIBRARY_BY_ID.Replace("{id}", request.LibraryId.Value.ToString()), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// The page exposes delete actions, which submit through the form anti-forgery token, so a fresh token is issued for it.
|
||||
AntiforgeryTokenSet antiforgeryTokens = _antiforgery.GetAndStoreTokens(HttpContext);
|
||||
|
||||
ThemePageDto pageModel = new()
|
||||
{
|
||||
PageKey = VIEW_PAGE_KEY,
|
||||
Title = library.Title ?? string.Empty,
|
||||
Description = string.Empty,
|
||||
PageData = new Dictionary<string, object?>
|
||||
{
|
||||
["libraryId"] = library.Id?.ToString() ?? request.LibraryId.Value.ToString(),
|
||||
["antiforgeryToken"] = antiforgeryTokens.RequestToken,
|
||||
["itemsUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.GET_ARTISTS) ?? string.Empty,
|
||||
["settingsUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Settings.GET_USER_SETTINGS) ?? string.Empty,
|
||||
["artistUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.ARTIST, new { artistId = default(Guid) }) ?? string.Empty,
|
||||
["deleteUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.DELETE_ARTIST, new { artistId = default(Guid) }) ?? string.Empty,
|
||||
["strings"] = ThemePageDataFactory.CreateLocalizedStrings(_localizer)
|
||||
}
|
||||
};
|
||||
|
||||
Result<ThemePageRenderResultDto> sectionResult = await _themePageRenderer.RenderAsync(pageModel, requestedThemeId: null, cancellationToken).ConfigureAwait(false);
|
||||
if (sectionResult.IsFailure)
|
||||
return View("/Core/Views/Library/AudioLibrary/MusicLibrary/Artists/Index.cshtml", library);
|
||||
|
||||
return View(
|
||||
"/Core/Views/Shared/_ThemedView.cshtml",
|
||||
new ThemeViewDto(sectionResult.Value.Content, sectionResult.Value.Script),
|
||||
new Dictionary<string, object?> { ["Title"] = pageModel.Title });
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.Index;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="MusicArtistsIndexViewEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicArtistsIndexViewEndpointSummary : Summary<MusicArtistsIndexViewEndpoint, GetMusicArtistsViewRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MusicArtistsIndexViewEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public MusicArtistsIndexViewEndpointSummary()
|
||||
{
|
||||
Summary = "Renders the music artists browsing view.";
|
||||
Description = "Renders the view for browsing the music artists of the media library identified by the query.";
|
||||
|
||||
RequestParam(r => r.LibraryId, "The unique identifier of the media library whose artists are browsed. Optional.");
|
||||
|
||||
ExampleRequest = new GetMusicArtistsViewRequest(
|
||||
LibraryId: Guid.NewGuid()
|
||||
);
|
||||
|
||||
Response(200, "The view for browsing the music artists of the media library is rendered.");
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.SaveMusicArtist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/api-save-artist</c> route.
|
||||
/// </summary>
|
||||
public class SaveMusicArtistEndpoint : BaseEndpoint<UpdateMusicArtistRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SaveMusicArtistEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public SaveMusicArtistEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.PUT);
|
||||
Routes(WebRoutes.Music.SAVE_ARTIST);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the music artist described by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the edited details of the artist.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(UpdateMusicArtistRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The artist is identified by the {artistId} route value, not by any id posted in the body, so that a mismatched id can never redirect
|
||||
// the update to another artist; both ids are normalized to Guids before they are substituted into the upstream URL, so that a crafted
|
||||
// value can never escape its URL segment, and an unparseable id is reported by the API as a missing id.
|
||||
string routeArtistId = HttpContext.Request.RouteValues["artistId"]?.ToString() ?? string.Empty;
|
||||
string artistId = Guid.TryParse(routeArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
string queryLibraryId = HttpContext.Request.Query["libraryId"].ToString();
|
||||
string libraryId = Guid.TryParse(queryLibraryId, out Guid parsedLibraryId) ? parsedLibraryId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
MusicArtistDto artist = await _apiHttpClient.PutAsync<MusicArtistDto, UpdateMusicArtistRequest>(
|
||||
ApiRoutes.Music.UPDATE_ARTIST.Replace("{libraryId}", libraryId).Replace("{artistId}", artistId), request, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(artist);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Artists;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.SaveMusicArtist;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="SaveMusicArtistEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SaveMusicArtistEndpointSummary : Summary<SaveMusicArtistEndpoint, UpdateMusicArtistRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SaveMusicArtistEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public SaveMusicArtistEndpointSummary()
|
||||
{
|
||||
Summary = "Updates a music artist.";
|
||||
Description = "Updates the music artist identified by the route, together with the albums of the artist and the tracks of those albums.";
|
||||
|
||||
Response(200, "The music artist was updated.");
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.UpdateArtistCover;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/api-update-cover</c> route.
|
||||
/// </summary>
|
||||
public class UpdateArtistCoverEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateArtistCoverEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public UpdateArtistCoverEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.PUT);
|
||||
Routes(WebRoutes.Music.UPDATE_ARTIST_COVER);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the cover image of the artist with the image uploaded in the multipart form of the request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The endpoint takes no typed request, because its body is a multipart file, so the artist id is read from the {artistId} route value and the
|
||||
// owning library from the {libraryId} query string; both are normalized to Guids before they are substituted into the upstream URL, so that a
|
||||
// crafted value can never escape its URL segment, and an unparseable id is reported by the API as a missing id. A missing file is forwarded
|
||||
// as a multipart form without any file, so that the upstream API reports it with its own validation error.
|
||||
Guid artistId = Guid.TryParse(HttpContext.Request.RouteValues["artistId"]?.ToString(), out Guid parsedArtistId) ? parsedArtistId : Guid.Empty;
|
||||
string libraryId = Guid.TryParse(HttpContext.Request.Query["libraryId"].ToString(), out Guid parsedLibraryId) ? parsedLibraryId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
IFormFile? cover = null;
|
||||
if (HttpContext.Request.HasFormContentType)
|
||||
{
|
||||
try
|
||||
{
|
||||
cover = HttpContext.Request.Form.Files.Count > 0 ? HttpContext.Request.Form.Files[0] : null;
|
||||
}
|
||||
catch (InvalidDataException)
|
||||
{
|
||||
cover = null;
|
||||
}
|
||||
}
|
||||
|
||||
// The cover stream must stay open while the file is streamed to the API, and is disposed when the request completes.
|
||||
Stream? coverStream = cover?.OpenReadStream();
|
||||
try
|
||||
{
|
||||
UpdateMusicCoverDto response = await _apiHttpClient.PutMultipartAsync<UpdateMusicCoverDto>(
|
||||
ApiRoutes.Music.UPDATE_ARTIST_COVER.Replace("{libraryId}", libraryId).Replace("{artistId}", artistId.ToString()), coverStream, cover?.FileName, "cover", cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response.CoverPath);
|
||||
}
|
||||
finally
|
||||
{
|
||||
coverStream?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.UpdateArtistCover;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="UpdateArtistCoverEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateArtistCoverEndpointSummary : Summary<UpdateArtistCoverEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateArtistCoverEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public UpdateArtistCoverEndpointSummary()
|
||||
{
|
||||
Summary = "Updates the cover image of an artist.";
|
||||
Description = "Updates the cover image of the artist identified by the route, with the image uploaded in the multipart form of the request.";
|
||||
|
||||
Response(200, "The relative path of the stored cover image is returned.", example: new SuccessResponse<string>(true, default));
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.DeleteMusicTrack;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-delete-track</c> route.
|
||||
/// </summary>
|
||||
public class DeleteMusicTrackEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteMusicTrackEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public DeleteMusicTrackEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.DELETE);
|
||||
Routes(WebRoutes.Music.DELETE_TRACK);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the music track identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The track is identified by the {artistId}, {albumId} and {trackId} route values; all ids are normalized to Guids before they are substituted
|
||||
// into the upstream URL, so that a crafted value can never escape its URL segment, and an unparseable id is reported by the API as a missing id.
|
||||
string routeArtistId = HttpContext.Request.RouteValues["artistId"]?.ToString() ?? string.Empty;
|
||||
string artistId = Guid.TryParse(routeArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
string routeAlbumId = HttpContext.Request.RouteValues["albumId"]?.ToString() ?? string.Empty;
|
||||
string albumId = Guid.TryParse(routeAlbumId, out Guid parsedAlbumId) ? parsedAlbumId.ToString() : Guid.Empty.ToString();
|
||||
string routeTrackId = HttpContext.Request.RouteValues["trackId"]?.ToString() ?? string.Empty;
|
||||
string trackId = Guid.TryParse(routeTrackId, out Guid parsedTrackId) ? parsedTrackId.ToString() : Guid.Empty.ToString();
|
||||
string queryLibraryId = HttpContext.Request.Query["libraryId"].ToString();
|
||||
string libraryId = Guid.TryParse(queryLibraryId, out Guid parsedLibraryId) ? parsedLibraryId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
await _apiHttpClient.DeleteAsync(ApiRoutes.Music.DELETE_TRACK.Replace("{libraryId}", libraryId).Replace("{artistId}", artistId).Replace("{albumId}", albumId).Replace("{trackId}", trackId), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.DeleteMusicTrack;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="DeleteMusicTrackEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteMusicTrackEndpointSummary : Summary<DeleteMusicTrackEndpoint>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteMusicTrackEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public DeleteMusicTrackEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes a music track.";
|
||||
Description = "Deletes the music track identified by the route, together with its metadata.";
|
||||
|
||||
Response(200, "The music track was deleted.");
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Antiforgery;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.EditMusicTrack;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}</c> route.
|
||||
/// </summary>
|
||||
public class EditMusicTrackViewEndpoint : BaseEndpoint<GetMusicTrackViewRequest, IResult>
|
||||
{
|
||||
// The resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it with the configured ResourcesPath.
|
||||
private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Library.AudioLibrary.MusicLibrary.Tracks.Item";
|
||||
private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web";
|
||||
// The page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope.
|
||||
private const string VIEW_PAGE_KEY = "library/audio-library/music-library/tracks/item";
|
||||
|
||||
private static readonly JsonSerializerOptions s_camelCaseJsonOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly IUrlService _urlService;
|
||||
private readonly ThemePageRenderer _themePageRenderer;
|
||||
private readonly IAntiforgery _antiforgery;
|
||||
private readonly IStringLocalizer _localizer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EditMusicTrackViewEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
/// <param name="urlService">Injected service for generating URLs from action and controller names, with localization.</param>
|
||||
/// <param name="themePageRenderer">Injected service for rendering themed pages.</param>
|
||||
/// <param name="antiforgery">Injected service for anti-forgery token handling.</param>
|
||||
/// <param name="stringLocalizerFactory">Injected factory used to create the localizer of the view resources.</param>
|
||||
public EditMusicTrackViewEndpoint(IApiHttpClient apiHttpClient, IUrlService urlService, ThemePageRenderer themePageRenderer, IAntiforgery antiforgery, IStringLocalizerFactory stringLocalizerFactory)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_urlService = urlService;
|
||||
_themePageRenderer = themePageRenderer;
|
||||
_antiforgery = antiforgery;
|
||||
_localizer = stringLocalizerFactory.Create(VIEW_RESOURCE_BASE_NAME, VIEW_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.TRACK);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the music track details and editing view, rendered by the active theme with a fallback to the Razor view.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Ids of the artist, album, track and media library to view.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMusicTrackViewRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The view needs the full details of the track to show its current values, so they are fetched from the API up front; the route
|
||||
// values are normalized to Guids before they are substituted into the upstream URL, so that a crafted route value can never escape
|
||||
// its URL segment, and an unparseable id is reported by the API as a missing id.
|
||||
string normalizedArtistId = Guid.TryParse(request.ArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
string normalizedAlbumId = Guid.TryParse(request.AlbumId, out Guid parsedAlbumId) ? parsedAlbumId.ToString() : Guid.Empty.ToString();
|
||||
string normalizedTrackId = Guid.TryParse(request.TrackId, out Guid parsedTrackId) ? parsedTrackId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
MusicTrackDto track = await _apiHttpClient.GetAsync<MusicTrackDto>(
|
||||
ApiRoutes.Music.GET_TRACK.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{artistId}", normalizedArtistId).Replace("{albumId}", normalizedAlbumId).Replace("{trackId}", normalizedTrackId), cancellationToken).ConfigureAwait(false);
|
||||
string title = track.Metadata?.Title ?? string.Empty;
|
||||
|
||||
// The cover shown on the left of the track page is the cover of the album that holds the track, so the album is fetched alongside the track.
|
||||
MusicAlbumDto album = await _apiHttpClient.GetAsync<MusicAlbumDto>(
|
||||
ApiRoutes.Music.GET_ALBUM.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{artistId}", normalizedArtistId).Replace("{albumId}", normalizedAlbumId), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// The themed view is a regular page that submits its own requests, so a fresh anti-forgery token must be issued for it.
|
||||
AntiforgeryTokenSet antiforgeryTokens = _antiforgery.GetAndStoreTokens(HttpContext);
|
||||
|
||||
ThemePageDto pageModel = new()
|
||||
{
|
||||
PageKey = VIEW_PAGE_KEY,
|
||||
Title = title,
|
||||
Description = string.Empty,
|
||||
PageData = new Dictionary<string, object?>
|
||||
{
|
||||
["artistId"] = normalizedArtistId,
|
||||
["albumId"] = normalizedAlbumId,
|
||||
["trackId"] = track.Id.ToString(),
|
||||
["libraryId"] = track.LibraryId.ToString(),
|
||||
["antiforgeryToken"] = antiforgeryTokens.RequestToken,
|
||||
["saveUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.SAVE_TRACK, new { artistId = default(Guid), albumId = default(Guid), trackId = default(Guid) }) ?? string.Empty,
|
||||
["deleteUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Music.DELETE_TRACK, new { artistId = default(Guid), albumId = default(Guid), trackId = default(Guid) }) ?? string.Empty,
|
||||
["backUrl"] = (_urlService.GetAbsoluteUrl(WebRoutes.Music.ALBUM, new { artistId = normalizedArtistId, albumId = track.AlbumId }) ?? string.Empty) + "?libraryId=" + track.LibraryId,
|
||||
["albumCoverPath"] = album.CoverPath ?? string.Empty,
|
||||
["trackJson"] = JsonSerializer.Serialize(track, s_camelCaseJsonOptions),
|
||||
["strings"] = ThemePageDataFactory.CreateLocalizedStrings(_localizer),
|
||||
["stringsJson"] = JsonSerializer.Serialize(ThemePageDataFactory.CreateLocalizedStrings(_localizer), s_camelCaseJsonOptions)
|
||||
}
|
||||
};
|
||||
|
||||
Result<ThemePageRenderResultDto> sectionResult = await _themePageRenderer.RenderAsync(pageModel, requestedThemeId: null, cancellationToken).ConfigureAwait(false);
|
||||
if (sectionResult.IsFailure)
|
||||
{
|
||||
Dictionary<string, object?> viewData = new()
|
||||
{
|
||||
["Title"] = title,
|
||||
["AlbumCoverPath"] = album.CoverPath ?? string.Empty
|
||||
};
|
||||
return View("/Core/Views/Library/AudioLibrary/MusicLibrary/Tracks/Item.cshtml", track, viewData);
|
||||
}
|
||||
|
||||
return View(
|
||||
"/Core/Views/Shared/_ThemedView.cshtml",
|
||||
new ThemeViewDto(sectionResult.Value.Content, sectionResult.Value.Script),
|
||||
new Dictionary<string, object?> { ["Title"] = title });
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Tracks;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.EditMusicTrack;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="EditMusicTrackViewEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class EditMusicTrackViewEndpointSummary : Summary<EditMusicTrackViewEndpoint, GetMusicTrackViewRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EditMusicTrackViewEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public EditMusicTrackViewEndpointSummary()
|
||||
{
|
||||
Summary = "Renders the music track details and editing view.";
|
||||
Description = "Renders the view for displaying and editing the music track identified by the route.";
|
||||
|
||||
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album belongs to. Required.");
|
||||
RequestParam(r => r.AlbumId, "The unique identifier of the album the track belongs to. Required.");
|
||||
RequestParam(r => r.TrackId, "The unique identifier of the track to display. Required.");
|
||||
RequestParam(r => r.LibraryId, "The unique identifier of the media library the track belongs to. Required.");
|
||||
|
||||
Response(200, "The view for displaying and editing the music track is rendered.");
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetAlbumTracks;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/api-get-tracks</c> route.
|
||||
/// </summary>
|
||||
public class GetAlbumTracksEndpoint : BaseEndpoint<GetAlbumTracksLiteRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetAlbumTracksEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetAlbumTracksEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.GET_ALBUM_TRACKS);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the lightweight details of the tracks of an album.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the parameters used to retrieve the tracks.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetAlbumTracksLiteRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
PaginatedMusicTrackLiteDto response = await _apiHttpClient.GetAsync<PaginatedMusicTrackLiteDto>(BuildItemsEndpoint(request), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the lightweight details of the tracks of an album.
|
||||
/// </summary>
|
||||
/// <param name="query">The request containing the parameters used to retrieve the tracks.</param>
|
||||
/// <returns>The API endpoint to which the retrieval request is sent.</returns>
|
||||
private static string BuildItemsEndpoint(GetAlbumTracksLiteRequest query)
|
||||
{
|
||||
// The route values are normalized to Guids before they are substituted into the upstream URL, so that a crafted route value can never
|
||||
// escape its URL segment, and an unparseable id is reported by the API as a missing id.
|
||||
string artistId = Guid.TryParse(query.ArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
string albumId = Guid.TryParse(query.AlbumId, out Guid parsedAlbumId) ? parsedAlbumId.ToString() : Guid.Empty.ToString();
|
||||
StringBuilder endpoint = new(ApiRoutes.Music.GET_ALBUM_TRACKS_LITE.Replace("{libraryId}", query.LibraryId.ToString()).Replace("{artistId}", artistId).Replace("{albumId}", albumId));
|
||||
List<string> parameters = [];
|
||||
if (query.CurrentPage is not null)
|
||||
parameters.Add($"currentPage={query.CurrentPage}");
|
||||
if (query.PerPage is not null)
|
||||
parameters.Add($"perPage={query.PerPage}");
|
||||
if (parameters.Count > 0)
|
||||
endpoint.Append('?').Append(string.Join('&', parameters));
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Tracks;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetAlbumTracks;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetAlbumTracksEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, GetAlbumTracksLiteRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetAlbumTracksEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetAlbumTracksEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the lightweight details of the tracks of an album.";
|
||||
Description = "Retrieves the lightweight read models of the tracks of the album identified by the route.";
|
||||
|
||||
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album belongs to. Required.");
|
||||
RequestParam(r => r.AlbumId, "The unique identifier of the album whose tracks are retrieved. Required.");
|
||||
RequestParam(r => r.LibraryId, "The unique identifier of the media library the album belongs to. Required.");
|
||||
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
|
||||
RequestParam(r => r.PerPage, "The maximum number of tracks to retrieve per page. Optional.");
|
||||
|
||||
ExampleRequest = new GetAlbumTracksLiteRequest(
|
||||
ArtistId: Guid.NewGuid().ToString(),
|
||||
AlbumId: Guid.NewGuid().ToString(),
|
||||
LibraryId: Guid.NewGuid(),
|
||||
CurrentPage: 1,
|
||||
PerPage: 10
|
||||
);
|
||||
|
||||
Response(200, "The lightweight details of the tracks of the album are retrieved.");
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetMusicTrack;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-get-track</c> route.
|
||||
/// </summary>
|
||||
public class GetMusicTrackEndpoint : BaseEndpoint<GetMusicTrackViewRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicTrackEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetMusicTrackEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Music.GET_TRACK);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the full details of the music track identified by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Ids of the artist, album, track and media library to retrieve.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMusicTrackViewRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The route values are normalized to Guids before they are substituted into the upstream URL, so that a crafted route value can never
|
||||
// escape its URL segment, and an unparseable id is reported by the API as a missing id.
|
||||
string normalizedArtistId = Guid.TryParse(request.ArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
string normalizedAlbumId = Guid.TryParse(request.AlbumId, out Guid parsedAlbumId) ? parsedAlbumId.ToString() : Guid.Empty.ToString();
|
||||
string normalizedTrackId = Guid.TryParse(request.TrackId, out Guid parsedTrackId) ? parsedTrackId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
MusicTrackDto track = await _apiHttpClient.GetAsync<MusicTrackDto>(
|
||||
ApiRoutes.Music.GET_TRACK.Replace("{libraryId}", request.LibraryId.ToString()).Replace("{artistId}", normalizedArtistId).Replace("{albumId}", normalizedAlbumId).Replace("{trackId}", normalizedTrackId), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(track);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Tracks;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetMusicTrack;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetMusicTrackEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetMusicTrackEndpointSummary : Summary<GetMusicTrackEndpoint, GetMusicTrackViewRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicTrackEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetMusicTrackEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the full details of a music track.";
|
||||
Description = "Retrieves the full details of the music track identified by the route.";
|
||||
|
||||
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album belongs to. Required.");
|
||||
RequestParam(r => r.AlbumId, "The unique identifier of the album the track belongs to. Required.");
|
||||
RequestParam(r => r.TrackId, "The unique identifier of the track to retrieve. Required.");
|
||||
RequestParam(r => r.LibraryId, "The unique identifier of the media library the track belongs to. Required.");
|
||||
|
||||
Response(200, "The full details of the music track are retrieved.");
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.SaveMusicTrack;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-save-track</c> route.
|
||||
/// </summary>
|
||||
public class SaveMusicTrackEndpoint : BaseEndpoint<UpdateMusicTrackRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SaveMusicTrackEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public SaveMusicTrackEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.PUT);
|
||||
Routes(WebRoutes.Music.SAVE_TRACK);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Music"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the music track described by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the edited details of the track.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(UpdateMusicTrackRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The track is identified by the {artistId}, {albumId} and {trackId} route values, not by any id posted in the body, so that a mismatched
|
||||
// id can never redirect the update to another track; all ids are normalized to Guids before they are substituted into the upstream URL, so
|
||||
// that a crafted value can never escape its URL segment, and an unparseable id is reported by the API as a missing id.
|
||||
string routeArtistId = HttpContext.Request.RouteValues["artistId"]?.ToString() ?? string.Empty;
|
||||
string artistId = Guid.TryParse(routeArtistId, out Guid parsedArtistId) ? parsedArtistId.ToString() : Guid.Empty.ToString();
|
||||
string routeAlbumId = HttpContext.Request.RouteValues["albumId"]?.ToString() ?? string.Empty;
|
||||
string albumId = Guid.TryParse(routeAlbumId, out Guid parsedAlbumId) ? parsedAlbumId.ToString() : Guid.Empty.ToString();
|
||||
string routeTrackId = HttpContext.Request.RouteValues["trackId"]?.ToString() ?? string.Empty;
|
||||
string trackId = Guid.TryParse(routeTrackId, out Guid parsedTrackId) ? parsedTrackId.ToString() : Guid.Empty.ToString();
|
||||
string queryLibraryId = HttpContext.Request.Query["libraryId"].ToString();
|
||||
string libraryId = Guid.TryParse(queryLibraryId, out Guid parsedLibraryId) ? parsedLibraryId.ToString() : Guid.Empty.ToString();
|
||||
|
||||
MusicTrackDto track = await _apiHttpClient.PutAsync<MusicTrackDto, UpdateMusicTrackRequest>(
|
||||
ApiRoutes.Music.UPDATE_TRACK.Replace("{libraryId}", libraryId).Replace("{artistId}", artistId).Replace("{albumId}", albumId).Replace("{trackId}", trackId), request, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(track);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.Tracks;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.SaveMusicTrack;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="SaveMusicTrackEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SaveMusicTrackEndpointSummary : Summary<SaveMusicTrackEndpoint, UpdateMusicTrackRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SaveMusicTrackEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public SaveMusicTrackEndpointSummary()
|
||||
{
|
||||
Summary = "Updates a music track.";
|
||||
Description = "Updates the music track identified by the route, together with its metadata.";
|
||||
|
||||
Response(200, "The music track was updated.");
|
||||
}
|
||||
}
|
||||
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+1509
File diff suppressed because it is too large.
Load diff
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>بحث</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>عناصر</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>من</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>صفحة</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>السابق</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>التالي</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>الترتيب: أ-ي</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>الترتيب: ي-أ</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>لا تحتوي هذه المكتبة على أي عناصر</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>لا توجد عناصر تطابق الفلاتر الحالية</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>الكل</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>عرض التفاصيل</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>حذف</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>هل أنت متأكد من أنك تريد حذف هذا العنصر؟</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>تعذر حذف العنصر.</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Suchen</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>Einträge</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>von</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Seite</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Zurück</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Weiter</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sortieren: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sortieren: Z-A</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Diese Bibliothek hat keine Einträge</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Keine Einträge entsprechen den aktuellen Filtern</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Alle</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>Details anzeigen</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Löschen</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>Möchten Sie dieses Element wirklich löschen?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>Das Element konnte nicht gelöscht werden.</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Search</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>items</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>of</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Page</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Previous</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Next</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sort: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sort: Z-A</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>This library has no items</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>No items match the current filters</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>All</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>View details</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Delete</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>Are you sure you want to delete this item?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>The item could not be deleted.</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Buscar</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>elementos</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>de</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Página</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Anterior</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Siguiente</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Ordenar: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Ordenar: Z-A</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Esta biblioteca no tiene elementos</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Ningún elemento coincide con los filtros actuales</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Todas</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>Ver detalles</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Eliminar</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>¿Seguro que quieres eliminar este elemento?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>No se ha podido eliminar el elemento.</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Rechercher</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>éléments</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>sur</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Page</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Précédent</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Suivant</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Trier : A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Trier : Z-A</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Cette bibliothèque ne contient aucun élément</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Aucun élément ne correspond aux filtres actuels</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Toutes</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>Voir les détails</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Supprimer</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>Voulez-vous vraiment supprimer cet élément ?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>L'élément n'a pas pu être supprimé.</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Cerca</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>elementi</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>di</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Pagina</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Precedente</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Successivo</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Ordina: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Ordina: Z-A</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Questa biblioteca non contiene elementi</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Nessun elemento corrisponde ai filtri correnti</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Tutte</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>Visualizza dettagli</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Elimina</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>Sei sicuro di voler eliminare questo elemento?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>Non è stato possibile eliminare l'elemento.</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>検索</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>件</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>/</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>ページ</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>前へ</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>次へ</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>並べ替え: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>並べ替え: Z-A</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>このライブラリには項目がありません</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>現在のフィルターに一致する項目はありません</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>すべて</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>詳細を表示</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>削除</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>この項目を削除してもよろしいですか?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>項目を削除できませんでした。</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Search</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>items</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>of</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Page</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Previous</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Next</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sort: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sort: Z-A</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>This library has no items</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>No items match the current filters</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>All</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>View details</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Delete</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>Are you sure you want to delete this item?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>The item could not be deleted.</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Caută</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>elemente</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>din</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Pagina</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Înapoi</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Înainte</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sortare: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sortare: Z-A</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Această bibliotecă nu are elemente</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Niciun element nu corespunde filtrelor curente</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Toate</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>Vezi detalii</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Șterge</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>Sigur doriți să ștergeți acest element?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>Elementul nu a putut fi șters.</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Пошук</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>елементів</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>з</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Сторінка</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Назад</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Вперед</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Сортування: А-Я</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Сортування: Я-А</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>У цій бібліотеці немає елементів</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Жоден елемент не відповідає поточним фільтрам</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Усі</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>Переглянути деталі</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>Видалити</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>Ви впевнені, що хочете видалити цей елемент?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>Не вдалося видалити елемент.</value>
|
||||
</data>
|
||||
</root>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>搜索</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>项</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>/</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>页</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>上一页</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>下一页</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>排序: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>排序: Z-A</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>此库中没有项目</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>没有项目符合当前筛选条件</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>全部</value>
|
||||
</data>
|
||||
<data name="ViewDetails" xml:space="preserve">
|
||||
<value>查看详情</value>
|
||||
</data>
|
||||
<data name="Delete" xml:space="preserve">
|
||||
<value>删除</value>
|
||||
</data>
|
||||
<data name="DeleteConfirm" xml:space="preserve">
|
||||
<value>确定要删除此项目吗?</value>
|
||||
</data>
|
||||
<data name="DeleteFailed" xml:space="preserve">
|
||||
<value>无法删除该项目。</value>
|
||||
</data>
|
||||
</root>
|
||||
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1086
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1182
File diff suppressed because it is too large.
Load diff
+1120
File diff suppressed because it is too large.
Load diff
+486
@@ -0,0 +1,486 @@
|
||||
@*
|
||||
FALLBACK MUSIC ARTISTS BROWSING VIEW - READ BEFORE EDITING
|
||||
|
||||
This view is the application fallback of the music artists browsing page, rendered only when the theme template
|
||||
of the page cannot be loaded. On a healthy site the page comes from the theme's
|
||||
library/audio-library/music-library/artists/index template. It keeps the DOM contract and the client script the
|
||||
theme template mirrors, so that navigation, searching and the card actions menu keep working even without the theme.
|
||||
|
||||
To restyle the page, edit the theme files. This fallback is intentionally plain, so that a broken theme
|
||||
is obvious to the user while the page still functions.
|
||||
|
||||
/library/audio-library/music-library/artists?libraryId=...
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.DTO.Libraries
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
// Generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler.
|
||||
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||
}
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
@inject IUrlService _urlService
|
||||
|
||||
@model LibraryDto
|
||||
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="cotton-candy">
|
||||
<!-- Container with two rows, one fixed, one filling remaining space. -->
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;">
|
||||
<!-- The first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position. -->
|
||||
<div style="min-height: 1rem;"></div>
|
||||
<div class="pl-10 pr-10 pb-10">
|
||||
<!-- Library title. -->
|
||||
<div class="text-center">
|
||||
<h1 class="text-light-two engraved-title">@(Model.Title ?? string.Empty)</h1>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<!-- Search box. -->
|
||||
<input id="search-input" type="text" class="enlightenment-input w-200px" placeholder="@_localizer["Search"]" />
|
||||
<button id="search-button" type="button" class="confirm-button">@_localizer["Search"]</button>
|
||||
<!-- Sort toggle. -->
|
||||
<button id="sort-toggle" type="button" class="confirm-button">@_localizer["SortAscending"]</button>
|
||||
<!-- Item count. -->
|
||||
<span id="count-label" class="text-light-two"></span>
|
||||
</div>
|
||||
<div style="display: flex; align-items: flex-start;">
|
||||
<!-- Artists grid. -->
|
||||
<div id="artists-container" class="cards-container justify-start h-100" style="flex: 1; min-width: 0;">
|
||||
<!-- No items messages. -->
|
||||
<p id="no-items" class="hidden text-light-two">@_localizer["NoItems"]</p>
|
||||
<p id="no-items-matching" class="hidden text-light-two">@_localizer["NoItemsMatchFilters"]</p>
|
||||
</div>
|
||||
<!-- Alpha picker. -->
|
||||
<div id="alpha-picker" class="alpha-picker"></div>
|
||||
</div>
|
||||
<!-- Pagination. -->
|
||||
<div id="pagination" class="form-row mx-auto w-25 hidden" style="justify-content: center;">
|
||||
<button id="prev-page" type="button" class="abort-button">@_localizer["Previous"]</button>
|
||||
<span id="page-indicator" class="text-light-two"></span>
|
||||
<button id="next-page" type="button" class="confirm-button">@_localizer["Next"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<!-- The "text/plain" type is a design choice, not a mistake: it keeps the browser from executing this view script during HTML parsing, before site.js defines the API helpers it calls. site.js (which loads deferred) executes these scripts once it is loaded, both on the initial page load and during AJAX navigation. -->
|
||||
<script type="text/plain" data-form="@scriptId">
|
||||
const cleanupFunctions = [];
|
||||
let isInitialized = false;
|
||||
let requestSequence = 0;
|
||||
|
||||
const libraryId = '@(Model.Id ?? Guid.Empty)';
|
||||
const artistUrlTemplate = '@_urlService.GetAbsoluteUrl(WebRoutes.Music.ARTIST, new { artistId = default(Guid) })';
|
||||
const deleteUrlTemplate = '@_urlService.GetAbsoluteUrl(WebRoutes.Music.DELETE_ARTIST, new { artistId = default(Guid) })';
|
||||
const artistsContainer = document.getElementById('artists-container');
|
||||
const noItemsMessage = document.getElementById('no-items');
|
||||
const noItemsMatchingMessage = document.getElementById('no-items-matching');
|
||||
const searchInput = document.getElementById('search-input');
|
||||
const searchButton = document.getElementById('search-button');
|
||||
const sortToggle = document.getElementById('sort-toggle');
|
||||
const countLabel = document.getElementById('count-label');
|
||||
const alphaPicker = document.getElementById('alpha-picker');
|
||||
const pagination = document.getElementById('pagination');
|
||||
const prevPageButton = document.getElementById('prev-page');
|
||||
const nextPageButton = document.getElementById('next-page');
|
||||
const pageIndicator = document.getElementById('page-indicator');
|
||||
|
||||
// The special alpha keys for numbers and symbols, followed by the letters.
|
||||
const alphaKeys = ['#', '*', ...Array.from({ length: 26 }, (_, index) => String.fromCharCode(65 + index))];
|
||||
|
||||
const state = {
|
||||
currentPage: 1,
|
||||
perPage: null,
|
||||
searchTerm: '',
|
||||
alphaKey: null,
|
||||
ignoreThePrefix: false,
|
||||
sortOrder: 'Ascending'
|
||||
};
|
||||
|
||||
const jsLocalizedStrings = {
|
||||
all: '@_localizer["All"]',
|
||||
items: '@_localizer["Items"]',
|
||||
of: '@_localizer["Of"]',
|
||||
page: '@_localizer["Page"]',
|
||||
sortAscending: '@_localizer["SortAscending"]',
|
||||
sortDescending: '@_localizer["SortDescending"]',
|
||||
viewDetails: '@_localizer["ViewDetails"]',
|
||||
deleteItem: '@_localizer["Delete"]',
|
||||
deleteConfirm: '@_localizer["DeleteConfirm"]',
|
||||
deleteFailed: '@_localizer["DeleteFailed"]'
|
||||
};
|
||||
|
||||
function buildItemsUrl() {
|
||||
const url = '@_urlService.GetAbsoluteUrl(WebRoutes.Music.GET_ARTISTS)';
|
||||
const params = new URLSearchParams();
|
||||
params.set('libraryId', libraryId);
|
||||
if (state.perPage !== null) {
|
||||
params.set('currentPage', state.currentPage);
|
||||
params.set('perPage', state.perPage);
|
||||
}
|
||||
if (state.searchTerm !== '')
|
||||
params.set('searchTerm', state.searchTerm);
|
||||
if (state.alphaKey !== null)
|
||||
params.set('filterAlphaKey', state.alphaKey);
|
||||
params.set('shouldIgnoreThePrefixForAlphaPicker', state.ignoreThePrefix);
|
||||
params.set('sortOrder', state.sortOrder);
|
||||
return `${url}?${params.toString()}`;
|
||||
}
|
||||
|
||||
async function loadItemsAsync() {
|
||||
const requestId = ++requestSequence;
|
||||
const response = await callApiGetAsync(buildItemsUrl());
|
||||
if (requestId !== requestSequence)
|
||||
return;
|
||||
if (response)
|
||||
renderItems(response);
|
||||
}
|
||||
|
||||
function renderItems(response) {
|
||||
artistsContainer.querySelectorAll('.media-card').forEach(card => card.remove());
|
||||
|
||||
const hasActiveFilters = state.searchTerm !== '' || state.alphaKey !== null;
|
||||
if (response.count === 0) {
|
||||
artistsContainer.classList.add('justify-center');
|
||||
noItemsMessage.classList.toggle('hidden', hasActiveFilters);
|
||||
noItemsMatchingMessage.classList.toggle('hidden', !hasActiveFilters);
|
||||
} else {
|
||||
artistsContainer.classList.remove('justify-center');
|
||||
noItemsMessage.classList.add('hidden');
|
||||
noItemsMatchingMessage.classList.add('hidden');
|
||||
response.data.forEach(artist => artistsContainer.appendChild(createArtistCard(artist)));
|
||||
}
|
||||
|
||||
bindNavigationLinks();
|
||||
updateCountLabel(response);
|
||||
updatePagination(response);
|
||||
}
|
||||
|
||||
function createArtistCard(artist) {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'media-card';
|
||||
card.dataset.artistId = artist.id;
|
||||
|
||||
const artistUrl = artistUrlTemplate.replace('/@(default(Guid))', `/${artist.id}`) + `?libraryId=${libraryId}`;
|
||||
|
||||
const cardLink = document.createElement('a');
|
||||
cardLink.className = 'media-panel nav-link no-underline';
|
||||
cardLink.style.width = '200px';
|
||||
cardLink.style.height = 'auto';
|
||||
cardLink.href = artistUrl;
|
||||
|
||||
// The cover is shown as a square, cropped from its center (never stretched), and the name is shown underneath it.
|
||||
const image = document.createElement('img');
|
||||
image.src = artist.coverPath
|
||||
? `${globalConfiguration.serverBasePath}${artist.coverPath}`
|
||||
: `/images/ui/music-placeholder.svg`;
|
||||
image.alt = artist.name;
|
||||
image.style.width = '200px';
|
||||
image.style.height = '200px';
|
||||
image.style.flexGrow = '0';
|
||||
image.style.objectFit = 'cover';
|
||||
image.style.objectPosition = 'center';
|
||||
cardLink.appendChild(image);
|
||||
|
||||
// The name is kept on a single line, truncated with an ellipsis when it does not fit, so that all the cards share the same height.
|
||||
const titleSpan = document.createElement('span');
|
||||
titleSpan.className = 'text-light-two';
|
||||
titleSpan.style.display = 'block';
|
||||
titleSpan.style.width = '200px';
|
||||
titleSpan.style.boxSizing = 'border-box';
|
||||
titleSpan.style.height = 'auto';
|
||||
titleSpan.style.padding = '4px';
|
||||
titleSpan.style.textAlign = 'center';
|
||||
titleSpan.style.whiteSpace = 'nowrap';
|
||||
titleSpan.style.overflow = 'hidden';
|
||||
titleSpan.style.textOverflow = 'ellipsis';
|
||||
const title = document.createElement('strong');
|
||||
title.textContent = artist.name;
|
||||
titleSpan.appendChild(title);
|
||||
cardLink.appendChild(titleSpan);
|
||||
|
||||
const trigger = document.createElement('button');
|
||||
trigger.type = 'button';
|
||||
trigger.className = 'card-actions-trigger';
|
||||
trigger.setAttribute('aria-haspopup', 'menu');
|
||||
trigger.setAttribute('aria-label', jsLocalizedStrings.viewDetails);
|
||||
trigger.addEventListener('click', event => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
toggleCardMenu(card, resolveMenuAnchor(event));
|
||||
});
|
||||
|
||||
const menu = document.createElement('nav');
|
||||
menu.className = 'card-actions-menu';
|
||||
menu.setAttribute('role', 'menu');
|
||||
menu.innerHTML = `
|
||||
<a role="menuitem" href="${artistUrl}">${jsLocalizedStrings.viewDetails}</a>
|
||||
<a role="menuitem" href="#" class="card-action-delete">${jsLocalizedStrings.deleteItem}</a>`;
|
||||
|
||||
menu.addEventListener('click', async event => {
|
||||
const deleteItem = event.target.closest('.card-action-delete');
|
||||
const menuItem = event.target.closest('a[role="menuitem"]');
|
||||
if (!menuItem)
|
||||
return;
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
closeCardMenus();
|
||||
if (deleteItem) {
|
||||
await deleteArtistAsync(card.dataset.artistId);
|
||||
return;
|
||||
}
|
||||
await updateContentAsync(menuItem.href, true);
|
||||
});
|
||||
|
||||
card.appendChild(cardLink);
|
||||
card.appendChild(trigger);
|
||||
card.appendChild(menu);
|
||||
|
||||
card.addEventListener('contextmenu', event => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
toggleCardMenu(card, resolveMenuAnchor(event));
|
||||
});
|
||||
|
||||
card.addEventListener('click', event => {
|
||||
if (card.classList.contains('open') && !event.target.closest('.card-actions-menu'))
|
||||
closeCardMenus();
|
||||
});
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
function toggleCardMenu(card, anchor) {
|
||||
const wasOpen = card.classList.contains('open');
|
||||
closeCardMenus();
|
||||
if (wasOpen)
|
||||
return;
|
||||
card.classList.add('open');
|
||||
const menu = card.querySelector('.card-actions-menu');
|
||||
if (menu) {
|
||||
menu.classList.add('open');
|
||||
positionActionsMenu(menu, anchor);
|
||||
}
|
||||
}
|
||||
|
||||
function resolveMenuAnchor(event) {
|
||||
if (event.clientX !== 0 || event.clientY !== 0)
|
||||
return { x: event.clientX, y: event.clientY };
|
||||
const triggerRect = event.currentTarget.getBoundingClientRect();
|
||||
return { x: triggerRect.left, y: triggerRect.bottom };
|
||||
}
|
||||
|
||||
function positionActionsMenu(menu, anchor) {
|
||||
const margin = 4;
|
||||
const maxLeft = Math.max(margin, window.innerWidth - menu.offsetWidth - margin);
|
||||
const maxTop = Math.max(margin, window.innerHeight - menu.offsetHeight - margin);
|
||||
menu.style.position = 'fixed';
|
||||
menu.style.left = `${Math.min(Math.max(margin, anchor.x), maxLeft)}px`;
|
||||
menu.style.top = `${Math.min(Math.max(margin, anchor.y), maxTop)}px`;
|
||||
}
|
||||
|
||||
function closeCardMenus() {
|
||||
artistsContainer.querySelectorAll('.media-card.open').forEach(card => {
|
||||
card.classList.remove('open');
|
||||
const menu = card.querySelector('.card-actions-menu');
|
||||
if (menu)
|
||||
menu.classList.remove('open');
|
||||
});
|
||||
}
|
||||
|
||||
function handleCardMenuDismiss(event) {
|
||||
if (event.type === 'keydown' && event.key !== 'Escape')
|
||||
return;
|
||||
if (event.type === 'click' && event.target.closest('.card-actions-menu, .card-actions-trigger'))
|
||||
return;
|
||||
closeCardMenus();
|
||||
}
|
||||
|
||||
async function deleteArtistAsync(artistId) {
|
||||
if (await dialogService.show(jsLocalizedStrings.deleteConfirm, jsLocalizedDialogs.confirmation, DialogButtons.YES_NO, DialogIcon.QUESTION) !== DialogButton.YES)
|
||||
return;
|
||||
const url = deleteUrlTemplate.replace('/@(default(Guid))', `/${artistId}`) + `?libraryId=${libraryId}`;
|
||||
const success = await callApiDeleteAsync(url);
|
||||
if (success)
|
||||
await loadItemsAsync();
|
||||
else
|
||||
notificationService.show(jsLocalizedStrings.deleteFailed, NotificationType.ERROR);
|
||||
}
|
||||
|
||||
function updateCountLabel(response) {
|
||||
if (!countLabel)
|
||||
return;
|
||||
if (state.perPage === null)
|
||||
countLabel.textContent = `${response.count} ${jsLocalizedStrings.items}`;
|
||||
else if (response.count === 0)
|
||||
countLabel.textContent = `0 ${jsLocalizedStrings.items}`;
|
||||
else {
|
||||
const start = (response.currentPage - 1) * response.perPage + 1;
|
||||
const end = Math.min(response.currentPage * response.perPage, response.count);
|
||||
countLabel.textContent = `${start}-${end} ${jsLocalizedStrings.of} ${response.count}`;
|
||||
}
|
||||
}
|
||||
|
||||
function updatePagination(response) {
|
||||
if (!pagination)
|
||||
return;
|
||||
if (state.perPage === null) {
|
||||
pagination.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
const totalPages = Math.max(1, response.numberOfPages);
|
||||
pagination.classList.remove('hidden');
|
||||
pageIndicator.textContent = `${jsLocalizedStrings.page} ${response.currentPage} ${jsLocalizedStrings.of} ${totalPages}`;
|
||||
prevPageButton.disabled = response.currentPage <= 1;
|
||||
nextPageButton.disabled = response.currentPage >= totalPages;
|
||||
}
|
||||
|
||||
// Builds the alpha picker column, with the "All" key followed by the numbers, symbols and letters keys.
|
||||
function buildAlphaPicker() {
|
||||
if (!alphaPicker)
|
||||
return;
|
||||
const allKey = document.createElement('span');
|
||||
allKey.className = 'alpha-key';
|
||||
allKey.dataset.alphaKey = '';
|
||||
allKey.textContent = jsLocalizedStrings.all;
|
||||
allKey.addEventListener('click', () => handleAlphaKeyClick(null));
|
||||
alphaPicker.appendChild(allKey);
|
||||
|
||||
alphaKeys.forEach(key => {
|
||||
const alphaKey = document.createElement('span');
|
||||
alphaKey.className = 'alpha-key';
|
||||
alphaKey.dataset.alphaKey = key;
|
||||
alphaKey.textContent = key;
|
||||
alphaKey.addEventListener('click', () => handleAlphaKeyClick(key));
|
||||
alphaPicker.appendChild(alphaKey);
|
||||
});
|
||||
|
||||
updateAlphaPickerActiveState();
|
||||
}
|
||||
|
||||
// Highlights the currently active key of the alpha picker.
|
||||
function updateAlphaPickerActiveState() {
|
||||
if (!alphaPicker)
|
||||
return;
|
||||
alphaPicker.querySelectorAll('.alpha-key').forEach(key => {
|
||||
const keyValue = key.dataset.alphaKey === '' ? null : key.dataset.alphaKey;
|
||||
key.classList.toggle('alpha-key-active', keyValue === state.alphaKey);
|
||||
});
|
||||
}
|
||||
|
||||
// Applies the given alpha key (null clears the alpha filter) and reloads the artists.
|
||||
function handleAlphaKeyClick(key) {
|
||||
state.alphaKey = key;
|
||||
state.currentPage = 1;
|
||||
updateAlphaPickerActiveState();
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// Toggles the sort direction and reloads the artists.
|
||||
function handleSortToggle() {
|
||||
state.sortOrder = state.sortOrder === 'Ascending' ? 'Descending' : 'Ascending';
|
||||
sortToggle.textContent = state.sortOrder === 'Ascending' ? jsLocalizedStrings.sortAscending : jsLocalizedStrings.sortDescending;
|
||||
state.currentPage = 1;
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// Applies an alpha filter when a letter is pressed while the search input does not have focus; Escape clears the alpha filter.
|
||||
function handleAlphaKeydown(event) {
|
||||
if (document.activeElement === searchInput)
|
||||
return;
|
||||
if (event.key.length === 1 && /[a-zA-Z]/.test(event.key))
|
||||
handleAlphaKeyClick(event.key.toUpperCase());
|
||||
else if (event.key === 'Escape')
|
||||
handleAlphaKeyClick(null);
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
state.searchTerm = searchInput.value.trim();
|
||||
state.currentPage = 1;
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
function handleSearchKeydown(event) {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
handleSearch();
|
||||
}
|
||||
}
|
||||
|
||||
function handlePrevPageClick() {
|
||||
state.currentPage = Math.max(1, state.currentPage - 1);
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
function handleNextPageClick() {
|
||||
state.currentPage = state.currentPage + 1;
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
async function loadSettingsAsync() {
|
||||
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl(WebRoutes.Settings.GET_USER_SETTINGS)');
|
||||
if (data) {
|
||||
state.ignoreThePrefix = data.shouldIgnoreThePrefixForAlphaPicker === true;
|
||||
state.perPage = data.isPaginationEnabled === true ? data.itemsPerPage : null;
|
||||
}
|
||||
}
|
||||
|
||||
function bindEventHandler(element, type, handler) {
|
||||
if (element)
|
||||
element.addEventListener(type, handler);
|
||||
}
|
||||
|
||||
function unbindEventHandler(element, type, handler) {
|
||||
if (element)
|
||||
element.removeEventListener(type, handler);
|
||||
}
|
||||
|
||||
bindEventHandler(searchButton, 'click', handleSearch);
|
||||
bindEventHandler(searchInput, 'keydown', handleSearchKeydown);
|
||||
bindEventHandler(sortToggle, 'click', handleSortToggle);
|
||||
bindEventHandler(prevPageButton, 'click', handlePrevPageClick);
|
||||
bindEventHandler(nextPageButton, 'click', handleNextPageClick);
|
||||
document.addEventListener('keydown', handleAlphaKeydown);
|
||||
document.addEventListener('click', handleCardMenuDismiss);
|
||||
document.addEventListener('keydown', handleCardMenuDismiss);
|
||||
document.addEventListener('DOMContentLoaded', InitializeAsync);
|
||||
|
||||
cleanupFunctions.push(() => {
|
||||
unbindEventHandler(searchButton, 'click', handleSearch);
|
||||
unbindEventHandler(searchInput, 'keydown', handleSearchKeydown);
|
||||
unbindEventHandler(sortToggle, 'click', handleSortToggle);
|
||||
unbindEventHandler(prevPageButton, 'click', handlePrevPageClick);
|
||||
unbindEventHandler(nextPageButton, 'click', handleNextPageClick);
|
||||
document.removeEventListener('keydown', handleAlphaKeydown);
|
||||
document.removeEventListener('click', handleCardMenuDismiss);
|
||||
document.removeEventListener('keydown', handleCardMenuDismiss);
|
||||
document.removeEventListener('DOMContentLoaded', InitializeAsync);
|
||||
});
|
||||
|
||||
async function InitializeAsync() {
|
||||
if (isInitialized)
|
||||
return;
|
||||
if (!artistsContainer || !sortToggle || !countLabel) {
|
||||
isInitialized = true;
|
||||
return;
|
||||
}
|
||||
isInitialized = true;
|
||||
sortToggle.textContent = jsLocalizedStrings.sortAscending;
|
||||
buildAlphaPicker();
|
||||
await loadSettingsAsync();
|
||||
await loadItemsAsync();
|
||||
}
|
||||
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
+1325
File diff suppressed because it is too large.
Load diff
+1059
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user