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

@@ -7,6 +7,7 @@ using Lumina.Application.Common.Infrastructure.Authorization.Policies.Over18;
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
using Lumina.Application.Common.Infrastructure.Plugins;
using Lumina.Application.Common.Infrastructure.Security;
using Lumina.Application.Common.Infrastructure.Themes;
using Lumina.Application.Common.Infrastructure.Time;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.MediaLibrary.Management.Progress;
@@ -29,6 +30,7 @@ using Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Progress;
using Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Queue;
using Lumina.Infrastructure.Core.Plugins;
using Lumina.Infrastructure.Core.Security;
using Lumina.Infrastructure.Core.Themes;
using Lumina.Infrastructure.Core.Time;
using Lumina.Plugins.Contracts.Core.Plugins;
using Microsoft.Extensions.Configuration;
@@ -113,6 +115,10 @@ public static class InfrastructureLayerServices
serviceProvider.GetRequiredService<ILogger<PluginDetectionSyncJob>>()));
services.AddHostedService(serviceProvider => serviceProvider.GetRequiredService<PluginDetectionSyncJob>());
// themes: the theme service stores and serves theme packs, and the detection job seeds the bundled themes at startup
services.AddSingleton<IThemeService, ThemeService>();
services.AddHostedService<ThemeDetectionSyncJob>();
return services;
}
}
@@ -35,11 +35,6 @@ public static class SharedConfiguration
configuration.AddEnvironmentVariables(); // environment variables should override the configuration files
// bind the appsettings sections
services.AddOptions<CommonSettingsDto>()
.Bind(configuration.GetRequiredSection(CommonSettingsDto.SECTION_NAME))
.ValidateFluently()
.ValidateOnStart();
services.AddOptions<DatabaseSettingsDto>()
.Bind(configuration.GetRequiredSection(DatabaseSettingsDto.SECTION_NAME))
.ValidateFluently()
@@ -70,6 +65,11 @@ public static class SharedConfiguration
.ValidateFluently()
.ValidateOnStart();
services.AddOptions<ThemeEngineOptionsDto>()
.Bind(configuration.GetRequiredSection(ThemeEngineOptionsDto.SECTION_NAME))
.ValidateFluently()
.ValidateOnStart();
return services;
}
}
@@ -11,7 +11,6 @@ public static partial class Errors
{
public static class Configuration
{
public static Error ApplicationThemeCannotBeEmpty => Error.Validation(description: nameof(ApplicationThemeCannotBeEmpty));
public static Error DatabaseConnectionStringCannotBeEmpty => Error.Validation(description: nameof(DatabaseConnectionStringCannotBeEmpty));
public static Error MediaRootDirectoryCannotBeEmpty => Error.Validation(description: nameof(MediaRootDirectoryCannotBeEmpty));
public static Error MediaLibrariesDirectoryCannotBeEmpty => Error.Validation(description: nameof(MediaLibrariesDirectoryCannotBeEmpty));
@@ -25,5 +24,12 @@ public static partial class Errors
public static Error CorsOriginsCannotBeEmpty => Error.Validation(description: nameof(CorsOriginsCannotBeEmpty));
public static Error CorsOriginIsInvalid => Error.Validation(description: nameof(CorsOriginIsInvalid));
public static Error PluginsDirectoryCannotBeEmpty => Error.Validation(description: nameof(PluginsDirectoryCannotBeEmpty));
public static Error ThemeStoragePathCannotBeEmpty => Error.Validation(description: nameof(ThemeStoragePathCannotBeEmpty));
public static Error ThemeBundledThemesPathCannotBeEmpty => Error.Validation(description: nameof(ThemeBundledThemesPathCannotBeEmpty));
public static Error ThemeDefaultThemeIdCannotBeEmpty => Error.Validation(description: nameof(ThemeDefaultThemeIdCannotBeEmpty));
public static Error ThemeMaxArchiveBytesMustBePositive => Error.Validation(description: nameof(ThemeMaxArchiveBytesMustBePositive));
public static Error ThemeMaxExpandedBytesMustBePositive => Error.Validation(description: nameof(ThemeMaxExpandedBytesMustBePositive));
public static Error ThemeMaxSingleFileBytesMustBePositive => Error.Validation(description: nameof(ThemeMaxSingleFileBytesMustBePositive));
public static Error ThemeMaxEntriesMustBePositive => Error.Validation(description: nameof(ThemeMaxEntriesMustBePositive));
}
}
@@ -1,19 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Infrastructure.Common.Models.DTO.Configuration;
/// <summary>
/// Data transfer object for deserializing shared application configuration settings.
/// </summary>
[DebuggerDisplay("{SECTION_NAME}")]
public class CommonSettingsDto
{
public const string SECTION_NAME = "CommonSettings";
/// <summary>
/// Gets or sets the theme of the application.
/// </summary>
public required string Theme { get; init; }
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Infrastructure.Common.Models.DTO.Configuration;
/// <summary>
/// Data transfer object for deserializing theme engine settings.
/// </summary>
[DebuggerDisplay("Section name: {SECTION_NAME}")]
public sealed class ThemeEngineOptionsDto
{
public const string SECTION_NAME = "ThemeEngine";
/// <summary>
/// Gets or sets the directory where installed theme packs are stored, relative to the API base directory when not rooted.
/// </summary>
public string StoragePath { get; set; } = "themes";
/// <summary>
/// Gets or sets the directory where the theme pack archives shipped with the application are located, relative to the API base directory when not rooted.
/// </summary>
public string BundledThemesPath { get; set; } = "themes/bundled";
/// <summary>
/// Gets or sets the identifier of the theme selected when no valid current theme is persisted.
/// </summary>
public string DefaultThemeId { get; set; } = "lumina-default";
/// <summary>
/// Gets or sets the maximum allowed size of an uploaded theme archive, in bytes.
/// </summary>
public long MaxArchiveBytes { get; set; } = 8 * 1024 * 1024;
/// <summary>
/// Gets or sets the maximum allowed total size of an extracted theme pack, in bytes.
/// </summary>
public long MaxExpandedBytes { get; set; } = 24 * 1024 * 1024;
/// <summary>
/// Gets or sets the maximum allowed size of a single file within a theme pack, in bytes.
/// </summary>
public long MaxSingleFileBytes { get; set; } = 6 * 1024 * 1024;
/// <summary>
/// Gets or sets the maximum allowed number of entries in a theme pack archive.
/// </summary>
public int MaxEntries { get; set; } = 250;
/// <summary>
/// Gets or sets a value indicating whether script elements in theme templates and script files in theme assets are allowed to be served.
/// </summary>
public bool AllowThemeScripts { get; set; }
}
@@ -1,23 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
#endregion
namespace Lumina.Infrastructure.Common.Validators;
/// <summary>
/// Validates the needed validation rules for the CommonSettings application configuration settings section.
/// </summary>
public class CommonSettingsDtoValidator : AbstractValidator<CommonSettingsDto>
{
/// <summary>
/// Initializes a new instance of the <see cref="CommonSettingsDtoValidator"/> class.
/// </summary>
public CommonSettingsDtoValidator()
{
RuleFor(settings => settings.Theme)
.NotEmpty()
.WithError(Errors.Errors.Configuration.ApplicationThemeCannotBeEmpty);
}
}
@@ -0,0 +1,47 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
#endregion
namespace Lumina.Infrastructure.Common.Validators;
/// <summary>
/// Validates the needed validation rules for the ThemeEngine application configuration settings section.
/// </summary>
public class ThemeEngineOptionsDtoValidator : AbstractValidator<ThemeEngineOptionsDto>
{
/// <summary>
/// Initializes a new instance of the <see cref="ThemeEngineOptionsDtoValidator"/> class.
/// </summary>
public ThemeEngineOptionsDtoValidator()
{
RuleFor(themeEngineOptions => themeEngineOptions.StoragePath)
.NotEmpty()
.WithError(Errors.Errors.Configuration.ThemeStoragePathCannotBeEmpty);
RuleFor(themeEngineOptions => themeEngineOptions.BundledThemesPath)
.NotEmpty()
.WithError(Errors.Errors.Configuration.ThemeBundledThemesPathCannotBeEmpty);
RuleFor(themeEngineOptions => themeEngineOptions.DefaultThemeId)
.NotEmpty()
.WithError(Errors.Errors.Configuration.ThemeDefaultThemeIdCannotBeEmpty);
RuleFor(themeEngineOptions => themeEngineOptions.MaxArchiveBytes)
.GreaterThan(0)
.WithError(Errors.Errors.Configuration.ThemeMaxArchiveBytesMustBePositive);
RuleFor(themeEngineOptions => themeEngineOptions.MaxExpandedBytes)
.GreaterThan(0)
.WithError(Errors.Errors.Configuration.ThemeMaxExpandedBytesMustBePositive);
RuleFor(themeEngineOptions => themeEngineOptions.MaxSingleFileBytes)
.GreaterThan(0)
.WithError(Errors.Errors.Configuration.ThemeMaxSingleFileBytesMustBePositive);
RuleFor(themeEngineOptions => themeEngineOptions.MaxEntries)
.GreaterThan(0)
.WithError(Errors.Errors.Configuration.ThemeMaxEntriesMustBePositive);
}
}