Browse Source
feat(oss-management): extract OSS stream processing to the basic modulepull/1050/head
committed by
GitHub
45 changed files with 754 additions and 590 deletions
@ -0,0 +1,14 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace LINGYUN.Abp.OssManagement; |
||||
|
|
||||
|
public static class AbpOssManagementOptionsExtensions |
||||
|
{ |
||||
|
public static void AddProcesser<TProcesserContributor>( |
||||
|
this AbpOssManagementOptions options, |
||||
|
TProcesserContributor contributor) |
||||
|
where TProcesserContributor : IOssObjectProcesserContributor |
||||
|
{ |
||||
|
options.Processers.InsertBefore((x) => x is NoneOssObjectProcesser, contributor); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace LINGYUN.Abp.OssManagement; |
||||
|
|
||||
|
public interface IOssObjectProcesserContributor |
||||
|
{ |
||||
|
Task ProcessAsync(OssObjectProcesserContext context); |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace LINGYUN.Abp.OssManagement; |
||||
|
|
||||
|
public class NoneOssObjectProcesser : IOssObjectProcesserContributor |
||||
|
{ |
||||
|
public Task ProcessAsync(OssObjectProcesserContext context) |
||||
|
{ |
||||
|
context.SetContent(context.OssObject.Content); |
||||
|
|
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace LINGYUN.Abp.OssManagement; |
||||
|
public abstract class OssContainerBase : IOssContainer |
||||
|
{ |
||||
|
protected AbpOssManagementOptions Options { get; } |
||||
|
protected IServiceScopeFactory ServiceScopeFactory { get; } |
||||
|
|
||||
|
protected OssContainerBase( |
||||
|
IOptions<AbpOssManagementOptions> options, |
||||
|
IServiceScopeFactory serviceScopeFactory) |
||||
|
{ |
||||
|
Options = options.Value; |
||||
|
ServiceScopeFactory = serviceScopeFactory; |
||||
|
} |
||||
|
|
||||
|
public async virtual Task<OssObject> GetObjectAsync(GetOssObjectRequest request) |
||||
|
{ |
||||
|
var ossObject = await GetOssObjectAsync(request); |
||||
|
|
||||
|
if (ShouldProcessObject(ossObject) && !request.Process.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
using var serviceScope = ServiceScopeFactory.CreateScope(); |
||||
|
var context = new OssObjectProcesserContext(request.Process, ossObject, serviceScope.ServiceProvider); |
||||
|
foreach (var processer in Options.Processers) |
||||
|
{ |
||||
|
await processer.ProcessAsync(context); |
||||
|
|
||||
|
if (context.Handled) |
||||
|
{ |
||||
|
ossObject.SetContent(context.Content); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return ossObject; |
||||
|
} |
||||
|
|
||||
|
public async virtual Task DeleteAsync(string name) |
||||
|
{ |
||||
|
if (Options.CheckStaticBucket(name)) |
||||
|
{ |
||||
|
throw new BusinessException(code: OssManagementErrorCodes.ContainerDeleteWithStatic); |
||||
|
} |
||||
|
|
||||
|
await DeleteBucketAsync(name); |
||||
|
} |
||||
|
|
||||
|
public abstract Task BulkDeleteObjectsAsync(BulkDeleteObjectRequest request); |
||||
|
public abstract Task<OssContainer> CreateAsync(string name); |
||||
|
public abstract Task<OssObject> CreateObjectAsync(CreateOssObjectRequest request); |
||||
|
public abstract Task DeleteObjectAsync(GetOssObjectRequest request); |
||||
|
public abstract Task<bool> ExistsAsync(string name); |
||||
|
public abstract Task<OssContainer> GetAsync(string name); |
||||
|
public abstract Task<GetOssContainersResponse> GetListAsync(GetOssContainersRequest request); |
||||
|
public abstract Task<GetOssObjectsResponse> GetObjectsAsync(GetOssObjectsRequest request); |
||||
|
protected abstract Task DeleteBucketAsync(string name); |
||||
|
protected abstract Task<OssObject> GetOssObjectAsync(GetOssObjectRequest request); |
||||
|
protected virtual bool ShouldProcessObject(OssObject ossObject) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -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)); |
||||
|
} |
||||
|
} |
||||
@ -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 _)); |
||||
|
} |
||||
|
} |
||||
@ -1,15 +0,0 @@ |
|||||
using Volo.Abp.Modularity; |
|
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement.FileSystem.ImageSharp; |
|
||||
|
|
||||
[DependsOn(typeof(AbpOssManagementFileSystemModule))] |
|
||||
public class AbpOssManagementFileSystemImageSharpModule : AbpModule |
|
||||
{ |
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
Configure<FileSystemOssOptions>(options => |
|
||||
{ |
|
||||
options.AddProcesser(new ImageSharpProcesserContributor()); |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
@ -1,12 +0,0 @@ |
|||||
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 |
|
||||
{ |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
using JetBrains.Annotations; |
|
||||
using System.Collections.Generic; |
|
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement.FileSystem; |
|
||||
|
|
||||
public class FileSystemOssOptions |
|
||||
{ |
|
||||
[NotNull] |
|
||||
public List<IFileSystemOssObjectProcesserContributor> Processers { get; } |
|
||||
|
|
||||
public FileSystemOssOptions() |
|
||||
{ |
|
||||
Processers = new List<IFileSystemOssObjectProcesserContributor> |
|
||||
{ |
|
||||
new NoneFileSystemOssObjectProcesser() |
|
||||
}; |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement.FileSystem; |
|
||||
|
|
||||
public static class FileSystemOssOptionsExtensions |
|
||||
{ |
|
||||
public static void AddProcesser<TProcesserContributor>( |
|
||||
this FileSystemOssOptions options, |
|
||||
TProcesserContributor contributor) |
|
||||
where TProcesserContributor : IFileSystemOssObjectProcesserContributor |
|
||||
{ |
|
||||
options.Processers.InsertBefore((x) => x is NoneFileSystemOssObjectProcesser, contributor); |
|
||||
} |
|
||||
} |
|
||||
@ -1,8 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement.FileSystem; |
|
||||
|
|
||||
public interface IFileSystemOssObjectProcesserContributor |
|
||||
{ |
|
||||
Task ProcessAsync(FileSystemOssObjectContext context); |
|
||||
} |
|
||||
@ -1,13 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement.FileSystem; |
|
||||
|
|
||||
public class NoneFileSystemOssObjectProcesser : IFileSystemOssObjectProcesserContributor |
|
||||
{ |
|
||||
public Task ProcessAsync(FileSystemOssObjectContext context) |
|
||||
{ |
|
||||
context.SetContent(context.OssObject.Content); |
|
||||
|
|
||||
return Task.CompletedTask; |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,15 @@ |
|||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.OssManagement.ImageSharp; |
||||
|
|
||||
|
[DependsOn(typeof(AbpOssManagementDomainModule))] |
||||
|
public class AbpOssManagementImageSharpModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpOssManagementOptions>(options => |
||||
|
{ |
||||
|
options.AddProcesser(new ImageSharpOssObjectProcesser()); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
14
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN/Abp/OssManagement/FileSystem/ImageSharp/ImageSharpFileSystemOssObjectProcesser.cs → aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.ImageSharp/LINGYUN/Abp/OssManagement/ImageSharp/ImageSharpOssObjectProcesser.cs
14
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.ImageSharp/LINGYUN/Abp/OssManagement/FileSystem/ImageSharp/ImageSharpFileSystemOssObjectProcesser.cs → aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.ImageSharp/LINGYUN/Abp/OssManagement/ImageSharp/ImageSharpOssObjectProcesser.cs
@ -1,20 +1,14 @@ |
|||||
using SixLabors.Fonts; |
using SixLabors.ImageSharp; |
||||
using SixLabors.ImageSharp; |
|
||||
using SixLabors.ImageSharp.Advanced; |
|
||||
using SixLabors.ImageSharp.Drawing.Processing; |
|
||||
using SixLabors.ImageSharp.Formats; |
|
||||
using SixLabors.ImageSharp.Processing; |
using SixLabors.ImageSharp.Processing; |
||||
using System; |
using System; |
||||
using System.Collections.Generic; |
|
||||
using System.IO; |
using System.IO; |
||||
using System.Linq; |
|
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement.FileSystem.ImageSharp; |
namespace LINGYUN.Abp.OssManagement.ImageSharp; |
||||
|
|
||||
public class ImageSharpProcesserContributor : IFileSystemOssObjectProcesserContributor |
public class ImageSharpOssObjectProcesser : IOssObjectProcesserContributor |
||||
{ |
{ |
||||
public async virtual Task ProcessAsync(FileSystemOssObjectContext context) |
public async virtual Task ProcessAsync(OssObjectProcesserContext context) |
||||
{ |
{ |
||||
var copyStream = context.OssObject.Content; |
var copyStream = context.OssObject.Content; |
||||
var bytes = await copyStream.GetAllBytesAsync(); |
var bytes = await copyStream.GetAllBytesAsync(); |
||||
@ -1,6 +1,6 @@ |
|||||
# LINGYUN.Abp.OssManagement.FileSystem.ImageSharp |
# LINGYUN.Abp.OssManagement.ImageSharp |
||||
|
|
||||
本地文件系统oss对象ImageSharp图形处理接口 |
oss对象ImageSharp图形处理接口 |
||||
|
|
||||
## 配置使用 |
## 配置使用 |
||||
|
|
||||
@ -0,0 +1,11 @@ |
|||||
|
using Volo.Abp.Imaging; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.OssManagement.Imaging.ImageSharp; |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpImagingImageSharpModule), |
||||
|
typeof(AbpOssManagementImagingModule))] |
||||
|
public class AbpOssManagementImagingImageSharpModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
16
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpImagingProcesserContributor.cs → aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Imaging/LINGYUN/Abp/OssManagement/Imaging/AbpImagingProcesserContributor.cs
16
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpImagingProcesserContributor.cs → aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Imaging/LINGYUN/Abp/OssManagement/Imaging/AbpImagingProcesserContributor.cs
8
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpOssManagementFileSystemImagingModule.cs → aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Imaging/LINGYUN/Abp/OssManagement/Imaging/AbpOssManagementImagingModule.cs
8
aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem.Imaging/LINGYUN/Abp/OssManagement/FileSystem/Imaging/AbpOssManagementFileSystemImagingModule.cs → aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Imaging/LINGYUN/Abp/OssManagement/Imaging/AbpOssManagementImagingModule.cs
@ -1,16 +1,16 @@ |
|||||
using Volo.Abp.Imaging; |
using Volo.Abp.Imaging; |
||||
using Volo.Abp.Modularity; |
using Volo.Abp.Modularity; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement.FileSystem.Imaging; |
namespace LINGYUN.Abp.OssManagement.Imaging; |
||||
|
|
||||
[DependsOn( |
[DependsOn( |
||||
typeof(AbpImagingAbstractionsModule), |
typeof(AbpImagingAbstractionsModule), |
||||
typeof(AbpOssManagementFileSystemModule))] |
typeof(AbpOssManagementDomainModule))] |
||||
public class AbpOssManagementFileSystemImagingModule : AbpModule |
public class AbpOssManagementImagingModule : AbpModule |
||||
{ |
{ |
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
{ |
{ |
||||
Configure<FileSystemOssOptions>(options => |
Configure<AbpOssManagementOptions>(options => |
||||
{ |
{ |
||||
options.AddProcesser(new AbpImagingProcesserContributor()); |
options.AddProcesser(new AbpImagingProcesserContributor()); |
||||
}); |
}); |
||||
Loading…
Reference in new issue