Skip to content

Commit

Permalink
Revert "Remove code path from FileVersionProviderDecorator that will …
Browse files Browse the repository at this point in the history
…never be true in OC 2.0." as it's not universally true.
  • Loading branch information
sarahelsaig committed Aug 20, 2024
1 parent 6205528 commit 2f1cba8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,6 +26,7 @@ internal sealed class FileVersionProviderDecorator : IFileVersionProvider
private readonly IFileVersionProvider _decorated;
private readonly IMediaFileStore _mediaFileStore;
private readonly IOptions<MediaOptions> _mediaOption;
private readonly NonSecurityRandomizer _randomizer = new();

public FileVersionProviderDecorator(
IFileVersionProvider decorated,
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2f1cba8

Please sign in to comment.