mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 01:01:10 +00:00
Removes the option to disable theme scripts
This commit is contained in:
1 parent
531450b3db
commit
15945c2e56
17 files changed
+15
-201
No files matched your search
@@ -14,11 +14,6 @@ namespace Lumina.Application.Common.Infrastructure.Themes;
|
||||
/// </summary>
|
||||
public interface IThemeService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether theme templates may contain script elements and theme assets may include script files.
|
||||
/// </summary>
|
||||
bool AllowThemeScripts { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum allowed size of a theme archive, in bytes.
|
||||
/// </summary>
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class GetThemeSettingsQueryHandler : IQueryHandler<GetThemeSettingsQuery,
|
||||
/// </returns>
|
||||
public Task<Result<ThemeSettingsResponse>> HandleAsync(GetThemeSettingsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
ThemeSettingsResponse response = new(_themeService.MaxArchiveBytes, _themeService.AllowThemeScripts, _themeService.DefaultThemeId);
|
||||
ThemeSettingsResponse response = new(_themeService.MaxArchiveBytes, _themeService.DefaultThemeId);
|
||||
return Task.FromResult(Result.From(response));
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,9 @@ namespace Lumina.Contracts.Responses.Themes;
|
||||
/// Represents a theme settings response.
|
||||
/// </summary>
|
||||
/// <param name="MaxArchiveBytes">The maximum allowed size of a theme archive, in bytes.</param>
|
||||
/// <param name="AllowThemeScripts">Whether theme templates may contain script elements and theme assets may include script files.</param>
|
||||
/// <param name="DefaultThemeId">The identifier of the theme selected when no valid current theme is available.</param>
|
||||
[DebuggerDisplay("MaxArchiveBytes: {MaxArchiveBytes}")]
|
||||
public record ThemeSettingsResponse(
|
||||
long MaxArchiveBytes,
|
||||
bool AllowThemeScripts,
|
||||
string DefaultThemeId
|
||||
);
|
||||
@@ -46,9 +46,4 @@ public sealed class ThemeEngineOptionsDto
|
||||
/// 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; }
|
||||
}
|
||||
@@ -45,12 +45,6 @@ public sealed class ThemeService : IThemeService
|
||||
"^[A-Za-z0-9][A-Za-z0-9._ -]*$",
|
||||
RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
||||
|
||||
// strips every script element from a template, both the inline content and the src attribute variants,
|
||||
// so that no script bundled in a theme is executed in any client when scripts are disabled
|
||||
private static readonly Regex s_scriptElementPattern = new(
|
||||
"<script\\b[^>]*>[\\s\\S]*?</script\\s*>",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
||||
|
||||
private static readonly JsonSerializerOptions s_manifestJsonOptions = new(JsonSerializerDefaults.Web)
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
@@ -87,11 +81,6 @@ public sealed class ThemeService : IThemeService
|
||||
_mutationGate = s_storageGates.GetOrAdd(_storageRoot, static _ => new SemaphoreSlim(1, 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether theme templates may contain script elements and theme assets may include script files.
|
||||
/// </summary>
|
||||
public bool AllowThemeScripts => _options.AllowThemeScripts;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum allowed size of a theme archive, in bytes.
|
||||
/// </summary>
|
||||
@@ -280,8 +269,6 @@ public sealed class ThemeService : IThemeService
|
||||
return Errors.Themes.ThemeFilesUnreadable;
|
||||
|
||||
string template = await File.ReadAllTextAsync(fullPathResult.Value, cancellationToken);
|
||||
if (!AllowThemeScripts)
|
||||
template = StripScriptElements(template);
|
||||
|
||||
return template;
|
||||
}
|
||||
@@ -330,10 +317,6 @@ public sealed class ThemeService : IThemeService
|
||||
if (!normalizedPath.StartsWith("assets/", StringComparison.Ordinal))
|
||||
return PackageInvalid("The requested asset is not located under the assets directory.");
|
||||
|
||||
// scripts in theme assets are gated globally: when disabled, script files are not served at all
|
||||
if (!AllowThemeScripts && string.Equals(Path.GetExtension(normalizedPath), ".js", StringComparison.OrdinalIgnoreCase))
|
||||
return Errors.Themes.ThemeFilesUnreadable;
|
||||
|
||||
Result<string> fullPathResult = ResolveContainedPath(ResolveThemePath(themeId), normalizedPath);
|
||||
if (fullPathResult.IsFailure)
|
||||
return fullPathResult.Errors;
|
||||
@@ -782,16 +765,6 @@ public sealed class ThemeService : IThemeService
|
||||
return Error.Validation(code: "Theme.Package.Invalid", description: description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes every script element from a theme template, so that no script bundled in the theme runs when scripts are disabled.
|
||||
/// </summary>
|
||||
/// <param name="template">The template content to strip script elements from.</param>
|
||||
/// <returns>The template content without script elements.</returns>
|
||||
private static string StripScriptElements(string template)
|
||||
{
|
||||
return s_scriptElementPattern.Replace(template, string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the storage path of a theme pack directory for a theme identifier.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
"MaxArchiveBytes": 8388608,
|
||||
"MaxExpandedBytes": 25165824,
|
||||
"MaxSingleFileBytes": 6291456,
|
||||
"MaxEntries": 250,
|
||||
"AllowThemeScripts": true
|
||||
"MaxEntries": 250
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=<host>;Database=<database>;User Id=<user>;Password=<password>;"
|
||||
|
||||
+1
-2
@@ -19,12 +19,11 @@ public class GetThemeSettingsEndpointSummary : Summary<GetThemeSettingsEndpoint,
|
||||
public GetThemeSettingsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the theme engine settings.";
|
||||
Description = "Retrieves the settings of the theme engine, including whether theme scripts are allowed and the maximum archive size.";
|
||||
Description = "Retrieves the settings of the theme engine, including the maximum archive size.";
|
||||
|
||||
Response(200, "The theme engine settings are returned.",
|
||||
example: new ThemeSettingsResponse(
|
||||
MaxArchiveBytes: 8388608,
|
||||
AllowThemeScripts: false,
|
||||
DefaultThemeId: "lumina-default"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -22,11 +22,6 @@ public sealed class ThemeAdminDto
|
||||
/// </summary>
|
||||
public required string CurrentThemeId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether theme templates may load script files.
|
||||
/// </summary>
|
||||
public required bool AllowThemeScripts { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum allowed size of a theme archive, in bytes.
|
||||
/// </summary>
|
||||
|
||||
@@ -9,11 +9,9 @@ namespace Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
/// Data transfer object for the theme engine settings returned by the remote API.
|
||||
/// </summary>
|
||||
/// <param name="MaxArchiveBytes">The maximum allowed size of a theme archive, in bytes.</param>
|
||||
/// <param name="AllowThemeScripts">Whether theme templates may contain script elements and theme assets may include script files.</param>
|
||||
/// <param name="DefaultThemeId">The identifier of the theme selected when no valid current theme is available.</param>
|
||||
[DebuggerDisplay("MaxArchiveBytes: {MaxArchiveBytes}")]
|
||||
public sealed record ThemeSettingsResponseDto(
|
||||
long MaxArchiveBytes,
|
||||
bool AllowThemeScripts,
|
||||
string DefaultThemeId
|
||||
);
|
||||
@@ -58,7 +58,6 @@ public class GetThemesEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
Themes = themes,
|
||||
CurrentThemeId = currentTheme.Id,
|
||||
AllowThemeScripts = settings.AllowThemeScripts,
|
||||
MaxArchiveBytes = settings.MaxArchiveBytes
|
||||
};
|
||||
return JsonSuccess(themeAdmin);
|
||||
|
||||
Reference in new issue
Block a user