Skip to content

Commit f7e4739

Browse files
authored
Merge pull request #18 from umbraco/bugfix/keep-physicalfilesystemprovider
Add AzureBlobFileSystemImageProvider as first provider and only match configured root path
2 parents 8749d2a + 0a62096 commit f7e4739

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/Umbraco.StorageProviders.AzureBlob/DependencyInjection/AzureBlobMediaFileSystemExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static IUmbracoBuilder AddAzureBlobMediaFileSystem(this IUmbracoBuilder b
4444
builder.Services.TryAddSingleton<AzureBlobFileSystemMiddleware>();
4545

4646
// ImageSharp image provider/cache
47-
builder.Services.AddUnique<IImageProvider, AzureBlobFileSystemImageProvider>();
47+
builder.Services.Insert(0, ServiceDescriptor.Singleton<IImageProvider, AzureBlobFileSystemImageProvider>());
4848
builder.Services.AddUnique<IImageCache, AzureBlobFileSystemImageCache>();
4949

5050
builder.SetMediaFileSystem(provider => provider.GetRequiredService<IAzureBlobFileSystemProvider>()

src/Umbraco.StorageProviders.AzureBlob/Imaging/AzureBlobFileSystemImageProvider.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public class AzureBlobFileSystemImageProvider : IImageProvider
2020
private string _rootPath;
2121
private readonly FormatUtilities _formatUtilities;
2222

23+
/// <summary>
24+
/// A match function used by the resolver to identify itself as the correct resolver to use.
25+
/// </summary>
26+
private Func<HttpContext, bool>? _match;
27+
2328
/// <summary>
2429
/// Initializes a new instance of the <see cref="AzureBlobFileSystemImageProvider" /> class.
2530
/// </summary>
@@ -68,8 +73,7 @@ public bool IsValidRequest(HttpContext context)
6873
{
6974
if (context == null) throw new ArgumentNullException(nameof(context));
7075

71-
return context.Request.Path.StartsWithSegments(_rootPath, StringComparison.InvariantCultureIgnoreCase)
72-
&& _formatUtilities.GetExtensionFromUri(context.Request.GetDisplayUrl()) != null;
76+
return _formatUtilities.GetExtensionFromUri(context.Request.GetDisplayUrl()) != null;
7377
}
7478

7579
/// <inheritdoc />
@@ -95,8 +99,19 @@ public bool IsValidRequest(HttpContext context)
9599
/// <inheritdoc />
96100
public ProcessingBehavior ProcessingBehavior => ProcessingBehavior.CommandOnly;
97101

98-
/// <inheritdoc />
99-
public Func<HttpContext, bool> Match { get; set; } = _ => true;
102+
/// <inheritdoc/>
103+
public Func<HttpContext, bool> Match
104+
{
105+
get => this._match ?? IsMatch;
106+
set => this._match = value;
107+
}
108+
109+
private bool IsMatch(HttpContext context)
110+
{
111+
if (context == null) throw new ArgumentNullException(nameof(context));
112+
113+
return context.Request.Path.StartsWithSegments(_rootPath, StringComparison.InvariantCultureIgnoreCase);
114+
}
100115

101116
private void OptionsOnChange(AzureBlobFileSystemOptions options, string name, IHostingEnvironment hostingEnvironment)
102117
{

0 commit comments

Comments
 (0)