@@ -12,7 +12,7 @@ namespace Umbraco.StorageProviders.AzureBlob.IO;
12
12
/// <inheritdoc />
13
13
public sealed class AzureBlobFileSystem : IAzureBlobFileSystem , IFileProviderFactory
14
14
{
15
- private readonly string _rootUrl ;
15
+ private readonly string _requestRootPath ;
16
16
private readonly string _containerRootPath ;
17
17
private readonly BlobContainerClient _container ;
18
18
private readonly IIOHelper _ioHelper ;
@@ -21,7 +21,7 @@ public sealed class AzureBlobFileSystem : IAzureBlobFileSystem, IFileProviderFac
21
21
/// <summary>
22
22
/// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class.
23
23
/// </summary>
24
- /// <param name="options">The options.</param>
24
+ /// <param name="options">The Azure Blob File System options.</param>
25
25
/// <param name="hostingEnvironment">The hosting environment.</param>
26
26
/// <param name="ioHelper">The I/O helper.</param>
27
27
/// <param name="contentTypeProvider">The content type provider.</param>
@@ -30,35 +30,27 @@ public sealed class AzureBlobFileSystem : IAzureBlobFileSystem, IFileProviderFac
30
30
/// <exception cref="System.ArgumentNullException"><paramref name="ioHelper" /> is <c>null</c>.</exception>
31
31
/// <exception cref="System.ArgumentNullException"><paramref name="contentTypeProvider" /> is <c>null</c>.</exception>
32
32
public AzureBlobFileSystem ( AzureBlobFileSystemOptions options , IHostingEnvironment hostingEnvironment , IIOHelper ioHelper , IContentTypeProvider contentTypeProvider )
33
- {
34
- ArgumentNullException . ThrowIfNull ( options ) ;
35
- ArgumentNullException . ThrowIfNull ( hostingEnvironment ) ;
36
-
37
- _rootUrl = EnsureUrlSeparatorChar ( hostingEnvironment . ToAbsolute ( options . VirtualPath ) ) . TrimEnd ( '/' ) ;
38
- _containerRootPath = options . ContainerRootPath ?? _rootUrl ;
39
- _container = new BlobContainerClient ( options . ConnectionString , options . ContainerName ) ;
40
- _ioHelper = ioHelper ?? throw new ArgumentNullException ( nameof ( ioHelper ) ) ;
41
- _contentTypeProvider = contentTypeProvider ?? throw new ArgumentNullException ( nameof ( contentTypeProvider ) ) ;
42
- }
33
+ : this ( GetRequestRootPath ( options , hostingEnvironment ) , new BlobContainerClient ( options . ConnectionString , options . ContainerName ) , ioHelper , contentTypeProvider , options . ContainerRootPath )
34
+ { }
43
35
44
36
/// <summary>
45
37
/// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class.
46
38
/// </summary>
47
- /// <param name="rootUrl ">The root URL .</param>
39
+ /// <param name="requestRootPath ">The request/URL root path .</param>
48
40
/// <param name="blobContainerClient">The blob container client.</param>
49
41
/// <param name="ioHelper">The I/O helper.</param>
50
42
/// <param name="contentTypeProvider">The content type provider.</param>
51
- /// <param name="containerRootPath">The container root path (uses the root URL if not set).</param>
52
- /// <exception cref="System.ArgumentNullException"><paramref name="rootUrl " /> is <c>null</c>.</exception>
43
+ /// <param name="containerRootPath">The container root path (uses the request/URL root path if not set).</param>
44
+ /// <exception cref="System.ArgumentNullException"><paramref name="requestRootPath " /> is <c>null</c>.</exception>
53
45
/// <exception cref="System.ArgumentNullException"><paramref name="blobContainerClient" /> is <c>null</c>.</exception>
54
46
/// <exception cref="System.ArgumentNullException"><paramref name="ioHelper" /> is <c>null</c>.</exception>
55
47
/// <exception cref="System.ArgumentNullException"><paramref name="contentTypeProvider" /> is <c>null</c>.</exception>
56
- public AzureBlobFileSystem ( string rootUrl , BlobContainerClient blobContainerClient , IIOHelper ioHelper , IContentTypeProvider contentTypeProvider , string ? containerRootPath = null )
48
+ public AzureBlobFileSystem ( string requestRootPath , BlobContainerClient blobContainerClient , IIOHelper ioHelper , IContentTypeProvider contentTypeProvider , string ? containerRootPath = null )
57
49
{
58
- ArgumentNullException . ThrowIfNull ( rootUrl ) ;
50
+ ArgumentNullException . ThrowIfNull ( requestRootPath ) ;
59
51
60
- _rootUrl = EnsureUrlSeparatorChar ( rootUrl ) . TrimEnd ( '/' ) ;
61
- _containerRootPath = containerRootPath ?? _rootUrl ;
52
+ _requestRootPath = EnsureUrlSeparatorChar ( requestRootPath ) . TrimEnd ( '/' ) ;
53
+ _containerRootPath = containerRootPath ?? _requestRootPath ;
62
54
_container = blobContainerClient ?? throw new ArgumentNullException ( nameof ( blobContainerClient ) ) ;
63
55
_ioHelper = ioHelper ?? throw new ArgumentNullException ( nameof ( ioHelper ) ) ;
64
56
_contentTypeProvider = contentTypeProvider ?? throw new ArgumentNullException ( nameof ( contentTypeProvider ) ) ;
@@ -275,11 +267,11 @@ public string GetRelativePath(string fullPathOrUrl)
275
267
// test url
276
268
var path = EnsureUrlSeparatorChar ( fullPathOrUrl ) ; // ensure url separator char
277
269
278
- // if it starts with the root url , strip it and trim the starting slash to make it relative
270
+ // if it starts with the request/URL root path , strip it and trim the starting slash to make it relative
279
271
// eg "/Media/1234/img.jpg" => "1234/img.jpg"
280
- if ( _ioHelper . PathStartsWith ( path , _rootUrl , '/' ) )
272
+ if ( _ioHelper . PathStartsWith ( path , _requestRootPath , '/' ) )
281
273
{
282
- path = path [ _rootUrl . Length ..] . TrimStart ( '/' ) ;
274
+ path = path [ _requestRootPath . Length ..] . TrimStart ( '/' ) ;
283
275
}
284
276
285
277
// unchanged - what else?
@@ -293,16 +285,17 @@ public string GetFullPath(string path)
293
285
ArgumentNullException . ThrowIfNull ( path ) ;
294
286
295
287
path = EnsureUrlSeparatorChar ( path ) ;
296
- return ( _ioHelper . PathStartsWith ( path , _rootUrl , '/' ) ? path : $ "{ _rootUrl } /{ path } ") . Trim ( '/' ) ;
288
+ return ( _ioHelper . PathStartsWith ( path , _requestRootPath , '/' ) ? path : $ "{ _requestRootPath } /{ path } ") . Trim ( '/' ) ;
297
289
}
298
290
299
291
/// <inheritdoc />
300
292
/// <exception cref="System.ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception>
293
+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Design" , "CA1055:URI-like return values should not be strings" , Justification = "This method is inherited from an interface." ) ]
301
294
public string GetUrl ( string ? path )
302
295
{
303
296
ArgumentNullException . ThrowIfNull ( path ) ;
304
297
305
- return $ "{ _rootUrl } /{ EnsureUrlSeparatorChar ( path ) . Trim ( '/' ) } ";
298
+ return $ "{ _requestRootPath } /{ EnsureUrlSeparatorChar ( path ) . Trim ( '/' ) } ";
306
299
}
307
300
308
301
/// <inheritdoc />
@@ -344,6 +337,14 @@ public BlobClient GetBlobClient(string path)
344
337
/// <inheritdoc />
345
338
public IFileProvider Create ( ) => new AzureBlobFileProvider ( _container , _containerRootPath ) ;
346
339
340
+ private static string GetRequestRootPath ( AzureBlobFileSystemOptions options , IHostingEnvironment hostingEnvironment )
341
+ {
342
+ ArgumentNullException . ThrowIfNull ( options ) ;
343
+ ArgumentNullException . ThrowIfNull ( hostingEnvironment ) ;
344
+
345
+ return hostingEnvironment . ToAbsolute ( options . VirtualPath ) ;
346
+ }
347
+
347
348
private static string EnsureUrlSeparatorChar ( string path )
348
349
=> path . Replace ( "\\ " , "/" , StringComparison . InvariantCultureIgnoreCase ) ;
349
350
@@ -354,7 +355,7 @@ private string GetDirectoryPath(string fullPathOrUrl)
354
355
return path . Length == 0 ? path : path . EnsureEndsWith ( '/' ) ;
355
356
}
356
357
357
- private IEnumerable < BlobHierarchyItem > ListBlobs ( string path )
358
+ private Pageable < BlobHierarchyItem > ListBlobs ( string path )
358
359
=> _container . GetBlobsByHierarchy ( prefix : path ) ;
359
360
360
361
private string GetBlobPath ( string path )
@@ -368,10 +369,10 @@ private string GetBlobPath(string path)
368
369
return path ;
369
370
}
370
371
371
- if ( _ioHelper . PathStartsWith ( path , _rootUrl , '/' ) )
372
+ if ( _ioHelper . PathStartsWith ( path , _requestRootPath , '/' ) )
372
373
{
373
- // Remove root URL from path (e.g. /media/abc123/file.ext to /abc123/file.ext)
374
- path = path [ _rootUrl . Length ..] ;
374
+ // Remove request/URL root path from path (e.g. /media/abc123/file.ext to /abc123/file.ext)
375
+ path = path [ _requestRootPath . Length ..] ;
375
376
}
376
377
377
378
path = $ "{ _containerRootPath } /{ path . TrimStart ( '/' ) } ";
0 commit comments