diff --git a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs index 869ead9b09..b4907c7fa3 100644 --- a/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs +++ b/src/Umbraco.Configuration/AspNetCoreConfigsFactory.cs @@ -43,6 +43,7 @@ namespace Umbraco.Configuration configs.Add(() => new GlobalSettings(_configuration)); configs.Add(() => new ConnectionStrings(_configuration)); configs.Add(() => new MachineKeyConfig(_configuration)); + configs.Add(() => new ImagingSettings(_configuration)); return configs; } diff --git a/src/Umbraco.Configuration/Models/ImagingSettings.cs b/src/Umbraco.Configuration/Models/ImagingSettings.cs new file mode 100644 index 0000000000..cea8905c56 --- /dev/null +++ b/src/Umbraco.Configuration/Models/ImagingSettings.cs @@ -0,0 +1,22 @@ +using Microsoft.Extensions.Configuration; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration.Models +{ + public class ImagingSettings :IImagingSettings + { + private readonly IConfiguration _configuration; + + public ImagingSettings(IConfiguration configuration) + { + _configuration = configuration; + } + + public int MaxBrowserCacheDays => _configuration.GetValue("Umbraco:CMS:Imaging:Cache:MaxBrowserCacheDays", 7); + public int MaxCacheDays => _configuration.GetValue("Umbraco:CMS:Imaging:Cache:MaxCacheDays", 365); + public uint CachedNameLength => _configuration.GetValue("Umbraco:CMS:Imaging:Cache:CachedNameLength", (uint)8); + public int MaxResizeWidth => _configuration.GetValue("Umbraco:CMS:Imaging:Resize:MaxWidth", 5000); + public int MaxResizeHeight => _configuration.GetValue("Umbraco:CMS:Imaging:Resize:MaxHeight", 5000); + public string CacheFolder => _configuration.GetValue("Umbraco:CMS:Imaging:Cache:Folder", "../App_Data/Cache"); + } +} diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs index 2157978dc6..f9ea352399 100644 --- a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs @@ -10,6 +10,9 @@ namespace Umbraco.Core /// public static class ConfigsExtensions { + + public static IImagingSettings Imaging(this Configs configs) + => configs.GetConfig(); public static IGlobalSettings Global(this Configs configs) => configs.GetConfig(); diff --git a/src/Umbraco.Core/Configuration/IImagingSettings.cs b/src/Umbraco.Core/Configuration/IImagingSettings.cs new file mode 100644 index 0000000000..13e1b30389 --- /dev/null +++ b/src/Umbraco.Core/Configuration/IImagingSettings.cs @@ -0,0 +1,12 @@ +namespace Umbraco.Core.Configuration +{ + public interface IImagingSettings + { + int MaxBrowserCacheDays { get;} + int MaxCacheDays { get; } + uint CachedNameLength { get; } + int MaxResizeWidth { get; } + int MaxResizeHeight { get; } + string CacheFolder { get; } + } +} diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs index f54e8501db..d06039f3f5 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs @@ -17,6 +17,19 @@ namespace Umbraco.Web.BackOffice.AspNetCore { public static class UmbracoBackOfficeServiceCollectionExtensions { + public static IServiceCollection AddUmbracoConfiguration(this IServiceCollection services) + { + var serviceProvider = services.BuildServiceProvider(); + var configuration = serviceProvider.GetService(); + var configsFactory = new AspNetCoreConfigsFactory(configuration); + + var configs = configsFactory.Create(); + + services.AddSingleton(configs); + + return services; + } + public static IServiceCollection AddUmbracoBackOffice(this IServiceCollection services) { services.AddSingleton(); @@ -26,15 +39,13 @@ namespace Umbraco.Web.BackOffice.AspNetCore var httpContextAccessor = serviceProvider.GetService(); var webHostEnvironment = serviceProvider.GetService(); var hostApplicationLifetime = serviceProvider.GetService(); - var configuration = serviceProvider.GetService(); - - var configsFactory = new AspNetCoreConfigsFactory(configuration); + var configs = serviceProvider.GetService(); services.CreateCompositionRoot( httpContextAccessor, webHostEnvironment, hostApplicationLifetime, - configsFactory); + configs); return services; } @@ -45,10 +56,8 @@ namespace Umbraco.Web.BackOffice.AspNetCore IHttpContextAccessor httpContextAccessor, IWebHostEnvironment webHostEnvironment, IHostApplicationLifetime hostApplicationLifetime, - IConfigsFactory configsFactory) + Configs configs) { - var configs = configsFactory.Create(); - var hostingSettings = configs.Hosting(); var coreDebug = configs.CoreDebug(); var globalSettings = configs.Global(); diff --git a/src/Umbraco.Web.UI.NetCore/Startup.cs b/src/Umbraco.Web.UI.NetCore/Startup.cs index fb9ab608a3..9ef4985aea 100644 --- a/src/Umbraco.Web.UI.NetCore/Startup.cs +++ b/src/Umbraco.Web.UI.NetCore/Startup.cs @@ -21,6 +21,7 @@ namespace Umbraco.Web.UI.BackOffice // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.AddUmbracoConfiguration(); services.AddUmbracoWebsite(); services.AddUmbracoBackOffice(); } diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index 6880b3fe89..a1cbdba994 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -9,6 +9,20 @@ "AllowedHosts": "*", "Umbraco": { "CMS": { + "Imaging": { + + "Resize": { + "MaxWidth": 5000, + "MaxHeight": 5000 + }, + "CacheFolder" : "../App_Data/Cache", + "Cache": { + "Folder": "../App_Data/Cache", + "MaxBrowserCacheDays": 7, + "MaxCacheDays": 365, + "CachedNameLength": 8 + } + }, "HealthChecks": { "DisabledChecks": [ { diff --git a/src/Umbraco.Web.Website/AspNetCore/UmbracoWebsiteServiceCollectionExtensions.cs b/src/Umbraco.Web.Website/AspNetCore/UmbracoWebsiteServiceCollectionExtensions.cs index aeae455294..f7a198bc3b 100644 --- a/src/Umbraco.Web.Website/AspNetCore/UmbracoWebsiteServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Website/AspNetCore/UmbracoWebsiteServiceCollectionExtensions.cs @@ -10,6 +10,8 @@ using SixLabors.ImageSharp.Web.Middleware; using SixLabors.ImageSharp.Web.Processors; using SixLabors.ImageSharp.Web.Providers; using SixLabors.Memory; +using Umbraco.Core; +using Umbraco.Core.Configuration; namespace Umbraco.Web.Website.AspNetCore { @@ -17,24 +19,29 @@ namespace Umbraco.Web.Website.AspNetCore { public static IServiceCollection AddUmbracoWebsite(this IServiceCollection services) { - services.AddUmbracoImageSharp(); + var serviceProvider = services.BuildServiceProvider(); + var configs = serviceProvider.GetService(); + var imagingSettings = configs.Imaging(); + services.AddUmbracoImageSharp(imagingSettings); return services; } - public static IServiceCollection AddUmbracoImageSharp(this IServiceCollection services) + public static IServiceCollection AddUmbracoImageSharp(this IServiceCollection services, IImagingSettings imagingSettings) { + + services.AddImageSharpCore( options => { options.Configuration = SixLabors.ImageSharp.Configuration.Default; - options.MaxBrowserCacheDays = 7; - options.MaxCacheDays = 365; - options.CachedNameLength = 8; + options.MaxBrowserCacheDays = imagingSettings.MaxBrowserCacheDays; + options.MaxCacheDays = imagingSettings.MaxCacheDays; + options.CachedNameLength = imagingSettings.CachedNameLength; options.OnParseCommands = context => { - RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Width, 5000); - RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Height, 5000); + RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Width, imagingSettings.MaxResizeWidth); + RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Height, imagingSettings.MaxResizeHeight); }; options.OnBeforeSave = _ => { }; options.OnProcessed = _ => { }; @@ -44,7 +51,7 @@ namespace Umbraco.Web.Website.AspNetCore .SetMemoryAllocator(provider => ArrayPoolMemoryAllocator.CreateWithMinimalPooling()) .Configure(options => { - options.CacheFolder = "../app_data/cache"; + options.CacheFolder = imagingSettings.CacheFolder; }) .SetCache() .SetCacheHash()