66using Microsoft . AspNetCore . WebUtilities ;
77using Microsoft . Extensions . DependencyInjection ;
88using Microsoft . Extensions . FileProviders ;
9- using System ;
109using System . Security . Cryptography ;
1110using System . Text ;
1211
@@ -20,8 +19,6 @@ public static class DeliveryTypeExtensions
2019 /// <summary>
2120 /// Fetch file from absolute or relative url.
2221 /// </summary>
23- /// <param name="url"></param>
24- /// <returns></returns>
2522 public static IFilter Fetch ( this ILoader imageUrlBuilder , string url )
2623 {
2724 return imageUrlBuilder . LoadData ( "fetch" , url ) ;
@@ -30,18 +27,8 @@ public static IFilter Fetch(this ILoader imageUrlBuilder, string url)
3027 /// <summary>
3128 /// Fetch file from wwwroot folder with fingerprint.
3229 /// </summary>
33- /// <param name="path"></param>
34- /// <returns></returns>
35- public static IFilter FetchLocalFile ( this ILoader imageBuilder , string path , int ? hashNameLength = null )
30+ public static IFilter FetchLocalFile ( this ILoader imageBuilder , string path , int maxVersionLength = 8 )
3631 {
37- if ( hashNameLength != null )
38- {
39- if ( hashNameLength < 1 || hashNameLength > 43 )
40- {
41- throw new ArgumentOutOfRangeException ( nameof ( hashNameLength ) ) ;
42- }
43- }
44-
4532 path = path . TrimStart ( '/' ) ;
4633
4734 IWebHostEnvironment env = imageBuilder . ServiceProvider . GetRequiredService < IWebHostEnvironment > ( ) ;
@@ -55,14 +42,7 @@ public static IFilter FetchLocalFile(this ILoader imageBuilder, string path, int
5542
5643 string hashBase64 = WebEncoders . Base64UrlEncode ( hashBufferSpan ) ;
5744
58- if ( hashNameLength == null )
59- {
60- path += $ "?v={ hashBase64 } ";
61- }
62- else
63- {
64- path += $ "?v={ hashBase64 . AsSpan ( 0 , hashNameLength . Value ) } ";
65- }
45+ path += $ "?v={ hashBase64 . AsSpan ( 0 , maxVersionLength ) } ";
6646
6747 return imageBuilder . LoadData ( "fetch" , path ) ;
6848 }
0 commit comments