Skip to content

Commit 09c256e

Browse files
Merge branch 'main' into js/optimize-pixel-memory
2 parents c3adc65 + ce43688 commit 09c256e

17 files changed

Lines changed: 298 additions & 169 deletions

.github/workflows/build-and-test.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,48 @@ jobs:
1515
strategy:
1616
matrix:
1717
options:
18+
- os: ubuntu-latest
19+
framework: net6.0
20+
runtime: -x64
21+
codecov: false
1822
- os: macos-latest
19-
framework: netcoreapp3.1
23+
framework: net6.0
24+
runtime: -x64
25+
codecov: false
26+
- os: windows-latest
27+
framework: net6.0
28+
runtime: -x64
29+
codecov: true
30+
- os: ubuntu-latest
31+
framework: net5.0
32+
runtime: -x64
33+
codecov: false
34+
- os: macos-latest
35+
framework: net5.0
36+
runtime: -x64
37+
codecov: false
38+
- os: windows-latest
39+
framework: net5.0
2040
runtime: -x64
2141
codecov: false
2242
- os: ubuntu-latest
2343
framework: netcoreapp3.1
2444
runtime: -x64
2545
codecov: false
46+
- os: macos-latest
47+
framework: netcoreapp3.1
48+
runtime: -x64
49+
codecov: false
2650
- os: windows-latest
2751
framework: netcoreapp3.1
2852
runtime: -x64
29-
codecov: true
53+
codecov: false
3054
- os: windows-latest
3155
framework: netcoreapp2.1
3256
runtime: -x64
3357
codecov: false
3458

3559
runs-on: ${{matrix.options.os}}
36-
if: "!contains(github.event.head_commit.message, '[skip ci]')"
3760

3861
steps:
3962
- name: Git Config
@@ -49,7 +72,7 @@ jobs:
4972
submodules: recursive
5073

5174
# See https://github.com/actions/checkout/issues/165#issuecomment-657673315
52-
- name: Git Create LFS file list
75+
- name: Git Create LFS FileList
5376
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
5477

5578
- name: Git Setup LFS Cache

samples/ImageSharp.Web.Sample/Startup.cs

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.Extensions.Configuration;
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Hosting;
11-
using Microsoft.Extensions.Options;
1211
using SixLabors.ImageSharp.Web.Caching;
1312
using SixLabors.ImageSharp.Web.Commands;
1413
using SixLabors.ImageSharp.Web.DependencyInjection;
@@ -43,17 +42,17 @@ public void ConfigureServices(IServiceCollection services)
4342
.SetRequestParser<QueryCollectionRequestParser>()
4443
.Configure<PhysicalFileSystemCacheOptions>(options =>
4544
{
45+
options.CacheRootPath = null;
4646
options.CacheFolder = "is-cache";
47+
options.CacheFolderDepth = 8;
4748
})
48-
.SetCache(provider =>
49-
{
50-
return new PhysicalFileSystemCache(
51-
provider.GetRequiredService<IOptions<PhysicalFileSystemCacheOptions>>(),
52-
provider.GetRequiredService<IWebHostEnvironment>(),
53-
provider.GetRequiredService<FormatUtilities>());
54-
})
49+
.SetCache<PhysicalFileSystemCache>()
5550
.SetCacheKey<UriRelativeLowerInvariantCacheKey>()
5651
.SetCacheHash<SHA256CacheHash>()
52+
.Configure<PhysicalFileSystemProviderOptions>(options =>
53+
{
54+
options.ProviderRootPath = null;
55+
})
5756
.AddProvider<PhysicalFileSystemProvider>()
5857
.AddProcessor<ResizeWebProcessor>()
5958
.AddProcessor<FormatWebProcessor>()
@@ -80,18 +79,17 @@ public void ConfigureServices(IServiceCollection services)
8079

8180
private void ConfigureDefaultServicesAndCustomOptions(IServiceCollection services)
8281
{
83-
services.AddImageSharp(
84-
options =>
85-
{
86-
options.Configuration = Configuration.Default;
87-
options.BrowserMaxAge = TimeSpan.FromDays(7);
88-
options.CacheMaxAge = TimeSpan.FromDays(365);
89-
options.CacheHashLength = 8;
90-
options.OnParseCommandsAsync = _ => Task.CompletedTask;
91-
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
92-
options.OnProcessedAsync = _ => Task.CompletedTask;
93-
options.OnPrepareResponseAsync = _ => Task.CompletedTask;
94-
});
82+
services.AddImageSharp(options =>
83+
{
84+
options.Configuration = Configuration.Default;
85+
options.BrowserMaxAge = TimeSpan.FromDays(7);
86+
options.CacheMaxAge = TimeSpan.FromDays(365);
87+
options.CacheHashLength = 8;
88+
options.OnParseCommandsAsync = _ => Task.CompletedTask;
89+
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
90+
options.OnProcessedAsync = _ => Task.CompletedTask;
91+
options.OnPrepareResponseAsync = _ => Task.CompletedTask;
92+
});
9593
}
9694

9795
private void ConfigureCustomServicesAndDefaultOptions(IServiceCollection services)
@@ -103,30 +101,23 @@ private void ConfigureCustomServicesAndDefaultOptions(IServiceCollection service
103101

104102
private void ConfigureCustomServicesAndCustomOptions(IServiceCollection services)
105103
{
106-
services.AddImageSharp(
107-
options =>
108-
{
109-
options.Configuration = Configuration.Default;
110-
options.BrowserMaxAge = TimeSpan.FromDays(7);
111-
options.CacheMaxAge = TimeSpan.FromDays(365);
112-
options.CacheHashLength = 8;
113-
options.OnParseCommandsAsync = _ => Task.CompletedTask;
114-
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
115-
options.OnProcessedAsync = _ => Task.CompletedTask;
116-
options.OnPrepareResponseAsync = _ => Task.CompletedTask;
117-
})
104+
services.AddImageSharp(options =>
105+
{
106+
options.Configuration = Configuration.Default;
107+
options.BrowserMaxAge = TimeSpan.FromDays(7);
108+
options.CacheMaxAge = TimeSpan.FromDays(365);
109+
options.CacheHashLength = 8;
110+
options.OnParseCommandsAsync = _ => Task.CompletedTask;
111+
options.OnBeforeSaveAsync = _ => Task.CompletedTask;
112+
options.OnProcessedAsync = _ => Task.CompletedTask;
113+
options.OnPrepareResponseAsync = _ => Task.CompletedTask;
114+
})
118115
.SetRequestParser<QueryCollectionRequestParser>()
119116
.Configure<PhysicalFileSystemCacheOptions>(options =>
120117
{
121118
options.CacheFolder = "different-cache";
122119
})
123-
.SetCache(provider =>
124-
{
125-
return new PhysicalFileSystemCache(
126-
provider.GetRequiredService<IOptions<PhysicalFileSystemCacheOptions>>(),
127-
provider.GetRequiredService<IWebHostEnvironment>(),
128-
provider.GetRequiredService<FormatUtilities>());
129-
})
120+
.SetCache<PhysicalFileSystemCache>()
130121
.SetCacheKey<UriRelativeLowerInvariantCacheKey>()
131122
.SetCacheHash<SHA256CacheHash>()
132123
.ClearProviders()

src/Directory.Build.targets

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<PackageReference Update="SixLabors.ImageSharp" Version="2.0.0" />
2525
</ItemGroup>
2626

27-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
27+
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp2.1'">
2828
<FrameworkReference Update="Microsoft.AspNetCore.App" />
2929
</ItemGroup>
3030

@@ -35,6 +35,5 @@
3535
<PackageReference Update="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
3636
<PackageReference Update="Microsoft.Extensions.Caching.Abstractions" Version="2.2.0" />
3737
<PackageReference Update="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
38-
<PackageReference Update="Microsoft.Extensions.FileProviders.Physical" Version="2.2.0"/>
3938
</ItemGroup>
4039
</Project>

src/ImageSharp.Web.Providers.AWS/ImageSharp.Web.Providers.AWS.csproj

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@
1313
<Description>A provider for resolving and caching images via AWS S3 Storage.</Description>
1414
</PropertyGroup>
1515

16-
<PropertyGroup>
17-
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
18-
</PropertyGroup>
16+
<Choose>
17+
<When Condition="$(SIXLABORS_TESTING) == true">
18+
<PropertyGroup>
19+
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
20+
</PropertyGroup>
21+
</When>
22+
<Otherwise>
23+
<PropertyGroup>
24+
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
25+
</PropertyGroup>
26+
</Otherwise>
27+
</Choose>
1928

2029
<ItemGroup>
2130
<None Include="..\..\shared-infrastructure\branding\icons\imagesharp.web\sixlabors.imagesharp.web.128.png" Pack="true" PackagePath="" />

src/ImageSharp.Web.Providers.Azure/ImageSharp.Web.Providers.Azure.csproj

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,25 @@
1111
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
1212
<PackageTags>Image Middleware Resize Crop Gif Jpg Jpeg Bitmap Png Azure</PackageTags>
1313
<Description>A provider for resolving and caching images via Azure Blob Storage.</Description>
14-
</PropertyGroup>
15-
16-
<PropertyGroup>
17-
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
1814
</PropertyGroup>
1915

16+
<Choose>
17+
<When Condition="$(SIXLABORS_TESTING) == true">
18+
<PropertyGroup>
19+
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
20+
</PropertyGroup>
21+
</When>
22+
<Otherwise>
23+
<PropertyGroup>
24+
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1</TargetFrameworks>
25+
</PropertyGroup>
26+
</Otherwise>
27+
</Choose>
28+
2029
<ItemGroup>
2130
<None Include="..\..\shared-infrastructure\branding\icons\imagesharp.web\sixlabors.imagesharp.web.128.png" Pack="true" PackagePath="" />
2231
</ItemGroup>
23-
32+
2433
<ItemGroup>
2534
<PackageReference Include="Azure.Storage.Blobs" />
2635
</ItemGroup>

src/ImageSharp.Web/Caching/PhysicalFileSystemCache.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Runtime.InteropServices;
88
using System.Threading.Tasks;
99
using Microsoft.AspNetCore.Hosting;
10-
using Microsoft.Extensions.FileProviders;
1110
using Microsoft.Extensions.Options;
1211
using SixLabors.ImageSharp.Web.Resolvers;
1312

@@ -28,11 +27,6 @@ public class PhysicalFileSystemCache : IImageCache
2827
/// </summary>
2928
private readonly int cacheFolderDepth;
3029

31-
/// <summary>
32-
/// The file provider abstraction.
33-
/// </summary>
34-
private readonly IFileProvider fileProvider;
35-
3630
/// <summary>
3731
/// Contains various format helper methods based on the current configuration.
3832
/// </summary>
@@ -53,19 +47,11 @@ public PhysicalFileSystemCache(
5347
#endif
5448
FormatUtilities formatUtilities)
5549
{
56-
Guard.NotNull(environment, nameof(environment));
5750
Guard.NotNull(options, nameof(options));
58-
Guard.NotNullOrWhiteSpace(environment.WebRootPath, nameof(environment.WebRootPath));
59-
60-
// Allow configuration of the cache without having to register everything
61-
PhysicalFileSystemCacheOptions cacheOptions = options != null ? options.Value : new();
62-
this.cacheRootPath = GetCacheRoot(cacheOptions, environment.WebRootPath, environment.ContentRootPath);
63-
this.cacheFolderDepth = (int)cacheOptions.CacheFolderDepth;
64-
65-
// Ensure cache directory is created before initializing the file provider
66-
Directory.CreateDirectory(this.cacheRootPath);
51+
Guard.NotNull(environment, nameof(environment));
6752

68-
this.fileProvider = new PhysicalFileProvider(this.cacheRootPath);
53+
this.cacheRootPath = GetCacheRoot(options.Value, environment.WebRootPath, environment.ContentRootPath);
54+
this.cacheFolderDepth = (int)options.Value.CacheFolderDepth;
6955
this.formatUtilities = formatUtilities;
7056
}
7157

@@ -78,21 +64,29 @@ public PhysicalFileSystemCache(
7864
/// <returns><see cref="string"/> representing the fully qualified cache root path.</returns>
7965
internal static string GetCacheRoot(PhysicalFileSystemCacheOptions cacheOptions, string webRootPath, string contentRootPath)
8066
{
81-
string cacheRoot = string.IsNullOrWhiteSpace(cacheOptions.CacheRootPath)
82-
? webRootPath
83-
: cacheOptions.CacheRootPath;
67+
string cacheRootPath = cacheOptions.CacheRootPath ?? webRootPath;
68+
if (string.IsNullOrEmpty(cacheRootPath))
69+
{
70+
throw new InvalidOperationException("The cache root path can't be determined, make sure it's explicitly configured or the webroot is set.");
71+
}
72+
73+
if (!Path.IsPathFullyQualified(cacheRootPath))
74+
{
75+
// Ensure this is an absolute path (resolved to the content root path)
76+
cacheRootPath = Path.GetFullPath(cacheRootPath, contentRootPath);
77+
}
8478

85-
return Path.IsPathFullyQualified(cacheRoot)
86-
? Path.Combine(cacheRoot, cacheOptions.CacheFolder)
87-
: Path.GetFullPath(Path.Combine(cacheRoot, cacheOptions.CacheFolder), contentRootPath);
79+
string cacheFolderPath = Path.Combine(cacheRootPath, cacheOptions.CacheFolder);
80+
81+
return PathUtils.EnsureTrailingSlash(cacheFolderPath);
8882
}
8983

9084
/// <inheritdoc/>
9185
public Task<IImageCacheResolver> GetAsync(string key)
9286
{
9387
string path = ToFilePath(key, this.cacheFolderDepth);
9488

95-
IFileInfo metaFileInfo = this.fileProvider.GetFileInfo(this.ToMetaDataFilePath(path));
89+
var metaFileInfo = new FileInfo(this.ToMetaDataFilePath(path));
9690
if (!metaFileInfo.Exists)
9791
{
9892
return Task.FromResult<IImageCacheResolver>(null);
@@ -110,7 +104,10 @@ public async Task SetAsync(string key, Stream stream, ImageCacheMetadata metadat
110104
string directory = Path.GetDirectoryName(path);
111105

112106
// Ensure cache directory is created before creating files
113-
Directory.CreateDirectory(directory);
107+
if (!Directory.Exists(directory))
108+
{
109+
Directory.CreateDirectory(directory);
110+
}
114111

115112
using (FileStream fileStream = File.Create(imagePath))
116113
{

src/ImageSharp.Web/Caching/PhysicalFileSystemCacheOptions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ namespace SixLabors.ImageSharp.Web.Caching
88
/// </summary>
99
public class PhysicalFileSystemCacheOptions
1010
{
11-
/// <summary>
12-
/// Gets or sets the cache folder name.
13-
/// </summary>
14-
public string CacheFolder { get; set; } = "is-cache";
15-
16-
/// <summary>
17-
/// Gets or sets the depth of the nested cache folders structure to store the images. Defaults to 8.
18-
/// </summary>
19-
public uint CacheFolderDepth { get; set; } = 8;
20-
2111
/// <summary>
2212
/// Gets or sets the optional cache root folder path.
2313
/// <para>
@@ -31,5 +21,15 @@ public class PhysicalFileSystemCacheOptions
3121
/// </para>
3222
/// </summary>
3323
public string CacheRootPath { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the cache folder name.
27+
/// </summary>
28+
public string CacheFolder { get; set; } = "is-cache";
29+
30+
/// <summary>
31+
/// Gets or sets the depth of the nested cache folders structure to store the images. Defaults to 8.
32+
/// </summary>
33+
public uint CacheFolderDepth { get; set; } = 8;
3434
}
3535
}

0 commit comments

Comments
 (0)