Adds the server-side theme repository and reworks the web theme engine onto it

This commit is contained in:
BinaryAlley committed 2026-08-19 22:50:07 -07:00
1 parent 85928f7c3c
commit bf8faba24d
136 files changed
+6942 -1197

No files matched your search

@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.Themes;
using Lumina.Application.Core.Themes.Management.Commands.DeleteTheme;
using Lumina.Contracts.Requests.Themes;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Themes;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.DeleteTheme;
/// <summary>
/// API endpoint for the <c>/themes/{themeId}</c> route.
/// </summary>
public class DeleteThemeEndpoint : BaseEndpoint<DeleteThemeRequest, IResult>
{
private readonly ICommandHandler<DeleteThemeCommand, Result<Success>> _deleteThemeCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="DeleteThemeEndpoint"/> class.
/// </summary>
/// <param name="deleteThemeCommandHandler">Injected service for handling delete theme commands.</param>
public DeleteThemeEndpoint(ICommandHandler<DeleteThemeCommand, Result<Success>> deleteThemeCommandHandler)
{
_deleteThemeCommandHandler = deleteThemeCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.DELETE);
Routes(ApiRoutes.Themes.DELETE_THEME);
Version(1);
DontCatchExceptions();
}
/// <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)
{
Result<Success> result = await _deleteThemeCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.NoContent(), Problem);
}
}
@@ -0,0 +1,129 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.DeleteTheme;
/// <summary>
/// Class used for providing a textual description for the <see cref="DeleteThemeEndpoint"/> API 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.";
ExampleRequest = new DeleteThemeRequest(
ThemeId: "neon-grid"
);
RequestParam(r => r.ThemeId, "The manifest id of the theme to delete. Required.");
Response(204, "The theme was successfully deleted.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/themes/{themeId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/themes/{themeId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/themes/{themeId}"
}
}
);
Response(403, "The request failed because the user is not an Admin, the theme is the last bundled theme, or the active theme cannot be replaced.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/themes/{themeId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "LastBundledThemeCannotBeDeleted",
instance = "/api/v1/themes/{themeId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "ThemeCannotBeDeleted",
instance = "/api/v1/themes/{themeId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
}
);
Response(404, "The request failed because the provided theme does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ThemeNotFound",
instance = "/api/v1/themes/{themeId}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/themes/{themeId}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"ThemeIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.Themes;
using Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
using Lumina.Contracts.Requests.Themes;
using Lumina.Contracts.Responses.Themes;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Themes;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.InstallTheme;
/// <summary>
/// API endpoint for the <c>/themes</c> route.
/// </summary>
public class InstallThemeEndpoint : BaseEndpoint<InstallThemeRequest, IResult>
{
private readonly ICommandHandler<InstallThemeCommand, Result<ThemeResponse>> _installThemeCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="InstallThemeEndpoint"/> class.
/// </summary>
/// <param name="installThemeCommandHandler">Injected service for handling install theme commands.</param>
public InstallThemeEndpoint(ICommandHandler<InstallThemeCommand, Result<ThemeResponse>> installThemeCommandHandler)
{
_installThemeCommandHandler = installThemeCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.POST);
Routes(ApiRoutes.Themes.INSTALL_THEME);
Version(1);
DontCatchExceptions();
}
/// <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(InstallThemeRequest request, CancellationToken cancellationToken)
{
IFormFile? archive = HttpContext.Request.Form.Files.FirstOrDefault();
Result<ThemeResponse> result = await _installThemeCommandHandler.HandleAsync(request.ToCommand(archive?.OpenReadStream(), archive?.FileName), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,125 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Themes;
using Lumina.Contracts.Responses.Themes;
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.InstallTheme;
/// <summary>
/// Class used for providing a textual description for the <see cref="InstallThemeEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class InstallThemeEndpointSummary : Summary<InstallThemeEndpoint, InstallThemeRequest>
{
/// <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 ThemeResponse(
Id: Guid.NewGuid(),
ThemeId: "lumina-default",
Name: "Lumina Default",
Description: "A clean, readable theme.",
Author: "Lumina Team",
Version: "1.2.0",
PreviewPath: "preview.png",
InstallSource: ThemeInstallSource.Uploaded,
IsCurrent: null,
InstalledAtUtc: DateTime.UtcNow
));
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/themes"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/themes"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/themes"
}
}
);
Response(403, "The request failed because the user is not an Admin, or the uploaded theme pack is not readable.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/themes",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "ThemeArchiveNotReadable",
instance = "/api/v1/themes",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "ThemeFilesUnreadable",
instance = "/api/v1/themes",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/themes",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"ThemeArchiveCannotBeNull"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.Themes;
using Lumina.Application.Core.Themes.Management.Commands.SetCurrentTheme;
using Lumina.Contracts.Requests.Themes;
using Lumina.Contracts.Responses.Themes;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Themes;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.SetCurrentTheme;
/// <summary>
/// API endpoint for the <c>/themes/current</c> route.
/// </summary>
public class SetCurrentThemeEndpoint : BaseEndpoint<SetCurrentThemeRequest, IResult>
{
private readonly ICommandHandler<SetCurrentThemeCommand, Result<ThemeResponse>> _setCurrentThemeCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpoint"/> class.
/// </summary>
/// <param name="setCurrentThemeCommandHandler">Injected service for handling set current theme commands.</param>
public SetCurrentThemeEndpoint(ICommandHandler<SetCurrentThemeCommand, Result<ThemeResponse>> setCurrentThemeCommandHandler)
{
_setCurrentThemeCommandHandler = setCurrentThemeCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.PUT);
Routes(ApiRoutes.Themes.SET_CURRENT_THEME);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Sets the theme stored in <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)
{
Result<ThemeResponse> result = await _setCurrentThemeCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,122 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Themes;
using Lumina.Contracts.Responses.Themes;
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Themes.Management.SetCurrentTheme;
/// <summary>
/// Class used for providing a textual description for the <see cref="SetCurrentThemeEndpoint"/> API 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.";
ExampleRequest = new SetCurrentThemeRequest(
ThemeId: "lumina-default"
);
RequestParam(r => r.ThemeId, "The manifest id of the theme to activate. Required.");
Response(200, "The theme was successfully activated.",
example: new ThemeResponse(
Id: Guid.NewGuid(),
ThemeId: "lumina-default",
Name: "Lumina Default",
Description: "A clean, readable theme.",
Author: "Lumina Team",
Version: "1.2.0",
PreviewPath: "preview.png",
InstallSource: ThemeInstallSource.Bundled,
IsCurrent: true,
InstalledAtUtc: DateTime.UtcNow
));
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/themes/current"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/themes/current"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/themes/current"
}
}
);
Response(403, "The request failed because the user is not an Admin.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/themes/current",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the provided theme does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ThemeNotFound",
instance = "/api/v1/themes/current",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/themes/current",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"ThemeIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}