-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Azure and AWS-specific Image Caches of ImageSharp (#15028)
Co-authored-by: Mike Alhayek <[email protected]>
- Loading branch information
1 parent
08a6771
commit 18efbf2
Showing
41 changed files
with
994 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/AmazonS3Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace OrchardCore.Media.AmazonS3; | ||
|
||
internal static class AmazonS3Constants | ||
{ | ||
internal static class ValidationMessages | ||
{ | ||
public const string BucketNameIsEmpty = "BucketName is required attribute for S3 storage."; | ||
public const string RegionAndServiceUrlAreEmpty = "Region or ServiceURL is a required attribute for S3 storage."; | ||
} | ||
|
||
internal static class AwsCredentialParamNames | ||
{ | ||
public const string SecretKey = "SecretKey"; | ||
public const string AccessKey = "AccessKey"; | ||
} | ||
|
||
internal static class ConfigSections | ||
{ | ||
public const string AmazonS3 = "OrchardCore_Media_AmazonS3"; | ||
public const string AmazonS3ImageSharpCache = "OrchardCore_Media_AmazonS3_ImageSharp_Cache"; | ||
} | ||
} |
80 changes: 0 additions & 80 deletions
80
src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/AwsStorageOptionsConfiguration.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Constants.cs
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Helpers/OptionsFluidParserHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Fluid; | ||
using OrchardCore.Environment.Shell; | ||
|
||
namespace OrchardCore.Media.AmazonS3.Helpers; | ||
|
||
// This is almost the same as in OrchardCore.Media.Azure but there isn't really a good common place for it. | ||
internal sealed class OptionsFluidParserHelper<TOptions> where TOptions : class | ||
{ | ||
// Local instance since it can be discarded once the startup is over. | ||
private readonly FluidParser _fluidParser = new(); | ||
private readonly ShellSettings _shellSettings; | ||
|
||
private TemplateContext _templateContext; | ||
|
||
public OptionsFluidParserHelper(ShellSettings shellSettings) | ||
{ | ||
_shellSettings = shellSettings; | ||
} | ||
|
||
public string ParseAndFormat(string template) | ||
{ | ||
var templateContext = GetTemplateContext(); | ||
|
||
// Use Fluid directly as this is transient and cannot invoke _liquidTemplateManager. | ||
var parsedTemplate = _fluidParser.Parse(template); | ||
return parsedTemplate.Render(templateContext, NullEncoder.Default) | ||
.Replace("\r", string.Empty) | ||
.Replace("\n", string.Empty) | ||
.Trim(); | ||
} | ||
|
||
private TemplateContext GetTemplateContext() | ||
{ | ||
if (_templateContext == null) | ||
{ | ||
var templateOptions = new TemplateOptions(); | ||
_templateContext = new TemplateContext(templateOptions); | ||
templateOptions.MemberAccessStrategy.Register<ShellSettings>(); | ||
templateOptions.MemberAccessStrategy.Register<TOptions>(); | ||
_templateContext.SetValue("ShellSettings", _shellSettings); | ||
} | ||
|
||
return _templateContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...Core.Modules/OrchardCore.Media.AmazonS3/Services/AWSS3StorageCacheOptionsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Microsoft.Extensions.Options; | ||
using OrchardCore.FileStorage.AmazonS3; | ||
using SixLabors.ImageSharp.Web.Caching.AWS; | ||
|
||
namespace OrchardCore.Media.AmazonS3.Services; | ||
|
||
// Configuration for ImageSharp's own configuration object. We just pass the settings from the Orchard Core | ||
// configuration. | ||
internal sealed class AWSS3StorageCacheOptionsConfiguration : IConfigureOptions<AWSS3StorageCacheOptions> | ||
{ | ||
private readonly AwsImageSharpImageCacheOptions _options; | ||
|
||
public AWSS3StorageCacheOptionsConfiguration(IOptions<AwsImageSharpImageCacheOptions> options) | ||
{ | ||
_options = options.Value; | ||
} | ||
|
||
public void Configure(AWSS3StorageCacheOptions options) | ||
{ | ||
var credentials = _options.AwsOptions.Credentials.GetCredentials(); | ||
|
||
// Only Endpoint or Region is necessary. | ||
options.Endpoint = _options.AwsOptions.DefaultClientConfig.ServiceURL; | ||
options.Region = _options.AwsOptions.Region?.SystemName; | ||
options.BucketName = _options.BucketName; | ||
options.AccessKey = credentials.AccessKey; | ||
options.AccessSecret = credentials.SecretKey; | ||
options.CacheFolder = _options.BasePath; | ||
} | ||
} |
Oops, something went wrong.