From aea1518a14b74921a2f550813d0987702a8af713 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 4 Sep 2023 11:34:32 +0800 Subject: [PATCH] Solve the following problems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、The integrated Volo.Abp.Imaging package has been used to process graphics streams 2、The tenant id is set to global when the file is obtained. The host is supported 3、Version update SixLabors. ImageSharp. Drawing package. --- aspnet-core/Directory.Build.props | 1 + aspnet-core/LINGYUN.MicroService.All.sln | 14 ++++ aspnet-core/NuGet.Config | 7 ++ .../LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj | 2 +- .../OssManagement/GetFileMultiTenancyInput.cs | 27 +++++++ .../Abp/OssManagement/GetPublicFileInput.cs | 9 +-- .../Abp/OssManagement/GetStaticFileInput.cs | 11 +-- .../Features/AbpOssManagementFeatureNames.cs | 2 +- ...OssManagement.FileSystem.ImageSharp.csproj | 2 +- .../ImageSharpFileSystemOssObjectProcesser.cs | 56 +------------- .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++++++++ ...gementFileSystemImagingImageSharpModule.cs | 12 +++ ...ement.FileSystem.Imaging.ImageSharp.csproj | 19 +++++ .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 ++++++++ ...bp.OssManagement.FileSystem.Imaging.csproj | 19 +++++ .../Imaging/AbpImagingProcesserContributor.cs | 75 +++++++++++++++++++ ...AbpOssManagementFileSystemImagingModule.cs | 18 +++++ .../System/ByteExtensions.cs | 31 ++++++++ .../System/StringArrayArgsExtensions.cs | 31 ++++++++ .../OssManagement/PrivateFilesController.cs | 2 +- .../OssManagement/PublicFilesController.cs | 2 +- .../OssManagement/StaticFilesController.cs | 2 +- aspnet-core/modules/oss-management/README.md | 3 + .../templates/content/Directory.Build.props | 40 +++++++--- .../PackageName.CompanyName.ProjectName.sln | 1 + ....CompanyName.ProjectName.DbMigrator.csproj | 1 - .../Program.cs | 4 +- 29 files changed, 368 insertions(+), 89 deletions(-) create mode 100644 aspnet-core/NuGet.Config create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetFileMultiTenancyInput.cs create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/FodyWeavers.xml create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/FodyWeavers.xsd create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/LIINGYUN/Abp/OssManagement/FileSystem/Imaging/ImageSharp/AbpOssManagementFileSystemImagingImageSharpModule.cs create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp.csproj create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/FodyWeavers.xml create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/FodyWeavers.xsd create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN.Abp.OssManagement.FileSystem.Imaging.csproj create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpImagingProcesserContributor.cs create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpOssManagementFileSystemImagingModule.cs create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/System/ByteExtensions.cs create mode 100644 aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/System/StringArrayArgsExtensions.cs diff --git a/aspnet-core/Directory.Build.props b/aspnet-core/Directory.Build.props index dc45008c6..9efa3b881 100644 --- a/aspnet-core/Directory.Build.props +++ b/aspnet-core/Directory.Build.props @@ -32,6 +32,7 @@ 7.0.1 4.0.0 9.0.3 + 1.0.0 5.0.0 6.3.0 7.2.3 diff --git a/aspnet-core/LINGYUN.MicroService.All.sln b/aspnet-core/LINGYUN.MicroService.All.sln index 4f7ed2e39..023038f5f 100644 --- a/aspnet-core/LINGYUN.MicroService.All.sln +++ b/aspnet-core/LINGYUN.MicroService.All.sln @@ -645,6 +645,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cli", "cli", "{59627844-A66 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Cli", "modules\cli\LINGYUN.Abp.Cli\LINGYUN.Abp.Cli.csproj", "{2F49E870-DAE2-4D89-98CA-46BBD91C68E2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging\LINGYUN.Abp.OssManagement.FileSystem.Imaging.csproj", "{6C8489F4-68B5-4CBC-8463-010C71C23245}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp.csproj", "{5177C729-7666-4A6C-9D54-D7E5DEF0E857}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1651,6 +1655,14 @@ Global {2F49E870-DAE2-4D89-98CA-46BBD91C68E2}.Debug|Any CPU.Build.0 = Debug|Any CPU {2F49E870-DAE2-4D89-98CA-46BBD91C68E2}.Release|Any CPU.ActiveCfg = Release|Any CPU {2F49E870-DAE2-4D89-98CA-46BBD91C68E2}.Release|Any CPU.Build.0 = Release|Any CPU + {6C8489F4-68B5-4CBC-8463-010C71C23245}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C8489F4-68B5-4CBC-8463-010C71C23245}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C8489F4-68B5-4CBC-8463-010C71C23245}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C8489F4-68B5-4CBC-8463-010C71C23245}.Release|Any CPU.Build.0 = Release|Any CPU + {5177C729-7666-4A6C-9D54-D7E5DEF0E857}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5177C729-7666-4A6C-9D54-D7E5DEF0E857}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5177C729-7666-4A6C-9D54-D7E5DEF0E857}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5177C729-7666-4A6C-9D54-D7E5DEF0E857}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1963,6 +1975,8 @@ Global {1D420BA6-2155-4E0D-AAAF-EECC0330A38C} = {DD1B10ED-73E2-41BE-928A-46501050FE2A} {59627844-A66A-46AC-B882-E8F302D0EC24} = {C5CAD011-DF84-4914-939C-0C029DCEF26F} {2F49E870-DAE2-4D89-98CA-46BBD91C68E2} = {59627844-A66A-46AC-B882-E8F302D0EC24} + {6C8489F4-68B5-4CBC-8463-010C71C23245} = {B05CB08F-C088-4D6D-97EE-A94A5D1AE4A6} + {5177C729-7666-4A6C-9D54-D7E5DEF0E857} = {B05CB08F-C088-4D6D-97EE-A94A5D1AE4A6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} diff --git a/aspnet-core/NuGet.Config b/aspnet-core/NuGet.Config new file mode 100644 index 000000000..d2149a970 --- /dev/null +++ b/aspnet-core/NuGet.Config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj b/aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj index 0b75adb34..2cc01aa93 100644 --- a/aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj +++ b/aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj @@ -5,7 +5,7 @@ Exe net7.0 - 7.2.1 + 7.3.2 colin Use LINGYUN.MicroService.Templates command line true diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetFileMultiTenancyInput.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetFileMultiTenancyInput.cs new file mode 100644 index 000000000..a49fcc9a8 --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetFileMultiTenancyInput.cs @@ -0,0 +1,27 @@ +using System; +using Volo.Abp.MultiTenancy; + +namespace LINGYUN.Abp.OssManagement; +public abstract class GetFileMultiTenancyInput +{ + /// + /// 解决通过路由传递租户标识时,abp写入cookies + /// + public string TenantId { get; set; } + + public virtual Guid? GetTenantId(ICurrentTenant currentTenant) + { + if (!TenantId.IsNullOrWhiteSpace()) + { + if ("global".Equals(TenantId, StringComparison.InvariantCultureIgnoreCase)) + { + return null; + } + if (Guid.TryParse(TenantId, out var tenantId)) + { + return tenantId; + } + } + return currentTenant.Id; + } +} diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetPublicFileInput.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetPublicFileInput.cs index 296692499..1a2bf31fe 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetPublicFileInput.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetPublicFileInput.cs @@ -1,9 +1,8 @@ -using System; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace LINGYUN.Abp.OssManagement { - public class GetPublicFileInput + public class GetPublicFileInput : GetFileMultiTenancyInput { [Required] public string Name { get; set; } @@ -11,9 +10,5 @@ namespace LINGYUN.Abp.OssManagement public string Path { get; set; } public string Process { get; set; } - /// - /// 解决通过路由传递租户标识时,abp写入cookies - /// - public Guid? TenantId { get; set; } } } diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetStaticFileInput.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetStaticFileInput.cs index 0ab69a4c7..a640e5a66 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetStaticFileInput.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application.Contracts/LINGYUN/Abp/OssManagement/GetStaticFileInput.cs @@ -1,9 +1,8 @@ -using System; -using System.ComponentModel.DataAnnotations; - +using System.ComponentModel.DataAnnotations; + namespace LINGYUN.Abp.OssManagement { - public class GetStaticFileInput + public class GetStaticFileInput : GetFileMultiTenancyInput { [Required] public string Name { get; set; } @@ -13,9 +12,5 @@ namespace LINGYUN.Abp.OssManagement public string Bucket { get; set; } public string Process { get; set; } - /// - /// 解决通过路由传递租户标识时,abp写入cookies - /// - public Guid? TenantId { get; set; } } } 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 8dd16b091..1dbc6829e 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 @@ -4,7 +4,7 @@ { public const string GroupName = "AbpOssManagement"; /// - /// 是否运行未经授权的用户访问公共目录 + /// 是否允许未经授权的用户访问公共目录 /// public const string PublicAccess = GroupName + ".PublicAccess"; diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp.csproj b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp.csproj index 57eee08c8..7f80ebac1 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp.csproj +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp.csproj @@ -9,7 +9,7 @@ - + diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN/Abp/OssManagement/FileSystem/ImageSharp/ImageSharpFileSystemOssObjectProcesser.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN/Abp/OssManagement/FileSystem/ImageSharp/ImageSharpFileSystemOssObjectProcesser.cs index 5a9695d33..5ba8198d4 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN/Abp/OssManagement/FileSystem/ImageSharp/ImageSharpFileSystemOssObjectProcesser.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN/Abp/OssManagement/FileSystem/ImageSharp/ImageSharpFileSystemOssObjectProcesser.cs @@ -14,20 +14,12 @@ namespace LINGYUN.Abp.OssManagement.FileSystem.ImageSharp { public class ImageSharpProcesserContributor : IFileSystemOssObjectProcesserContributor { - protected static readonly string[] ImageTypes = new string[] - { - "6677",// bmp - "7173",// gif - "13780",// png - "255216"// jpg - }; - public async virtual Task ProcessAsync(FileSystemOssObjectContext context) { var copyStream = context.OssObject.Content; var bytes = await copyStream.GetAllBytesAsync(); - if (IsImage(bytes)) + if (bytes.IsImage()) { var args = context.Process.Split(','); if (DrawGraphics(bytes, args, out var content)) @@ -45,8 +37,8 @@ namespace LINGYUN.Abp.OssManagement.FileSystem.ImageSharp using var image = Image.Load(fileBytes, out var format); // 大小 - var width = GetInt32Prarm(args, "w_"); - var height = GetInt32Prarm(args, "h_"); + var width = args.GetInt32Prarm("w_"); + var height = args.GetInt32Prarm("h_"); if (!width.IsNullOrWhiteSpace() && !height.IsNullOrWhiteSpace()) { @@ -76,47 +68,5 @@ namespace LINGYUN.Abp.OssManagement.FileSystem.ImageSharp content = imageStream; return true; } - - private static bool IsImage(byte[] fileBytes) - { - if (fileBytes.IsNullOrEmpty()) - { - return false; - } - - string fileclass = ""; - for (int i = 0; i < 2; i++) - { - fileclass += fileBytes[i].ToString(); - } - - return ImageTypes.Any(type => type.Equals(fileclass)); - } - - private static string GetString(string[] args, string key) - { - if (!args.Any()) - { - return null; - } - - return args - .Where(arg => arg.StartsWith(key)) - .Select(arg => arg.Substring(key.Length)) - .FirstOrDefault(); - } - - private static string GetInt32Prarm(string[] args, string key) - { - if (!args.Any()) - { - return null; - } - - return args - .Where(arg => arg.StartsWith(key)) - .Select(arg => arg.Substring(key.Length)) - .FirstOrDefault(arg => int.TryParse(arg, out _)); - } } } diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/FodyWeavers.xml b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/FodyWeavers.xsd b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/LIINGYUN/Abp/OssManagement/FileSystem/Imaging/ImageSharp/AbpOssManagementFileSystemImagingImageSharpModule.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/LIINGYUN/Abp/OssManagement/FileSystem/Imaging/ImageSharp/AbpOssManagementFileSystemImagingImageSharpModule.cs new file mode 100644 index 000000000..6378db3f6 --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/LIINGYUN/Abp/OssManagement/FileSystem/Imaging/ImageSharp/AbpOssManagementFileSystemImagingImageSharpModule.cs @@ -0,0 +1,12 @@ +using LINGYUN.Abp.OssManagement.FileSystem.Imaging; +using Volo.Abp.Imaging; +using Volo.Abp.Modularity; + +namespace LIINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp; + +[DependsOn( + typeof(AbpImagingImageSharpModule), + typeof(AbpOssManagementFileSystemImagingModule))] +public class AbpOssManagementFileSystemImagingImageSharpModule : AbpModule +{ +} diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp.csproj b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp.csproj new file mode 100644 index 000000000..f45925351 --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp/LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp.csproj @@ -0,0 +1,19 @@ + + + + + + + netstandard2.1 + + + + + + + + + + + + diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/FodyWeavers.xml b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/FodyWeavers.xsd b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/FodyWeavers.xsd new file mode 100644 index 000000000..3f3946e28 --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN.Abp.OssManagement.FileSystem.Imaging.csproj b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN.Abp.OssManagement.FileSystem.Imaging.csproj new file mode 100644 index 000000000..b1199ba14 --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN.Abp.OssManagement.FileSystem.Imaging.csproj @@ -0,0 +1,19 @@ + + + + + + + netstandard2.1 + + + + + + + + + + + + diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpImagingProcesserContributor.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpImagingProcesserContributor.cs new file mode 100644 index 000000000..e840cd7e5 --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpImagingProcesserContributor.cs @@ -0,0 +1,75 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.Imaging; + +namespace LINGYUN.Abp.OssManagement.FileSystem.Imaging; +public class AbpImagingProcesserContributor : IFileSystemOssObjectProcesserContributor +{ + public async virtual Task ProcessAsync(FileSystemOssObjectContext context) + { + Stream processSreeam = new MemoryStream(); + var copyStream = context.OssObject.Content; + await copyStream.CopyToAsync(processSreeam); + copyStream.Seek(0, SeekOrigin.Begin); + var bytes = await copyStream.GetAllBytesAsync(); + + if (bytes.IsImage()) + { + var args = context.Process.Split(','); + + if (Resize(args, out var resizeArgs)) + { + var imageResizer = context.ServiceProvider.GetRequiredService(); + var resizeResult = await imageResizer.ResizeAsync(processSreeam, resizeArgs); + if (resizeResult.State == ImageProcessState.Done) + { + processSreeam = resizeResult.Result; + } + } + if (Compress(args)) + { + var imageCompressor = context.ServiceProvider.GetRequiredService(); + var compressResult = await imageCompressor.CompressAsync(processSreeam); + if (compressResult.State == ImageProcessState.Done) + { + processSreeam = compressResult.Result; + } + } + if (processSreeam.Length != copyStream.Length) + { + context.SetContent(processSreeam); + // 释放原图形流数据 + await copyStream.DisposeAsync(); + } + else + { + await processSreeam.DisposeAsync(); + } + } + } + + protected virtual bool Resize(string[] args, out ImageResizeArgs resizeArgs) + { + // 大小 + var width = args.GetInt32Prarm("w_"); + var height = args.GetInt32Prarm("h_"); + if (!width.IsNullOrWhiteSpace() && + !height.IsNullOrWhiteSpace()) + { + resizeArgs = new ImageResizeArgs( + int.Parse(width), + int.Parse(height)); + return true; + } + resizeArgs = null; + return false; + } + + protected virtual bool Compress(string[] args) + { + return args.Contains("cm"); + } +} diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpOssManagementFileSystemImagingModule.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpOssManagementFileSystemImagingModule.cs new file mode 100644 index 000000000..ebe8496e6 --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpOssManagementFileSystemImagingModule.cs @@ -0,0 +1,18 @@ +using Volo.Abp.Imaging; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.OssManagement.FileSystem.Imaging; + +[DependsOn( + typeof(AbpImagingAbstractionsModule), + typeof(AbpOssManagementFileSystemModule))] +public class AbpOssManagementFileSystemImagingModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.AddProcesser(new AbpImagingProcesserContributor()); + }); + } +} diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/System/ByteExtensions.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/System/ByteExtensions.cs new file mode 100644 index 000000000..ccf86b05c --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/System/ByteExtensions.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace System; +public static class ByteExtensions +{ + private readonly static string[] ImageTypes = new string[] + { + "6677",// bmp + "7173",// gif + "13780",// png + "255216"// jpg + }; + + public static bool IsImage(this byte[] fileBytes) + { + if (fileBytes.IsNullOrEmpty()) + { + return false; + } + + string fileclass = ""; + for (int i = 0; i < 2; i++) + { + fileclass += fileBytes[i].ToString(); + } + + return ImageTypes.Any(type => type.Equals(fileclass)); + } +} diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/System/StringArrayArgsExtensions.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/System/StringArrayArgsExtensions.cs new file mode 100644 index 000000000..fdad716e9 --- /dev/null +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/System/StringArrayArgsExtensions.cs @@ -0,0 +1,31 @@ +using System.Linq; + +namespace System; +public static class StringArrayArgsExtensions +{ + public static string GetStringPrarm(this string[] args, string key) + { + if (!args.Any()) + { + return null; + } + + return args + .Where(arg => arg.StartsWith(key)) + .Select(arg => arg.Substring(key.Length)) + .FirstOrDefault(); + } + + public static string GetInt32Prarm(this string[] args, string key) + { + if (!args.Any()) + { + return null; + } + + return args + .Where(arg => arg.StartsWith(key)) + .Select(arg => arg.Substring(key.Length)) + .FirstOrDefault(arg => int.TryParse(arg, out _)); + } +} diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/PrivateFilesController.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/PrivateFilesController.cs index 359f3dddc..101710016 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/PrivateFilesController.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/PrivateFilesController.cs @@ -57,7 +57,7 @@ namespace LINGYUN.Abp.OssManagement [Route("t/{TenantId}/p/{Path}/{Name}/{Process}")] public async virtual Task GetAsync([FromRoute] GetPublicFileInput input) { - using (CurrentTenant.Change(input.TenantId ?? CurrentTenant.Id)) + using (CurrentTenant.Change(input.GetTenantId(CurrentTenant))) { return await _service.GetAsync(input); } diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/PublicFilesController.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/PublicFilesController.cs index c016dc6e1..c59dacdb8 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/PublicFilesController.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/PublicFilesController.cs @@ -56,7 +56,7 @@ namespace LINGYUN.Abp.OssManagement [Route("t/{TenantId}/p/{Path}/{Name}/{Process}")] public async virtual Task GetAsync([FromRoute] GetPublicFileInput input) { - using (CurrentTenant.Change(input.TenantId ?? CurrentTenant.Id)) + using (CurrentTenant.Change(input.GetTenantId(CurrentTenant))) { return await _publicFileAppService.GetAsync(input); } diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs index ae5ea598d..d0e0ec318 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.HttpApi/LINGYUN/Abp/OssManagement/StaticFilesController.cs @@ -45,7 +45,7 @@ namespace LINGYUN.Abp.OssManagement [Route("t/{TenantId}/{Bucket}/p/{Path}/{Name}/{Process}")] public async virtual Task GetAsync([FromRoute] GetStaticFileInput input) { - using (CurrentTenant.Change(input.TenantId ?? CurrentTenant.Id)) + using (CurrentTenant.Change(input.GetTenantId(CurrentTenant))) { return await _staticFilesAppServic.GetAsync(input); } diff --git a/aspnet-core/modules/oss-management/README.md b/aspnet-core/modules/oss-management/README.md index 5aa93b44f..1ff3996bf 100644 --- a/aspnet-core/modules/oss-management/README.md +++ b/aspnet-core/modules/oss-management/README.md @@ -20,6 +20,8 @@ File-Management更名为Oss-Management * [LINGYUN.Abp.OssManagement.Aliyun](./LINGYUN.Abp.OssManagement.Aliyun) Oss管理的阿里云实现,实现了部分阿里云Oss服务的容器与对象管理 * [LINGYUN.Abp.OssManagement.FileSystem](./LINGYUN.Abp.OssManagement.FileSystem) Oss管理的本地文件系统实现,实现了部分本地文件系统的容器(目录)与对象(文件/目录)管理 * [LINGYUN.Abp.OssManagement.FileSystem.ImageSharp](./LINGYUN.Abp.OssManagement.FileSystem.ImageSharp) Oss本地对象的ImageSharp扩展,当前端传递需求处理对象时,此模块用于实现基于图形文件流的处理 +* [LINGYUN.Abp.OssManagement.FileSystem.Imaging](./LINGYUN.Abp.OssManagement.FileSystem.Imaging) Oss本地对象的Volo.Abp.Imaging扩展 +* [LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp](./LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp) Oss本地对象的Volo.Abp.Imaging.ImageSharp扩展 ### 权限定义 @@ -52,3 +54,4 @@ File-Management更名为Oss-Management *【2021-03-10】 变更FileManagement命名空间为OssManagement *【2021-10-22】 增加PublicFilesController用于身份认证通过的用户上传/下载文件,所有操作限定在用户目录下 *【2021-12-13】 增加LINGYUN.Abp.BlobStoring.OssManagement用于实现Oss代理二进制文件存储 +*【2023-09-04】 集成Volo.Abp.Imaging模块用于图形文件流处理 diff --git a/aspnet-core/templates/content/Directory.Build.props b/aspnet-core/templates/content/Directory.Build.props index 5d1e2d2f9..ad38fa765 100644 --- a/aspnet-core/templates/content/Directory.Build.props +++ b/aspnet-core/templates/content/Directory.Build.props @@ -1,33 +1,49 @@ - 1.6.9 - 7.2.2 - 7.2.2 - 7.1.0 - 1.10.0 + 7.3.2 + 2.3.2 + 7.3.2 + 1.11.0 1.0.2 + 7.2.0 + 2.11.0 + 1.5.10 + 2.13.0 + 3.0.712 + 1.6.9 + 2.0.3 + 1.8.2 + 7.15.1 + 13.0.1 1.0.0-rc8 1.3.1 1.0.0-rc8 1.0.0-rc8 1.0.0-beta2 - 2.10.0 - 1.5.0 - 5.0.0 + 3.3.3 + 2.2.4 + 2.12.0 + 7.0.0 2.2.0 2.0.0 - 2.0.1 + 2.0.2 3.1.0 3.0.1 - 3.4.0 + 7.0.1 4.0.0 - 8.4.1 + 9.0.3 5.0.0 - 6.1.5 + 6.3.0 + 7.2.3 7.0.* 7.0.2 2.4.1 3.0.2 4.2.1 + 17.3.2 + 2.5.0 + 3.0.2 + 4.2.1 + 3.0.2 \ No newline at end of file diff --git a/aspnet-core/templates/content/PackageName.CompanyName.ProjectName.sln b/aspnet-core/templates/content/PackageName.CompanyName.ProjectName.sln index 0ea10a454..baccd1688 100644 --- a/aspnet-core/templates/content/PackageName.CompanyName.ProjectName.sln +++ b/aspnet-core/templates/content/PackageName.CompanyName.ProjectName.sln @@ -30,6 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Solution Items", ".Solutio common.props = common.props configureawait.props = configureawait.props Directory.Build.props = Directory.Build.props + ..\..\NuGet.Config = ..\..\NuGet.Config EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "host", "host", "{4786387C-C1C5-46F8-806F-EBC54DB0A4FA}" diff --git a/aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj b/aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj index aa926d275..d12f950b5 100644 --- a/aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj +++ b/aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj @@ -11,7 +11,6 @@ - diff --git a/aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.DbMigrator/Program.cs b/aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.DbMigrator/Program.cs index 8f6151dfe..087267054 100644 --- a/aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.DbMigrator/Program.cs +++ b/aspnet-core/templates/content/host/PackageName.CompanyName.ProjectName.DbMigrator/Program.cs @@ -20,8 +20,8 @@ public class Program .MinimumLevel.Override("PackageName.CompanyName.ProjectName", LogEventLevel.Information) #endif .Enrich.FromLogContext() - .WriteTo.Async(c => c.File("Logs/logs.txt")) - .WriteTo.Async(c => c.Console()) + .WriteTo.File("Logs/logs.txt") + .WriteTo.Console() .CreateLogger(); await CreateHostBuilder(args).RunConsoleAsync();