From b580dbcc80ba48ad58d0e5cb4e10e2c87be0d04f Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Fri, 22 Oct 2021 20:11:11 +0800 Subject: [PATCH] feat(oss): added the feature switch for accessing public files --- .../Abp/OssManagement/PublicFileAppService.cs | 43 ++++++++++++++++++- ...pOssManagementFeatureDefinitionProvider.cs | 7 +++ .../Features/AbpOssManagementFeatureNames.cs | 5 ++- .../Localization/Resources/en.json | 6 ++- .../Localization/Resources/zh-Hans.json | 2 + 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/PublicFileAppService.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/PublicFileAppService.cs index d92642ede..76f063a39 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/PublicFileAppService.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/PublicFileAppService.cs @@ -1,4 +1,10 @@ -namespace LINGYUN.Abp.OssManagement +using LINGYUN.Abp.Features.LimitValidation; +using LINGYUN.Abp.OssManagement.Features; +using System.IO; +using System.Threading.Tasks; +using Volo.Abp.Features; + +namespace LINGYUN.Abp.OssManagement { public class PublicFileAppService : FileAppServiceBase, IPublicFileAppService { @@ -10,6 +16,41 @@ { } + [RequiresFeature( + AbpOssManagementFeatureNames.PublicAccess, + AbpOssManagementFeatureNames.OssObject.UploadFile, + RequiresAll = true)] + public override async Task UploadAsync(UploadFileChunkInput input) + { + await base.UploadAsync(input); + } + + [RequiresFeature( + AbpOssManagementFeatureNames.PublicAccess, + AbpOssManagementFeatureNames.OssObject.UploadFile, + RequiresAll = true)] + [RequiresLimitFeature( + AbpOssManagementFeatureNames.OssObject.UploadLimit, + AbpOssManagementFeatureNames.OssObject.UploadInterval, + LimitPolicy.Month)] + public override async Task UploadAsync(UploadFileInput input) + { + return await base.UploadAsync(input); + } + + [RequiresFeature( + AbpOssManagementFeatureNames.PublicAccess, + AbpOssManagementFeatureNames.OssObject.DownloadFile, + RequiresAll = true)] + [RequiresLimitFeature( + AbpOssManagementFeatureNames.OssObject.DownloadLimit, + AbpOssManagementFeatureNames.OssObject.DownloadInterval, + LimitPolicy.Month)] + public override async Task GetAsync(GetPublicFileInput input) + { + return await base.GetAsync(input); + } + protected override string GetCurrentBucket() { return "public"; diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Features/AbpOssManagementFeatureDefinitionProvider.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Features/AbpOssManagementFeatureDefinitionProvider.cs index df5aa95b1..11c534793 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Features/AbpOssManagementFeatureDefinitionProvider.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Features/AbpOssManagementFeatureDefinitionProvider.cs @@ -13,6 +13,13 @@ namespace LINGYUN.Abp.OssManagement.Features name: AbpOssManagementFeatureNames.GroupName, displayName: L("Features:OssManagement")); + featureGroup.AddFeature( + name: AbpOssManagementFeatureNames.PublicAccess, + defaultValue: false.ToString(), + displayName: L("Features:DisplayName:PublicAccess"), + description: L("Features:Description:PublicAccess"), + valueType: new ToggleStringValueType(new BooleanValueValidator())); + var ossFeature = featureGroup.AddFeature( name: AbpOssManagementFeatureNames.OssObject.Default, defaultValue: true.ToString(), diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Features/AbpOssManagementFeatureNames.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Features/AbpOssManagementFeatureNames.cs index 4d0ee0b35..00cb81f3f 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Features/AbpOssManagementFeatureNames.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Features/AbpOssManagementFeatureNames.cs @@ -3,7 +3,10 @@ public class AbpOssManagementFeatureNames { public const string GroupName = "AbpOssManagement"; - + /// + /// 是否运行未经授权的用户访问公共目录 + /// + public const string PublicAccess = GroupName + ".PublicAccess"; public class OssObject { diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/en.json b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/en.json index 58d760a60..2fcabc326 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/en.json +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/en.json @@ -33,8 +33,10 @@ "Description:FileLimitLength": "Limit size of uploaded file in MB", "DisplayName:AllowFileExtensions": "File extension", "Description:AllowFileExtensions": "List of allowed extensions to upload files, with multiple extensions separated by, don't need a notation", - "Features:FileManagement": "File management", - "Features:DisplayName:FileSystem": "File system", + "Features:OssManagement": "Oss management", + "Features:DisplayName:PublicAccess": "Public Access", + "Features:Description:PublicAccess": "Whether to allow unauthorized users to access public directories", + "Features:DisplayName:OssObject": "Oss Objects", "Features:DisplayName:DownloadFile": "Download file", "Features:Description:DownloadFile": "Whether to allow users to download files", "Features:DisplayName:DownloadLimit": "Limit Of Downloads", diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/zh-Hans.json b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/zh-Hans.json index 262a849a8..e2c9c1b76 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Domain.Shared/LINGYUN/Abp/OssManagement/Localization/Resources/zh-Hans.json @@ -34,6 +34,8 @@ "DisplayName:AllowFileExtensions": "文件扩展名", "Description:AllowFileExtensions": "允许的上传文件扩展名列表,多个扩展名以,分隔,无需输入.符号", "Features:OssManagement": "对象存储", + "Features:DisplayName:PublicAccess": "公共访问", + "Features:Description:PublicAccess": "是否允许未经授权的用户访问公共目录", "Features:DisplayName:OssObject": "Oss管理", "Features:DisplayName:DownloadFile": "下载文件", "Features:Description:DownloadFile": "是否允许用户下载文件",