committed by
GitHub
3 changed files with 165 additions and 165 deletions
@ -1,22 +1,22 @@ |
|||||
namespace LINGYUN.Abp.OssManagement.Settings |
namespace LINGYUN.Abp.OssManagement.Settings |
||||
{ |
{ |
||||
public class AbpOssManagementSettingNames |
public class AbpOssManagementSettingNames |
||||
{ |
{ |
||||
public const string GroupName = "Abp.OssManagement"; |
public const string GroupName = "Abp.OssManagement"; |
||||
/// <summary>
|
/// <summary>
|
||||
/// 下载分包大小
|
/// 下载分包大小
|
||||
/// </summary>
|
/// </summary>
|
||||
public const string DownloadPackageSize = GroupName + ".DownloadPackageSize"; |
public const string DownloadPackageSize = GroupName + ".DownloadPackageSize"; |
||||
/// <summary>
|
/// <summary>
|
||||
/// 文件限制长度
|
/// 文件限制长度
|
||||
/// </summary>
|
/// </summary>
|
||||
public const string FileLimitLength = GroupName + ".FileLimitLength"; |
public const string FileLimitLength = GroupName + ".FileLimitLength"; |
||||
/// <summary>
|
/// <summary>
|
||||
/// 允许的文件扩展名类型
|
/// 允许的文件扩展名类型
|
||||
/// </summary>
|
/// </summary>
|
||||
public const string AllowFileExtensions = GroupName + ".AllowFileExtensions"; |
public const string AllowFileExtensions = GroupName + ".AllowFileExtensions"; |
||||
|
|
||||
public const int DefaultFileLimitLength = 100; |
public const long DefaultFileLimitLength = 100L; |
||||
public const string DefaultAllowFileExtensions = "dll,zip,rar,txt,log,xml,config,json,jpeg,jpg,png,bmp,ico,xlsx,xltx,xls,xlt,docs,dots,doc,dot,pptx,potx,ppt,pot,chm"; |
public const string DefaultAllowFileExtensions = "dll,zip,rar,txt,log,xml,config,json,jpeg,jpg,png,bmp,ico,xlsx,xltx,xls,xlt,docs,dots,doc,dot,pptx,potx,ppt,pot,chm"; |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,96 +1,96 @@ |
|||||
using LINGYUN.Abp.OssManagement.Localization; |
using LINGYUN.Abp.OssManagement.Localization; |
||||
using LINGYUN.Abp.OssManagement.Settings; |
using LINGYUN.Abp.OssManagement.Settings; |
||||
using Microsoft.Extensions.Caching.Memory; |
using Microsoft.Extensions.Caching.Memory; |
||||
using Microsoft.Extensions.Localization; |
using Microsoft.Extensions.Localization; |
||||
using System; |
using System; |
||||
using System.Linq; |
using System.Linq; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp; |
using Volo.Abp; |
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
using Volo.Abp.IO; |
using Volo.Abp.IO; |
||||
using Volo.Abp.Settings; |
using Volo.Abp.Settings; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement |
namespace LINGYUN.Abp.OssManagement |
||||
{ |
{ |
||||
public class FileValidater : IFileValidater, ISingletonDependency |
public class FileValidater : IFileValidater, ISingletonDependency |
||||
{ |
{ |
||||
private readonly IMemoryCache _cache; |
private readonly IMemoryCache _cache; |
||||
private readonly ISettingProvider _settingProvider; |
private readonly ISettingProvider _settingProvider; |
||||
private readonly IServiceProvider _serviceProvider; |
private readonly IServiceProvider _serviceProvider; |
||||
private readonly IStringLocalizer _stringLocalizer; |
private readonly IStringLocalizer _stringLocalizer; |
||||
|
|
||||
public FileValidater( |
public FileValidater( |
||||
IMemoryCache cache, |
IMemoryCache cache, |
||||
ISettingProvider settingProvider, |
ISettingProvider settingProvider, |
||||
IServiceProvider serviceProvider, |
IServiceProvider serviceProvider, |
||||
IStringLocalizer<AbpOssManagementResource> stringLocalizer) |
IStringLocalizer<AbpOssManagementResource> stringLocalizer) |
||||
{ |
{ |
||||
_cache = cache; |
_cache = cache; |
||||
_settingProvider = settingProvider; |
_settingProvider = settingProvider; |
||||
_serviceProvider = serviceProvider; |
_serviceProvider = serviceProvider; |
||||
_stringLocalizer = stringLocalizer; |
_stringLocalizer = stringLocalizer; |
||||
} |
} |
||||
|
|
||||
public virtual async Task ValidationAsync(UploadOssObjectInput input) |
public virtual async Task ValidationAsync(UploadOssObjectInput input) |
||||
{ |
{ |
||||
var validation = await GetByCacheItemAsync(); |
var validation = await GetByCacheItemAsync(); |
||||
if (validation.SizeLimit * 1024 * 1024 < input.TotalSize) |
if (validation.SizeLimit * 1024 * 1024 < input.TotalSize) |
||||
{ |
{ |
||||
throw new UserFriendlyException(_stringLocalizer["UploadFileSizeBeyondLimit", validation.SizeLimit]); |
throw new UserFriendlyException(_stringLocalizer["UploadFileSizeBeyondLimit", validation.SizeLimit]); |
||||
} |
} |
||||
var fileExtensionName = FileHelper.GetExtension(input.FileName); |
var fileExtensionName = FileHelper.GetExtension(input.FileName); |
||||
if (!validation.AllowedExtensions |
if (!validation.AllowedExtensions |
||||
.Any(fe => fe.Equals(fileExtensionName, StringComparison.CurrentCultureIgnoreCase))) |
.Any(fe => fe.Equals(fileExtensionName, StringComparison.CurrentCultureIgnoreCase))) |
||||
{ |
{ |
||||
throw new UserFriendlyException(_stringLocalizer["NotAllowedFileExtensionName", fileExtensionName]); |
throw new UserFriendlyException(_stringLocalizer["NotAllowedFileExtensionName", fileExtensionName]); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
protected virtual async Task<FileValidation> GetByCacheItemAsync() |
protected virtual async Task<FileValidation> GetByCacheItemAsync() |
||||
{ |
{ |
||||
var fileValidation = _cache.Get<FileValidation>(FileValidation.CacheKey); |
var fileValidation = _cache.Get<FileValidation>(FileValidation.CacheKey); |
||||
if (fileValidation == null) |
if (fileValidation == null) |
||||
{ |
{ |
||||
fileValidation = await GetBySettingAsync(); |
fileValidation = await GetBySettingAsync(); |
||||
_cache.Set(FileValidation.CacheKey, |
_cache.Set(FileValidation.CacheKey, |
||||
fileValidation, |
fileValidation, |
||||
new MemoryCacheEntryOptions |
new MemoryCacheEntryOptions |
||||
{ |
{ |
||||
AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(2) |
AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(2) |
||||
}); |
}); |
||||
} |
} |
||||
return fileValidation; |
return fileValidation; |
||||
} |
} |
||||
|
|
||||
protected virtual async Task<FileValidation> GetBySettingAsync() |
protected virtual async Task<FileValidation> GetBySettingAsync() |
||||
{ |
{ |
||||
var fileSizeLimited = await _settingProvider |
var fileSizeLimited = await _settingProvider |
||||
.GetAsync( |
.GetAsync( |
||||
AbpOssManagementSettingNames.FileLimitLength, |
AbpOssManagementSettingNames.FileLimitLength, |
||||
AbpOssManagementSettingNames.DefaultFileLimitLength); |
AbpOssManagementSettingNames.DefaultFileLimitLength); |
||||
var fileAllowExtension = await _settingProvider |
var fileAllowExtension = await _settingProvider |
||||
.GetOrDefaultAsync(AbpOssManagementSettingNames.AllowFileExtensions, _serviceProvider); |
.GetOrDefaultAsync(AbpOssManagementSettingNames.AllowFileExtensions, _serviceProvider); |
||||
|
|
||||
return new FileValidation(fileSizeLimited, fileAllowExtension.Split(',')); |
return new FileValidation(fileSizeLimited, fileAllowExtension.Split(',')); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
public class FileValidation |
public class FileValidation |
||||
{ |
{ |
||||
public const string CacheKey = "Abp.OssManagement.FileValidation"; |
public const string CacheKey = "Abp.OssManagement.FileValidation"; |
||||
public int SizeLimit { get; set; } |
public long SizeLimit { get; set; } |
||||
public string[] AllowedExtensions { get; set; } |
public string[] AllowedExtensions { get; set; } |
||||
public FileValidation() |
public FileValidation() |
||||
{ |
{ |
||||
|
|
||||
} |
} |
||||
|
|
||||
public FileValidation( |
public FileValidation( |
||||
int sizeLimit, |
long sizeLimit, |
||||
string[] allowedExtensions) |
string[] allowedExtensions) |
||||
{ |
{ |
||||
SizeLimit = sizeLimit; |
SizeLimit = sizeLimit; |
||||
AllowedExtensions = allowedExtensions; |
AllowedExtensions = allowedExtensions; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,47 +1,47 @@ |
|||||
using Microsoft.AspNetCore.Http; |
using Microsoft.AspNetCore.Http; |
||||
using System.ComponentModel.DataAnnotations; |
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement |
namespace LINGYUN.Abp.OssManagement |
||||
{ |
{ |
||||
public class UploadOssObjectInput |
public class UploadOssObjectInput |
||||
{ |
{ |
||||
public string Bucket { get; set; } |
public string Bucket { get; set; } |
||||
public string Path { get; set; } |
public string Path { get; set; } |
||||
|
|
||||
#region 配合Uplaoder 分块传输
|
#region 配合Uplaoder 分块传输
|
||||
/// <summary>
|
/// <summary>
|
||||
/// 文件名
|
/// 文件名
|
||||
/// </summary>
|
/// </summary>
|
||||
[Required] |
[Required] |
||||
public string FileName { get; set; } |
public string FileName { get; set; } |
||||
/// <summary>
|
/// <summary>
|
||||
/// 常规块大小
|
/// 常规块大小
|
||||
/// </summary>
|
/// </summary>
|
||||
[Required] |
[Required] |
||||
public int ChunkSize { get; set; } |
public long ChunkSize { get; set; } |
||||
/// <summary>
|
/// <summary>
|
||||
/// 当前块大小
|
/// 当前块大小
|
||||
/// </summary>
|
/// </summary>
|
||||
[Required] |
[Required] |
||||
public int CurrentChunkSize { get; set; } |
public long CurrentChunkSize { get; set; } |
||||
/// <summary>
|
/// <summary>
|
||||
/// 当前上传中块的索引
|
/// 当前上传中块的索引
|
||||
/// </summary>
|
/// </summary>
|
||||
[Required] |
[Required] |
||||
public int ChunkNumber { get; set; } |
public int ChunkNumber { get; set; } |
||||
/// <summary>
|
/// <summary>
|
||||
/// 块总数
|
/// 块总数
|
||||
/// </summary>
|
/// </summary>
|
||||
[Required] |
[Required] |
||||
public int TotalChunks { get; set; } |
public int TotalChunks { get; set; } |
||||
/// <summary>
|
/// <summary>
|
||||
/// 总文件大小
|
/// 总文件大小
|
||||
/// </summary>
|
/// </summary>
|
||||
[Required] |
[Required] |
||||
public int TotalSize { get; set; } |
public long TotalSize { get; set; } |
||||
|
|
||||
#endregion
|
#endregion
|
||||
|
|
||||
public IFormFile File { get; set; } |
public IFormFile File { get; set; } |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue