Imaging settings

This commit is contained in:
Bjarke Berg
2020-03-17 17:56:00 +01:00
parent 0efc335e4f
commit 3e75c889ab
8 changed files with 84 additions and 15 deletions

View File

@@ -43,6 +43,7 @@ namespace Umbraco.Configuration
configs.Add<IGlobalSettings>(() => new GlobalSettings(_configuration));
configs.Add<IConnectionStrings>(() => new ConnectionStrings(_configuration));
configs.Add<IMachineKeyConfig>(() => new MachineKeyConfig(_configuration));
configs.Add<IImagingSettings>(() => new ImagingSettings(_configuration));
return configs;
}

View File

@@ -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");
}
}

View File

@@ -10,6 +10,9 @@ namespace Umbraco.Core
/// </summary>
public static class ConfigsExtensions
{
public static IImagingSettings Imaging(this Configs configs)
=> configs.GetConfig<IImagingSettings>();
public static IGlobalSettings Global(this Configs configs)
=> configs.GetConfig<IGlobalSettings>();

View File

@@ -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; }
}
}

View File

@@ -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<IConfiguration>();
var configsFactory = new AspNetCoreConfigsFactory(configuration);
var configs = configsFactory.Create();
services.AddSingleton(configs);
return services;
}
public static IServiceCollection AddUmbracoBackOffice(this IServiceCollection services)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
@@ -26,15 +39,13 @@ namespace Umbraco.Web.BackOffice.AspNetCore
var httpContextAccessor = serviceProvider.GetService<IHttpContextAccessor>();
var webHostEnvironment = serviceProvider.GetService<IWebHostEnvironment>();
var hostApplicationLifetime = serviceProvider.GetService<IHostApplicationLifetime>();
var configuration = serviceProvider.GetService<IConfiguration>();
var configsFactory = new AspNetCoreConfigsFactory(configuration);
var configs = serviceProvider.GetService<Configs>();
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();

View File

@@ -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();
}

View File

@@ -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": [
{

View File

@@ -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<Configs>();
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<PhysicalFileSystemCacheOptions>(options =>
{
options.CacheFolder = "../app_data/cache";
options.CacheFolder = imagingSettings.CacheFolder;
})
.SetCache<PhysicalFileSystemCache>()
.SetCacheHash<CacheHash>()