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