14 changed files with 239 additions and 178 deletions
@ -1,15 +1,16 @@ |
|||||
using System.ComponentModel.DataAnnotations; |
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement |
namespace LINGYUN.Abp.OssManagement |
||||
{ |
{ |
||||
public class GetOssObjectInput |
public class GetOssObjectInput |
||||
{ |
{ |
||||
[Required] |
[Required] |
||||
public string Bucket { get; set; } |
public string Bucket { get; set; } |
||||
|
|
||||
public string Path { get; set; } |
public string Path { get; set; } |
||||
|
|
||||
[Required] |
[Required] |
||||
public string Object { get; set; } |
public string Object { get; set; } |
||||
} |
public bool MD5 { get; set; } |
||||
} |
} |
||||
|
} |
||||
|
|||||
@ -1,13 +1,14 @@ |
|||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement |
namespace LINGYUN.Abp.OssManagement |
||||
{ |
{ |
||||
public class GetOssObjectsInput : PagedAndSortedResultRequestDto |
public class GetOssObjectsInput : PagedAndSortedResultRequestDto |
||||
{ |
{ |
||||
public string Bucket { get; set; } |
public string Bucket { get; set; } |
||||
public string Prefix { get; set; } |
public string Prefix { get; set; } |
||||
public string Delimiter { get; set; } |
public string Delimiter { get; set; } |
||||
public string Marker { get; set; } |
public string Marker { get; set; } |
||||
public string EncodingType { get; set; } |
public string EncodingType { get; set; } |
||||
} |
public bool MD5 { get; set; } |
||||
} |
} |
||||
|
} |
||||
|
|||||
@ -1,16 +1,17 @@ |
|||||
using System; |
using System; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement |
namespace LINGYUN.Abp.OssManagement |
||||
{ |
{ |
||||
public class OssObjectDto |
public class OssObjectDto |
||||
{ |
{ |
||||
public bool IsFolder { get; set; } |
public bool IsFolder { get; set; } |
||||
public string Path { get; set; } |
public string Path { get; set; } |
||||
public string Name { get; set; } |
public string Name { get; set; } |
||||
public long Size { get; set; } |
public long Size { get; set; } |
||||
public DateTime? CreationDate { get; set; } |
public string MD5 { get; set; } |
||||
public DateTime? LastModifiedDate { get; set; } |
public DateTime? CreationDate { get; set; } |
||||
public IDictionary<string, string> Metadata { get; set; } |
public DateTime? LastModifiedDate { get; set; } |
||||
} |
public IDictionary<string, string> Metadata { get; set; } |
||||
} |
} |
||||
|
} |
||||
|
|||||
@ -1,39 +1,42 @@ |
|||||
using LINGYUN.Abp.Features.LimitValidation; |
using LINGYUN.Abp.Features.LimitValidation; |
||||
using LINGYUN.Abp.OssManagement.Features; |
using LINGYUN.Abp.OssManagement.Features; |
||||
using System.IO; |
using System.IO; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using System.Web; |
using System.Web; |
||||
using Volo.Abp.Features; |
using Volo.Abp.Features; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement |
namespace LINGYUN.Abp.OssManagement |
||||
{ |
{ |
||||
public class StaticFilesAppService : OssManagementApplicationServiceBase, IStaticFilesAppService |
public class StaticFilesAppService : OssManagementApplicationServiceBase, IStaticFilesAppService |
||||
{ |
{ |
||||
protected IOssContainerFactory OssContainerFactory { get; } |
protected IOssContainerFactory OssContainerFactory { get; } |
||||
|
|
||||
public StaticFilesAppService( |
public StaticFilesAppService( |
||||
IOssContainerFactory ossContainerFactory) |
IOssContainerFactory ossContainerFactory) |
||||
{ |
{ |
||||
OssContainerFactory = ossContainerFactory; |
OssContainerFactory = ossContainerFactory; |
||||
} |
} |
||||
|
|
||||
[RequiresFeature(AbpOssManagementFeatureNames.OssObject.DownloadFile)] |
[RequiresFeature(AbpOssManagementFeatureNames.OssObject.DownloadFile)] |
||||
[RequiresLimitFeature( |
[RequiresLimitFeature( |
||||
AbpOssManagementFeatureNames.OssObject.DownloadLimit, |
AbpOssManagementFeatureNames.OssObject.DownloadLimit, |
||||
AbpOssManagementFeatureNames.OssObject.DownloadInterval, |
AbpOssManagementFeatureNames.OssObject.DownloadInterval, |
||||
LimitPolicy.Month)] |
LimitPolicy.Month)] |
||||
public virtual async Task<Stream> GetAsync(GetStaticFileInput input) |
public virtual async Task<Stream> GetAsync(GetStaticFileInput input) |
||||
{ |
{ |
||||
var ossObjectRequest = new GetOssObjectRequest( |
var ossObjectRequest = new GetOssObjectRequest( |
||||
HttpUtility.UrlDecode(input.Bucket), // 需要处理特殊字符
|
HttpUtility.UrlDecode(input.Bucket), // 需要处理特殊字符
|
||||
HttpUtility.UrlDecode(input.Name), |
HttpUtility.UrlDecode(input.Name), |
||||
HttpUtility.UrlDecode(input.Path), |
HttpUtility.UrlDecode(input.Path), |
||||
HttpUtility.UrlDecode(input.Process)); |
HttpUtility.UrlDecode(input.Process)) |
||||
|
{ |
||||
var ossContainer = OssContainerFactory.Create(); |
MD5 = true, |
||||
var ossObject = await ossContainer.GetObjectAsync(ossObjectRequest); |
}; |
||||
|
|
||||
return ossObject.Content; |
var ossContainer = OssContainerFactory.Create(); |
||||
} |
var ossObject = await ossContainer.GetObjectAsync(ossObjectRequest); |
||||
} |
|
||||
} |
return ossObject.Content; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|||||
@ -1,31 +1,32 @@ |
|||||
using JetBrains.Annotations; |
using JetBrains.Annotations; |
||||
using Volo.Abp; |
using Volo.Abp; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement |
namespace LINGYUN.Abp.OssManagement |
||||
{ |
{ |
||||
public class GetOssObjectRequest |
public class GetOssObjectRequest |
||||
{ |
{ |
||||
public string Bucket { get; } |
public string Bucket { get; } |
||||
public string Path { get; } |
public string Path { get; } |
||||
public string Object { get; } |
public string Object { get; } |
||||
/// <summary>
|
public bool MD5 { get; set; } |
||||
/// 需要处理文件的参数
|
/// <summary>
|
||||
/// </summary>
|
/// 需要处理文件的参数
|
||||
public string Process { get; } |
/// </summary>
|
||||
|
public string Process { get; } |
||||
public GetOssObjectRequest( |
|
||||
[NotNull] string bucket, |
public GetOssObjectRequest( |
||||
[NotNull] string @object, |
[NotNull] string bucket, |
||||
[CanBeNull] string path = "", |
[NotNull] string @object, |
||||
[CanBeNull] string process = "") |
[CanBeNull] string path = "", |
||||
{ |
[CanBeNull] string process = "") |
||||
Check.NotNullOrWhiteSpace(bucket, nameof(bucket)); |
{ |
||||
Check.NotNullOrWhiteSpace(@object, nameof(@object)); |
Check.NotNullOrWhiteSpace(bucket, nameof(bucket)); |
||||
|
Check.NotNullOrWhiteSpace(@object, nameof(@object)); |
||||
Bucket = bucket; |
|
||||
Object = @object; |
Bucket = bucket; |
||||
Path = path; |
Object = @object; |
||||
Process = process; |
Path = path; |
||||
} |
Process = process; |
||||
} |
} |
||||
} |
} |
||||
|
} |
||||
|
|||||
@ -1,50 +1,53 @@ |
|||||
using System; |
using System; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.IO; |
using System.IO; |
||||
|
|
||||
namespace LINGYUN.Abp.OssManagement |
namespace LINGYUN.Abp.OssManagement |
||||
{ |
{ |
||||
/// <summary>
|
/// <summary>
|
||||
/// 描述了一个对象的状态信息
|
/// 描述了一个对象的状态信息
|
||||
/// </summary>
|
/// </summary>
|
||||
public class OssObject |
public class OssObject |
||||
{ |
{ |
||||
private Stream _content; |
private Stream _content; |
||||
|
|
||||
public bool IsFolder { get; } |
public bool IsFolder { get; } |
||||
public string Name { get; } |
public string Name { get; } |
||||
public string FullName { get; set; } |
public string FullName { get; set; } |
||||
public string Prefix { get; } |
public string Prefix { get; } |
||||
public long Size { get; } |
public string MD5{ get; } |
||||
public Stream Content => _content; |
public long Size { get; } |
||||
public DateTime? CreationDate { get; } |
public Stream Content => _content; |
||||
public DateTime? LastModifiedDate { get; } |
public DateTime? CreationDate { get; } |
||||
public IDictionary<string, string> Metadata { get; } |
public DateTime? LastModifiedDate { get; } |
||||
public OssObject( |
public IDictionary<string, string> Metadata { get; } |
||||
string name, |
public OssObject( |
||||
string prefix, |
string name, |
||||
DateTime? creationDate = null, |
string prefix, |
||||
long size = 0, |
string md5, |
||||
DateTime? lastModifiedDate = null, |
DateTime? creationDate = null, |
||||
IDictionary<string, string> metadata = null, |
long size = 0, |
||||
bool isFolder = false) |
DateTime? lastModifiedDate = null, |
||||
{ |
IDictionary<string, string> metadata = null, |
||||
Name = name; |
bool isFolder = false) |
||||
Prefix = prefix; |
{ |
||||
CreationDate = creationDate; |
Name = name; |
||||
LastModifiedDate = lastModifiedDate; |
Prefix = prefix; |
||||
Size = size; |
MD5 = md5; |
||||
IsFolder = isFolder; |
CreationDate = creationDate; |
||||
Metadata = metadata ?? new Dictionary<string, string>(); |
LastModifiedDate = lastModifiedDate; |
||||
} |
Size = size; |
||||
|
IsFolder = isFolder; |
||||
public void SetContent(Stream stream) |
Metadata = metadata ?? new Dictionary<string, string>(); |
||||
{ |
} |
||||
_content = stream; |
|
||||
if (!_content.IsNullOrEmpty()) |
public void SetContent(Stream stream) |
||||
{ |
{ |
||||
_content.Seek(0, SeekOrigin.Begin); |
_content = stream; |
||||
} |
if (!_content.IsNullOrEmpty()) |
||||
} |
{ |
||||
} |
_content.Seek(0, SeekOrigin.Begin); |
||||
} |
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|||||
@ -0,0 +1,25 @@ |
|||||
|
using System.Security.Cryptography; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace System.IO |
||||
|
{ |
||||
|
internal static class FileSystemExtensions |
||||
|
{ |
||||
|
public static string MD5(this FileStream stream) |
||||
|
{ |
||||
|
if (stream.CanSeek) |
||||
|
{ |
||||
|
stream.Seek(0, SeekOrigin.Begin); |
||||
|
} |
||||
|
using MD5 md5 = new MD5CryptoServiceProvider(); |
||||
|
byte[] retVal = md5.ComputeHash(stream); |
||||
|
StringBuilder sb = new StringBuilder(); |
||||
|
for (int i = 0; i < retVal.Length; i++) |
||||
|
{ |
||||
|
sb.Append(retVal[i].ToString("x2")); |
||||
|
} |
||||
|
stream.Seek(0, SeekOrigin.Begin); |
||||
|
return sb.ToString(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue