diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs index 88ee7d8c..2779952d 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Extensions/MediaStorageManagementExtensions.cs @@ -9,15 +9,15 @@ public static class MediaStorageManagementExtensions { public static void SetMediaStorageManagementOptionsForUITest( this OrchardCoreUITestExecutorConfiguration configuration, - long maximumSpace) + long maximumStorageQuotaBytes) { configuration.OrchardCoreConfiguration.BeforeAppStart += (_, argumentsBuilder) => { argumentsBuilder .AddWithValue( - "OrchardCore:Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpace", - maximumSpace); + "OrchardCore:Lombiq_Hosting_Tenants_MediaStorageManagement:MaximumStorageQuotaBytes", + maximumStorageQuotaBytes); return Task.CompletedTask; }; diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Constants/MediaStorageManagementOptionsConstants.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Constants/MediaStorageManagementOptionsConstants.cs index f649fd6f..0331dc71 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Constants/MediaStorageManagementOptionsConstants.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Constants/MediaStorageManagementOptionsConstants.cs @@ -1,9 +1,9 @@ -namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Constants; +namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Constants; public static class MediaStorageManagementOptionsConstants { /// - /// Default MaximumStorageQuota in bytes representing 1GB. + /// Default maximum storage quota in bytes representing 1GB. /// - public const long MaximumStorageQuota = 1_073_741_824; + public const long MaximumStorageQuotaBytes = 1_073_741_824; } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs index 2c79e219..42cf1781 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/MediaStorageQuotaActionFilter.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.MediaStorageManagement.Service; +using Lombiq.Hosting.Tenants.MediaStorageManagement.Service; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.DependencyInjection; @@ -16,7 +16,7 @@ public async Task OnAuthorizationAsync(AuthorizationFilterContext context) .HttpContext .RequestServices .GetRequiredService() - .GetRemainingMediaSpaceQuotaLeftAsync(); + .GetRemainingMediaStorageQuotaBytesAsync(); var formOptions = new FormOptions { diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs index e4571ab9..dd200e84 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs @@ -45,10 +45,10 @@ actionRouteValue is nameof(AdminController.Index) && { var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Footer"]; - var maximumSpace = _mediaStorageQuotaService.MaxSpaceForTenantInMegabytes(); + var maximumStorageQuotaMegabytes = _mediaStorageQuotaService.GetMaxStorageQuotaMegabytes(); await contentZone.AddAsync(await _shapeFactory.CreateAsync( "UploadFileSize", - viewModel => viewModel.MaximumSpace = maximumSpace)); + viewModel => viewModel.MaximumStorageQuotaMegabytes = maximumStorageQuotaMegabytes)); } await next(); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md b/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md index d10e1b0f..5cdc7ab0 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Readme.md @@ -21,9 +21,7 @@ With this module, you can specify how much space would you like to limit each te ```json "OrchardCore": { "Lombiq_Hosting_Tenants_MediaStorageManagement": { - "Media_Storage_Management_Options": { - "MaximumSpace": 2147483648 - } + "MaximumStorageQuotaBytes": 2147483648 } } ``` @@ -34,9 +32,7 @@ Tenant based configuration can be defined as the following, for more details rea "OrchardCore": { "TenantName": { "Lombiq_Hosting_Tenants_MediaStorageManagement": { - "Media_Storage_Management_Options": { - "MaximumSpace": 2147483648 - } + "MaximumStorageQuotaBytes": 2147483648 } } } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs index 2579af71..a092c35e 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs @@ -1,4 +1,4 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Service; @@ -8,17 +8,22 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Service; public interface IMediaStorageQuotaService { /// - /// Returns remaining quota space left in bytes. It is always a non-negative number, meaning the minimum value is 0. + /// Returns the remaining storage space left from the quota in bytes. It is always a non-negative number, meaning + /// the minimum value is 0. /// - Task GetRemainingMediaSpaceQuotaLeftAsync(); + Task GetRemainingMediaStorageQuotaBytesAsync(); /// - /// Returns the maximum quota space in bytes. + /// Returns the maximum storage space form the quota in bytes. /// - long MaxSpaceForTenantInBytes(); + long GetMaxStorageQuotaBytes(); +} +public static class MediaStorageQuotaServiceExtensions +{ /// - /// Returns the maximum quota space in Megabytes. + /// Returns the maximum storage quota space in Megabytes. /// - float MaxSpaceForTenantInMegabytes(); + public static float GetMaxStorageQuotaMegabytes(this IMediaStorageQuotaService mediaStorageQuotaService) => + mediaStorageQuotaService.GetMaxStorageQuotaBytes() / 1024f / 1024f; } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs index 53127025..06cbd9c7 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.MediaStorageManagement.Settings; +using Lombiq.Hosting.Tenants.MediaStorageManagement.Settings; using Microsoft.Extensions.Options; using OrchardCore.Media; using System.Linq; @@ -19,18 +19,16 @@ public MediaStorageQuotaService( _mediaFileStore = mediaFileStore; } - public async Task GetRemainingMediaSpaceQuotaLeftAsync() + public async Task GetRemainingMediaStorageQuotaBytesAsync() { var directoryContent = _mediaFileStore.GetDirectoryContentAsync(includeSubDirectories: true); var listed = await directoryContent.ToListAsync(); - var sumSize = listed.Where(item => item.Length > 0).Sum(item => item.Length); - var remainingSpace = MaxSpaceForTenantInBytes() - sumSize; + var sumBytes = listed.Where(item => item.Length > 0).Sum(item => item.Length); + var remainingStorageQuotaBytes = GetMaxStorageQuotaBytes() - sumBytes; - return remainingSpace < 0 ? 0 : remainingSpace; + return remainingStorageQuotaBytes < 0 ? 0 : remainingStorageQuotaBytes; } - public long MaxSpaceForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuota; - - public float MaxSpaceForTenantInMegabytes() => MaxSpaceForTenantInBytes() / 1024f / 1024f; + public long GetMaxStorageQuotaBytes() => _mediaStorageManagementOptions.MaximumStorageQuotaBytes; } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Settings/MediaStorageManagementOptions.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Settings/MediaStorageManagementOptions.cs index fbe068fe..435903d5 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Settings/MediaStorageManagementOptions.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Settings/MediaStorageManagementOptions.cs @@ -1,9 +1,9 @@ -namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Settings; +namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Settings; public class MediaStorageManagementOptions { /// /// Gets or sets the maximum storage quota for a tenant in bytes. Default is 1GB. /// - public long MaximumStorageQuota { get; set; } + public long MaximumStorageQuotaBytes { get; set; } } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs index 830224cb..300b24d8 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs @@ -18,11 +18,13 @@ public class Startup : StartupBase public override void ConfigureServices(IServiceCollection services) { - var maximumStorageQuota = + var maximumStorageQuotaBytes = + _shellConfiguration.GetValue( + "Lombiq_Hosting_Tenants_MediaStorageManagement:MaximumStorageQuotaBytes") ?? _shellConfiguration.GetValue( "Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpace"); services.Configure(options => - options.MaximumStorageQuota = maximumStorageQuota ?? MaximumStorageQuota); + options.MaximumStorageQuotaBytes = maximumStorageQuotaBytes ?? MaximumStorageQuotaBytes); services.AddScoped(); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs index faa0af3b..9d3fd7a2 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/ViewModels/UploadFileSizeViewModel.cs @@ -1,6 +1,6 @@ -namespace Lombiq.Hosting.Tenants.MediaStorageManagement.ViewModels; +namespace Lombiq.Hosting.Tenants.MediaStorageManagement.ViewModels; public class UploadFileSizeViewModel { - public float MaximumSpace { get; set; } + public float MaximumStorageQuotaMegabytes { get; set; } } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml index 21a159ea..2d05c7bf 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Views/UploadFileSize.cshtml @@ -21,7 +21,9 @@ $(function () { return; } model.errorMessage = - @T["You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", Model.MaximumSpace].Json(); + @T[ + "You may only store {0} MB of Media files for your site, and it seems that you’d just go over that. But don’t worry! If you delete some large files, you should be able to upload new ones. Also, you can contact us for a larger quota.", + Model.MaximumStorageQuotaMegabytes].Json(); }); });