mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 02:01:10 +00:00
Adds comments.
This commit is contained in:
1 parent
4ef8570854
commit
fd64cbd6ba
13 files changed
+17
No files matched your search
+1
@@ -47,6 +47,7 @@ public class GetThemesQueryHandler : IQueryHandler<GetThemesQuery, Result<IReadO
|
||||
|
||||
return Result.From<IReadOnlyList<ThemeResponse>>([.. 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())]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
/// <summary>
|
||||
@@ -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.");
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ public class GetCurrentThemeEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
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();
|
||||
}
|
||||
|
||||
+1
@@ -39,6 +39,7 @@ public class GetThemeAssetEndpoint : BaseEndpoint<GetThemeAssetRequest, IResult>
|
||||
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();
|
||||
}
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ public class GetThemeSettingsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
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();
|
||||
}
|
||||
|
||||
+1
@@ -39,6 +39,7 @@ public class GetThemeTemplateEndpoint : BaseEndpoint<GetThemeTemplateRequest, IR
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Themes.GET_THEME_TEMPLATE);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class ThemeAssetsEndpoint : BaseEndpoint<GetThemeAssetRequest, IResult>
|
||||
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);
|
||||
|
||||
@@ -49,6 +49,7 @@ public sealed class RazorViewToStringRenderer
|
||||
/// <returns>The rendered HTML of the partial.</returns>
|
||||
public async Task<string> 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
|
||||
|
||||
@@ -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<ThemeNavSectionDto> mobileSections = [];
|
||||
mobileSections.Add(CreateSiteSection());
|
||||
mobileSections.Add(CreateAccountSection(isAuthenticated));
|
||||
|
||||
@@ -17,6 +17,7 @@ public static class ThemePageDataFactory
|
||||
/// <returns>The localized strings keyed by their resource names.</returns>
|
||||
public static Dictionary<string, object?> CreateLocalizedStrings(IStringLocalizer localizer)
|
||||
{
|
||||
// expose the page's full resource set, so templates can pull any localized string without the page enumerating keys
|
||||
Dictionary<string, object?> strings = [];
|
||||
foreach (LocalizedString localizedString in localizer.GetAllStrings(includeParentCultures: true))
|
||||
strings[localizedString.Name] = localizedString.Value;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Lumina.Presentation.Web.Core.Themes;
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user