Skip to content

Commit

Permalink
Fixing that media theme URLs are not evaluated on prefixed tenants
Browse files Browse the repository at this point in the history
  • Loading branch information
barthamark committed Mar 19, 2024
1 parent 1eda7ff commit 93c6bb6
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Lombiq.Hosting.MediaTheme.Bridge.Constants;
using Microsoft.AspNetCore.Http;
using OrchardCore.Environment.Shell;
using OrchardCore.FileStorage;
using OrchardCore.Media;
using OrchardCore.Themes.Services;
Expand All @@ -21,7 +22,8 @@ internal sealed class MediaThemeAssetUrlRewritingMiddleware
public async Task InvokeAsync(
HttpContext context,
IMediaFileStore mediaFileStore,
ISiteThemeService siteThemeService)
ISiteThemeService siteThemeService,
ShellSettings shellSettings)
{
var isMediaThemeRequest = context.Request.Path
.StartsWithSegments(new PathString(Routes.MediaThemeAssets), StringComparison.OrdinalIgnoreCase, out _);
Expand All @@ -40,6 +42,12 @@ public async Task InvokeAsync(
if (!context.IsDevelopment() || await mediaFileStore.FileExistsAsync(mediaPath))
{
assetUrl = mediaFileStore.MapPathToPublicUrl(mediaPath);

if (!string.IsNullOrEmpty(shellSettings.RequestUrlPrefix) &&
assetUrl.StartsWith("/" + shellSettings.RequestUrlPrefix, StringComparison.OrdinalIgnoreCase))
{
assetUrl = assetUrl[(shellSettings.RequestUrlPrefix.Length + 1)..];
}
}
else
{
Expand Down

0 comments on commit 93c6bb6

Please sign in to comment.