mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 11:11:10 +00:00
Adds the server-side theme repository and reworks the web theme engine onto it
This commit is contained in:
1 parent
85928f7c3c
commit
bf8faba24d
136 files changed
+6942
-1197
No files matched your search
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.DeleteTheme;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/admin/themes/api-delete-theme/{themeId}</c> route.
|
||||
/// </summary>
|
||||
public class DeleteThemeEndpoint : BaseEndpoint<DeleteThemeRequest, IResult>
|
||||
{
|
||||
private readonly ThemeService _themeService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteThemeEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="themeService">Injected service for interactions with the remote theme endpoints.</param>
|
||||
public DeleteThemeEndpoint(ThemeService themeService)
|
||||
{
|
||||
_themeService = themeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.DELETE);
|
||||
Routes(WebRoutes.Themes.DELETE_THEME);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Themes"));
|
||||
Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE);
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the theme identified by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the theme to delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(DeleteThemeRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.ThemeId))
|
||||
return Results.Problem(statusCode: StatusCodes.Status400BadRequest, detail: "The theme id cannot be empty.");
|
||||
|
||||
await _themeService.DeleteThemeAsync(request.ThemeId, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess();
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.DeleteTheme;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="DeleteThemeEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteThemeEndpointSummary : Summary<DeleteThemeEndpoint, DeleteThemeRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteThemeEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public DeleteThemeEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes a theme.";
|
||||
Description = "Deletes the theme identified by the request, switching to another available theme when the deleted theme was the active one.";
|
||||
|
||||
RequestParam(r => r.ThemeId, "The manifest id of the theme to delete.");
|
||||
|
||||
Response(200, "The theme was successfully deleted.", example: new SuccessResponse(true));
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.DownloadTheme;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/admin/themes/api-download-theme/{themeId}</c> route.
|
||||
/// </summary>
|
||||
public class DownloadThemeEndpoint : BaseEndpoint<GetThemeArchiveRequest, IResult>
|
||||
{
|
||||
private readonly ThemeService _themeService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DownloadThemeEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="themeService">Injected service for interactions with the remote theme endpoints.</param>
|
||||
public DownloadThemeEndpoint(ThemeService themeService)
|
||||
{
|
||||
_themeService = themeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Themes.DOWNLOAD_THEME);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Themes"));
|
||||
Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads the archive of the theme identified by <paramref name="request"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the theme to download.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetThemeArchiveRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.ThemeId))
|
||||
return Results.Problem(statusCode: StatusCodes.Status400BadRequest, detail: "The theme id cannot be empty.");
|
||||
|
||||
ThemeArchiveDto archive = await _themeService.BuildArchiveAsync(request.ThemeId, cancellationToken).ConfigureAwait(false);
|
||||
return Results.File(archive.Content, "application/zip", archive.FileName);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.DownloadTheme;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="DownloadThemeEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DownloadThemeEndpointSummary : Summary<DownloadThemeEndpoint, GetThemeArchiveRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DownloadThemeEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public DownloadThemeEndpointSummary()
|
||||
{
|
||||
Summary = "Downloads the archive of a theme.";
|
||||
Description = "Downloads the ZIP archive of the installed theme identified by the request.";
|
||||
|
||||
RequestParam(r => r.ThemeId, "The manifest id of the theme to download.");
|
||||
|
||||
Response(200, "The ZIP archive of the theme is returned.", "application/zip");
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.GetThemes;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/admin/themes/api-get-themes</c> route.
|
||||
/// </summary>
|
||||
public class GetThemesEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ThemeService _themeService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="themeService">Injected service for interactions with the remote theme endpoints.</param>
|
||||
public GetThemesEndpoint(ThemeService themeService)
|
||||
{
|
||||
_themeService = themeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Themes.GET_THEMES);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Themes"));
|
||||
Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the installed themes together with the current theme and the theme engine settings.
|
||||
/// </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)
|
||||
{
|
||||
IReadOnlyList<ThemeInfoDto> themes = await _themeService.GetThemesAsync(cancellationToken).ConfigureAwait(false);
|
||||
ThemeInfoDto currentTheme = await _themeService.GetCurrentThemeAsync(cancellationToken).ConfigureAwait(false);
|
||||
ThemeSettingsResponseDto settings = await _themeService.GetThemeSettingsAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
ThemeAdminDto themeAdmin = new()
|
||||
{
|
||||
Themes = themes,
|
||||
CurrentThemeId = currentTheme.Id,
|
||||
AllowThemeScripts = settings.AllowThemeScripts,
|
||||
MaxArchiveBytes = settings.MaxArchiveBytes
|
||||
};
|
||||
return JsonSuccess(themeAdmin);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.GetThemes;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetThemesEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemesEndpointSummary : Summary<GetThemesEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetThemesEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the theme administration data.";
|
||||
Description = "Retrieves the installed themes, together with the current theme and the theme engine settings.";
|
||||
|
||||
Response(200, "The theme administration data is returned.", example: new SuccessResponse<ThemeAdminDto>(true, default));
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.InstallTheme;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/admin/themes/api-install-theme</c> route.
|
||||
/// </summary>
|
||||
public class InstallThemeEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ThemeService _themeService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallThemeEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="themeService">Injected service for interactions with the remote theme endpoints.</param>
|
||||
public InstallThemeEndpoint(ThemeService themeService)
|
||||
{
|
||||
_themeService = themeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.POST);
|
||||
Routes(WebRoutes.Themes.INSTALL_THEME);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Themes"));
|
||||
Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE);
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs the theme pack 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)
|
||||
{
|
||||
IFormFile? archive = HttpContext.Request.Form.Files.FirstOrDefault();
|
||||
if (archive is null)
|
||||
return Results.Problem(statusCode: StatusCodes.Status400BadRequest, detail: "The uploaded theme archive is missing.");
|
||||
|
||||
await using Stream archiveStream = archive.OpenReadStream();
|
||||
ThemeInfoDto theme = await _themeService.InstallAsync(archiveStream, archive.FileName, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(theme);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.InstallTheme;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="InstallThemeEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InstallThemeEndpointSummary : Summary<InstallThemeEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallThemeEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public InstallThemeEndpointSummary()
|
||||
{
|
||||
Summary = "Installs a theme pack.";
|
||||
Description = "Installs the theme pack uploaded in the multipart form of the request, replacing the files of an existing theme with the same manifest id.";
|
||||
|
||||
Response(200, "The theme was successfully installed.", example: new SuccessResponse<ThemeInfoDto>(true, default));
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/admin/themes/api-set-current-theme</c> route.
|
||||
/// </summary>
|
||||
public class SetCurrentThemeEndpoint : BaseEndpoint<SetCurrentThemeRequest, IResult>
|
||||
{
|
||||
private readonly ThemeService _themeService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="themeService">Injected service for interactions with the remote theme endpoints.</param>
|
||||
public SetCurrentThemeEndpoint(ThemeService themeService)
|
||||
{
|
||||
_themeService = themeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.PUT);
|
||||
Routes(WebRoutes.Themes.SET_CURRENT_THEME);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Themes"));
|
||||
Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE);
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the theme identified by <paramref name="request"/> as the currently active theme.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the theme to activate.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(SetCurrentThemeRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.ThemeId))
|
||||
return Results.Problem(statusCode: StatusCodes.Status400BadRequest, detail: "The theme id cannot be empty.");
|
||||
|
||||
await _themeService.SetCurrentThemeAsync(request.ThemeId, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess();
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="SetCurrentThemeEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetCurrentThemeEndpointSummary : Summary<SetCurrentThemeEndpoint, SetCurrentThemeRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public SetCurrentThemeEndpointSummary()
|
||||
{
|
||||
Summary = "Sets the currently active theme.";
|
||||
Description = "Sets the theme identified by the request as the currently active theme.";
|
||||
|
||||
RequestParam(r => r.ThemeId, "The manifest id of the theme to activate.");
|
||||
|
||||
Response(200, "The theme was successfully activated.", example: new SuccessResponse(true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Themes.ThemeAssets;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/theme-assets/{themeId}/{path}</c> route.
|
||||
/// </summary>
|
||||
public class ThemeAssetsEndpoint : BaseEndpoint<GetThemeAssetRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThemeAssetsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public ThemeAssetsEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.Themes.THEME_ASSETS);
|
||||
AllowAnonymous();
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Themes"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serves the asset of the theme stored in <paramref name="request"/>, fetched from the remote API.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the theme and the path of the asset.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetThemeAssetRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.ThemeId) || string.IsNullOrWhiteSpace(request.Path))
|
||||
return Results.Problem(statusCode: StatusCodes.Status400BadRequest, detail: "The theme id and the asset path are required.");
|
||||
|
||||
BlobDataDto blob = await _apiHttpClient.GetBlobAsync(
|
||||
ApiRoutes.Themes.GET_THEME_ASSET.Replace("{themeId}", request.ThemeId).Replace("{assetPath}", request.Path), cancellationToken).ConfigureAwait(false);
|
||||
return Results.File(blob.Data, blob.ContentType);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Themes.ThemeAssets;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="ThemeAssetsEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeAssetsEndpointSummary : Summary<ThemeAssetsEndpoint, GetThemeAssetRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThemeAssetsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public ThemeAssetsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves an asset file of a theme.";
|
||||
Description = "Serves the binary content of an asset file of a theme, fetched from the remote API.";
|
||||
|
||||
RequestParam(r => r.ThemeId, "The manifest id of the theme.");
|
||||
RequestParam(r => r.Path, "The asset path relative to the theme pack root.");
|
||||
|
||||
Response(200, "The asset file of the theme is returned.", "application/octet-stream");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user