From fd64cbd6baff448abf4d7022578e1f9f3b715ff7 Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Thu, 20 Aug 2026 23:38:50 -0700 Subject: [PATCH] Adds comments. --- .../Management/Queries/GetThemes/GetThemesQueryHandler.cs | 1 + src/Lumina.Infrastructure/Core/Themes/ThemeService.cs | 3 +++ .../Themes/Queries/GetCurrentTheme/GetCurrentThemeEndpoint.cs | 1 + .../Themes/Queries/GetThemeAsset/GetThemeAssetEndpoint.cs | 1 + .../Queries/GetThemeSettings/GetThemeSettingsEndpoint.cs | 1 + .../Queries/GetThemeTemplate/GetThemeTemplateEndpoint.cs | 1 + .../Core/Endpoints/Themes/ThemeAssets/ThemeAssetsEndpoint.cs | 1 + .../Core/Themes/RazorViewToStringRenderer.cs | 1 + src/Lumina.Presentation.Web/Core/Themes/ThemeNavBuilder.cs | 2 ++ .../Core/Themes/ThemePageDataFactory.cs | 1 + src/Lumina.Presentation.Web/Core/Themes/ThemePageRenderer.cs | 1 + src/Lumina.Presentation.Web/Core/Themes/ThemeTemplateEngine.cs | 1 + src/Lumina.Presentation.Web/Core/Views/Shared/_Layout.cshtml | 2 ++ 13 files changed, 17 insertions(+) diff --git a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQueryHandler.cs b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQueryHandler.cs index d3ceca64..90202b57 100644 --- a/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQueryHandler.cs +++ b/src/Lumina.Application/Core/Themes/Management/Queries/GetThemes/GetThemesQueryHandler.cs @@ -47,6 +47,7 @@ public class GetThemesQueryHandler : IQueryHandler>([.. getThemesResult.Value .Where(theme => !theme.IsDeleted) + // the shipped bundled themes are listed before the user themes, so the defaults stay the most visible .OrderByDescending(theme => theme.InstallSource == ThemeInstallSource.Bundled) .ThenBy(theme => theme.Name, StringComparer.OrdinalIgnoreCase) .Select(theme => theme.ToResponse())]); diff --git a/src/Lumina.Infrastructure/Core/Themes/ThemeService.cs b/src/Lumina.Infrastructure/Core/Themes/ThemeService.cs index b8948db1..7af797f9 100644 --- a/src/Lumina.Infrastructure/Core/Themes/ThemeService.cs +++ b/src/Lumina.Infrastructure/Core/Themes/ThemeService.cs @@ -61,6 +61,7 @@ public sealed class ThemeService : IThemeService private readonly string _storageRoot; private readonly string _stagingRoot; private readonly string _bundledRoot; + // serializes theme pack mutations, so concurrent installs and deletes cannot race on the same files private readonly SemaphoreSlim _mutationGate = new(1, 1); /// @@ -484,6 +485,7 @@ public sealed class ThemeService : IThemeService if (entry.Length > _options.MaxSingleFileBytes) return Error.Validation(code: "Theme.File.TooLarge", description: $"Theme file '{normalizedPath}' is too large."); + // guard the total decompressed size, so a tiny archive cannot expand into a decompression bomb expandedBytes += entry.Length; if (expandedBytes > _options.MaxExpandedBytes) return Error.Validation(code: "Theme.Archive.ExpandedTooLarge", description: "The expanded theme archive is too large."); @@ -506,6 +508,7 @@ public sealed class ThemeService : IThemeService if (read == 0) break; + // enforce the per-file limit while streaming, because the declared entry size is not trustworthy entryBytes += read; if (entryBytes > _options.MaxSingleFileBytes) return Error.Validation(code: "Theme.File.TooLarge", description: $"Theme file '{normalizedPath}' is too large."); diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetCurrentTheme/GetCurrentThemeEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetCurrentTheme/GetCurrentThemeEndpoint.cs index 7191b7b0..0c981623 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetCurrentTheme/GetCurrentThemeEndpoint.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetCurrentTheme/GetCurrentThemeEndpoint.cs @@ -37,6 +37,7 @@ public class GetCurrentThemeEndpoint : BaseEndpoint Verbs(Http.GET); Routes(ApiRoutes.Themes.GET_CURRENT_THEME); Version(1); + // theme content is public, since the web renders themed pages for anonymous visitors too (i.e.: login page); only install and manage operations are admin-gated AllowAnonymous(); DontCatchExceptions(); } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeAsset/GetThemeAssetEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeAsset/GetThemeAssetEndpoint.cs index 1fefad91..81bf2e62 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeAsset/GetThemeAssetEndpoint.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeAsset/GetThemeAssetEndpoint.cs @@ -39,6 +39,7 @@ public class GetThemeAssetEndpoint : BaseEndpoint Verbs(Http.GET); Routes(ApiRoutes.Themes.GET_THEME_ASSET); Version(1); + // theme content is public, since the web renders themed pages for anonymous visitors too (i.e.: login page); only install and manage operations are admin-gated AllowAnonymous(); DontCatchExceptions(); } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeSettings/GetThemeSettingsEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeSettings/GetThemeSettingsEndpoint.cs index ba384018..fd6c177d 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeSettings/GetThemeSettingsEndpoint.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeSettings/GetThemeSettingsEndpoint.cs @@ -37,6 +37,7 @@ public class GetThemeSettingsEndpoint : BaseEndpoint Verbs(Http.GET); Routes(ApiRoutes.Themes.GET_THEME_SETTINGS); Version(1); + // theme content is public, since the web renders themed pages for anonymous visitors too (i.e.: login page); only install and manage operations are admin-gated AllowAnonymous(); DontCatchExceptions(); } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeTemplate/GetThemeTemplateEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeTemplate/GetThemeTemplateEndpoint.cs index 439b27f4..10cae257 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeTemplate/GetThemeTemplateEndpoint.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Themes/Queries/GetThemeTemplate/GetThemeTemplateEndpoint.cs @@ -39,6 +39,7 @@ public class GetThemeTemplateEndpoint : BaseEndpoint 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."); + // the API route token is a catch-all ("{*assetPath}"), so the replace target must include the star to match it 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); diff --git a/src/Lumina.Presentation.Web/Core/Themes/RazorViewToStringRenderer.cs b/src/Lumina.Presentation.Web/Core/Themes/RazorViewToStringRenderer.cs index 834fd809..7961f07f 100644 --- a/src/Lumina.Presentation.Web/Core/Themes/RazorViewToStringRenderer.cs +++ b/src/Lumina.Presentation.Web/Core/Themes/RazorViewToStringRenderer.cs @@ -49,6 +49,7 @@ public sealed class RazorViewToStringRenderer /// The rendered HTML of the partial. public async Task RenderPartialAsync(string partialName, CancellationToken cancellationToken = default) { + // the theme shell reuses the application's Razor chrome as strings, so the same markup stays in one place HttpContext httpContext = _httpContextAccessor.HttpContext ?? throw new InvalidOperationException("The current HTTP context is unavailable."); ActionContext actionContext = new(httpContext, httpContext.GetRouteData() ?? new RouteData(), new ActionDescriptor()); IView view = _viewEngine.FindView(actionContext, partialName, isMainPage: false).View diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemeNavBuilder.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemeNavBuilder.cs index 7dd6b983..eed43d75 100644 --- a/src/Lumina.Presentation.Web/Core/Themes/ThemeNavBuilder.cs +++ b/src/Lumina.Presentation.Web/Core/Themes/ThemeNavBuilder.cs @@ -60,6 +60,8 @@ public sealed class ThemeNavBuilder string returnUrl = Uri.EscapeDataString(GetCurrentRequestUrl()); ThemeNavEntryDto[] languages = CreateLanguageEntries(returnUrl); + // the mobile and desktop menus arrange the same sections differently, notably the language switcher, which is + // its own mobile heading but a submenu under Tools on the desktop, so each menu gets its own section list List mobileSections = []; mobileSections.Add(CreateSiteSection()); mobileSections.Add(CreateAccountSection(isAuthenticated)); diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemePageDataFactory.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemePageDataFactory.cs index 85f1c29c..25f752fc 100644 --- a/src/Lumina.Presentation.Web/Core/Themes/ThemePageDataFactory.cs +++ b/src/Lumina.Presentation.Web/Core/Themes/ThemePageDataFactory.cs @@ -17,6 +17,7 @@ public static class ThemePageDataFactory /// The localized strings keyed by their resource names. public static Dictionary CreateLocalizedStrings(IStringLocalizer localizer) { + // expose the page's full resource set, so templates can pull any localized string without the page enumerating keys Dictionary strings = []; foreach (LocalizedString localizedString in localizer.GetAllStrings(includeParentCultures: true)) strings[localizedString.Name] = localizedString.Value; diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemePageRenderer.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemePageRenderer.cs index 1e7ceda8..bbcc3f8b 100644 --- a/src/Lumina.Presentation.Web/Core/Themes/ThemePageRenderer.cs +++ b/src/Lumina.Presentation.Web/Core/Themes/ThemePageRenderer.cs @@ -40,6 +40,7 @@ public class ThemePageRenderer model.ThemeId = document.Theme.Id; model.AssetBase = $"/theme-assets/{document.Theme.Id}/assets"; + // a fresh script id per render lets the AJAX navigator unload this view's script when navigating away model.ScriptId = ScriptIdentifierHelper.GenerateScriptId(); return _templateEngine.RenderPage(document.Template, model); diff --git a/src/Lumina.Presentation.Web/Core/Themes/ThemeTemplateEngine.cs b/src/Lumina.Presentation.Web/Core/Themes/ThemeTemplateEngine.cs index 3a838b82..a535de9c 100644 --- a/src/Lumina.Presentation.Web/Core/Themes/ThemeTemplateEngine.cs +++ b/src/Lumina.Presentation.Web/Core/Themes/ThemeTemplateEngine.cs @@ -18,6 +18,7 @@ namespace Lumina.Presentation.Web.Core.Themes; /// public sealed class ThemeTemplateEngine { + // bound template nesting and rendered output, so a single theme cannot exhaust the server memory private const int MAX_NESTING_DEPTH = 32; private const int MAX_RENDERED_CHARACTERS = 4 * 1024 * 1024; diff --git a/src/Lumina.Presentation.Web/Core/Views/Shared/_Layout.cshtml b/src/Lumina.Presentation.Web/Core/Views/Shared/_Layout.cshtml index 8bb2c584..538e66af 100644 --- a/src/Lumina.Presentation.Web/Core/Views/Shared/_Layout.cshtml +++ b/src/Lumina.Presentation.Web/Core/Views/Shared/_Layout.cshtml @@ -8,6 +8,7 @@ @inject ThemeLayoutRenderer _themeLayoutRenderer @{ + // capture the page body and its scripts, so the themed shell can wrap them instead of rendering them directly string bodyHtml; using (StringWriter bodyWriter = new()) { @@ -19,6 +20,7 @@ string scriptsHtml; using (StringWriter scriptsWriter = new()) { + // RenderSectionAsync writes to ViewContext.Writer, so swap it to capture the section content TextWriter originalWriter = ViewContext.Writer; ViewContext.Writer = scriptsWriter; await RenderSectionAsync("Scripts", required: false);