diff --git a/Lombiq.Hosting.MediaTheme.Bridge/Services/FileVersionProviderDecorator.cs b/Lombiq.Hosting.MediaTheme.Bridge/Services/FileVersionProviderDecorator.cs index a3a067c..628ddf5 100644 --- a/Lombiq.Hosting.MediaTheme.Bridge/Services/FileVersionProviderDecorator.cs +++ b/Lombiq.Hosting.MediaTheme.Bridge/Services/FileVersionProviderDecorator.cs @@ -1,6 +1,8 @@ +using Lombiq.HelpfulLibraries.Common.Utilities; using Lombiq.Hosting.MediaTheme.Bridge.Constants; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Options; using OrchardCore.FileStorage; using OrchardCore.Media; @@ -24,6 +26,7 @@ internal sealed class FileVersionProviderDecorator : IFileVersionProvider private readonly IFileVersionProvider _decorated; private readonly IMediaFileStore _mediaFileStore; private readonly IOptions _mediaOption; + private readonly NonSecurityRandomizer _randomizer = new(); public FileVersionProviderDecorator( IFileVersionProvider decorated, @@ -58,6 +61,12 @@ public string AddFileVersionToPath(PathString requestPathBase, string path) // we need to add a random parameter. var cacheBustedPath = _decorated.AddFileVersionToPath(requestPathBase, path.Replace(Routes.MediaThemeAssets, assetsSubPath)); + // This check could be more sophisticated with UriBuilder, but let's keep it simple, since it'll run frequently. + if (!cacheBustedPath.Contains("?v=")) + { + return QueryHelpers.AddQueryString(path, "mediatheme", _randomizer.Get().ToTechnicalString()); + } + return cacheBustedPath.Replace(assetsSubPath, Routes.MediaThemeAssets); } } diff --git a/Lombiq.Hosting.MediaTheme.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs b/Lombiq.Hosting.MediaTheme.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs index e6dc183..352a38c 100644 --- a/Lombiq.Hosting.MediaTheme.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs +++ b/Lombiq.Hosting.MediaTheme.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs @@ -27,7 +27,7 @@ public static async Task TestMediaThemeLocalBehaviorAsync(this UITestContext con { await context.SetThemeDirectlyAsync("Lombiq.Hosting.MediaTheme.Tests.Theme"); await context.GoToHomePageAsync(onlyIfNotAlreadyThere: false); - AssertElements(context, "v", tenantPrefix); + AssertElements(context, "mediatheme", tenantPrefix); } private static void AssertElements(UITestContext context, string cacheBustingParameterName, string tenantPrefix)