6 changed files with 244 additions and 249 deletions
@ -1,70 +1,70 @@ |
|||
using LINGYUN.Abp.OssManagement.Permissions; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.OssManagement |
|||
{ |
|||
[Authorize(AbpOssManagementPermissions.Container.Default)] |
|||
public class OssContainerAppService : OssManagementApplicationServiceBase, IOssContainerAppService |
|||
{ |
|||
protected IOssContainerFactory OssContainerFactory { get; } |
|||
|
|||
public OssContainerAppService( |
|||
IOssContainerFactory ossContainerFactory) |
|||
{ |
|||
OssContainerFactory = ossContainerFactory; |
|||
} |
|||
|
|||
[Authorize(AbpOssManagementPermissions.Container.Create)] |
|||
public virtual async Task<OssContainerDto> CreateAsync(string name) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
var container = await oss.CreateAsync(name); |
|||
|
|||
return ObjectMapper.Map<OssContainer, OssContainerDto>(container); |
|||
} |
|||
|
|||
[Authorize(AbpOssManagementPermissions.Container.Delete)] |
|||
public virtual async Task DeleteAsync(string name) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
|
|||
await oss.DeleteAsync(name); |
|||
} |
|||
|
|||
public virtual async Task<OssContainerDto> GetAsync(string name) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
var container = await oss.GetAsync(name); |
|||
|
|||
return ObjectMapper.Map<OssContainer, OssContainerDto>(container); |
|||
} |
|||
|
|||
public virtual async Task<OssContainersResultDto> GetListAsync(GetOssContainersInput input) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
|
|||
var containerResponse = await oss.GetListAsync( |
|||
input.Prefix, input.Marker, input.MaxResultCount); |
|||
|
|||
return ObjectMapper.Map<GetOssContainersResponse, OssContainersResultDto>(containerResponse); |
|||
} |
|||
|
|||
public virtual async Task<OssObjectsResultDto> GetObjectListAsync(GetOssObjectsInput input) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
|
|||
var ossObjectResponse = await oss.GetObjectsAsync( |
|||
input.Bucket, input.Prefix, input.Marker, |
|||
input.Delimiter, input.EncodingType, |
|||
input.MaxResultCount); |
|||
|
|||
return ObjectMapper.Map<GetOssObjectsResponse, OssObjectsResultDto>(ossObjectResponse); |
|||
} |
|||
|
|||
protected virtual IOssContainer CreateOssContainer() |
|||
{ |
|||
return OssContainerFactory.Create(); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.OssManagement.Permissions; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.OssManagement |
|||
{ |
|||
[Authorize(AbpOssManagementPermissions.Container.Default)] |
|||
public class OssContainerAppService : OssManagementApplicationServiceBase, IOssContainerAppService |
|||
{ |
|||
protected IOssContainerFactory OssContainerFactory { get; } |
|||
|
|||
public OssContainerAppService( |
|||
IOssContainerFactory ossContainerFactory) |
|||
{ |
|||
OssContainerFactory = ossContainerFactory; |
|||
} |
|||
|
|||
[Authorize(AbpOssManagementPermissions.Container.Create)] |
|||
public virtual async Task<OssContainerDto> CreateAsync(string name) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
var container = await oss.CreateAsync(name); |
|||
|
|||
return ObjectMapper.Map<OssContainer, OssContainerDto>(container); |
|||
} |
|||
|
|||
[Authorize(AbpOssManagementPermissions.Container.Delete)] |
|||
public virtual async Task DeleteAsync(string name) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
|
|||
await oss.DeleteAsync(name); |
|||
} |
|||
|
|||
public virtual async Task<OssContainerDto> GetAsync(string name) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
var container = await oss.GetAsync(name); |
|||
|
|||
return ObjectMapper.Map<OssContainer, OssContainerDto>(container); |
|||
} |
|||
|
|||
public virtual async Task<OssContainersResultDto> GetListAsync(GetOssContainersInput input) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
|
|||
var containerResponse = await oss.GetListAsync( |
|||
input.Prefix, input.Marker, input.SkipCount, input.MaxResultCount); |
|||
|
|||
return ObjectMapper.Map<GetOssContainersResponse, OssContainersResultDto>(containerResponse); |
|||
} |
|||
|
|||
public virtual async Task<OssObjectsResultDto> GetObjectListAsync(GetOssObjectsInput input) |
|||
{ |
|||
var oss = CreateOssContainer(); |
|||
|
|||
var ossObjectResponse = await oss.GetObjectsAsync( |
|||
input.Bucket, input.Prefix, input.Marker, |
|||
input.Delimiter, input.EncodingType, |
|||
input.SkipCount, input.MaxResultCount); |
|||
|
|||
return ObjectMapper.Map<GetOssObjectsResponse, OssObjectsResultDto>(ossObjectResponse); |
|||
} |
|||
|
|||
protected virtual IOssContainer CreateOssContainer() |
|||
{ |
|||
return OssContainerFactory.Create(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,18 +1,21 @@ |
|||
namespace LINGYUN.Abp.OssManagement |
|||
{ |
|||
public class GetOssContainersRequest |
|||
{ |
|||
public string Prefix { get; } |
|||
public string Marker { get; } |
|||
public int? MaxKeys { get; } |
|||
public GetOssContainersRequest( |
|||
string prefix = null, |
|||
string marker = null, |
|||
int? maxKeys = 10) |
|||
{ |
|||
Prefix = prefix; |
|||
Marker = marker; |
|||
MaxKeys = maxKeys; |
|||
} |
|||
} |
|||
} |
|||
namespace LINGYUN.Abp.OssManagement |
|||
{ |
|||
public class GetOssContainersRequest |
|||
{ |
|||
public string Prefix { get; } |
|||
public string Marker { get; } |
|||
public int Current { get; } |
|||
public int? MaxKeys { get; } |
|||
public GetOssContainersRequest( |
|||
string prefix = null, |
|||
string marker = null, |
|||
int current = 0, |
|||
int? maxKeys = 10) |
|||
{ |
|||
Prefix = prefix; |
|||
Marker = marker; |
|||
Current = current; |
|||
MaxKeys = maxKeys; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,32 +1,35 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
|
|||
namespace LINGYUN.Abp.OssManagement |
|||
{ |
|||
public class GetOssObjectsRequest |
|||
{ |
|||
public string BucketName { get; } |
|||
public string Prefix { get; } |
|||
public string Delimiter { get; } |
|||
public string Marker { get; } |
|||
public string EncodingType { get; } |
|||
public int? MaxKeys { get; } |
|||
public GetOssObjectsRequest( |
|||
[NotNull] string bucketName, |
|||
string prefix = null, |
|||
string marker = null, |
|||
string delimiter = null, |
|||
string encodingType = null, |
|||
int maxKeys = 10) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(bucketName, nameof(bucketName)); |
|||
|
|||
BucketName = bucketName; |
|||
Prefix = prefix; |
|||
Marker = marker; |
|||
Delimiter = delimiter; |
|||
EncodingType = encodingType; |
|||
MaxKeys = maxKeys; |
|||
} |
|||
} |
|||
} |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
|
|||
namespace LINGYUN.Abp.OssManagement |
|||
{ |
|||
public class GetOssObjectsRequest |
|||
{ |
|||
public string BucketName { get; } |
|||
public string Prefix { get; } |
|||
public string Delimiter { get; } |
|||
public string Marker { get; } |
|||
public string EncodingType { get; } |
|||
public int Current { get; } |
|||
public int? MaxKeys { get; } |
|||
public GetOssObjectsRequest( |
|||
[NotNull] string bucketName, |
|||
string prefix = null, |
|||
string marker = null, |
|||
string delimiter = null, |
|||
string encodingType = null, |
|||
int current = 0, |
|||
int maxKeys = 10) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(bucketName, nameof(bucketName)); |
|||
|
|||
BucketName = bucketName; |
|||
Prefix = prefix; |
|||
Marker = marker; |
|||
Delimiter = delimiter; |
|||
EncodingType = encodingType; |
|||
Current = current; |
|||
MaxKeys = maxKeys; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,79 +1,81 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.OssManagement |
|||
{ |
|||
public static class IOssContainerExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// 如果不存在容器则创建
|
|||
/// </summary>
|
|||
/// <param name="ossContainer"></param>
|
|||
/// <param name="name"></param>
|
|||
/// <returns>返回容器信息</returns>
|
|||
public static async Task<OssContainer> CreateIfNotExistsAsync( |
|||
this IOssContainer ossContainer, |
|||
string name) |
|||
{ |
|||
if (! await ossContainer.ExistsAsync(name)) |
|||
{ |
|||
await ossContainer.CreateAsync(name); |
|||
} |
|||
|
|||
return await ossContainer.GetAsync(name); |
|||
} |
|||
|
|||
public static async Task DeleteObjectAsync( |
|||
this IOssContainer ossContainer, |
|||
string bucket, |
|||
string @object, |
|||
string path = "") |
|||
{ |
|||
await ossContainer.DeleteObjectAsync( |
|||
new GetOssObjectRequest(bucket, @object, path)); |
|||
} |
|||
|
|||
public static async Task BulkDeleteObjectsAsync( |
|||
this IOssContainer ossContainer, |
|||
string bucketName, |
|||
ICollection<string> objectNames, |
|||
string path = "") |
|||
{ |
|||
await ossContainer.BulkDeleteObjectsAsync( |
|||
new BulkDeleteObjectRequest(bucketName, objectNames, path)); |
|||
} |
|||
|
|||
public static async Task<GetOssContainersResponse> GetListAsync( |
|||
this IOssContainer ossContainer, |
|||
string prefix = null, |
|||
string marker = null, |
|||
int maxResultCount = 10) |
|||
{ |
|||
return await ossContainer.GetListAsync( |
|||
new GetOssContainersRequest(prefix, marker, maxResultCount)); |
|||
} |
|||
|
|||
public static async Task<OssObject> GetObjectAsync( |
|||
this IOssContainer ossContainer, |
|||
string bucket, |
|||
string @object, |
|||
string path = "") |
|||
{ |
|||
return await ossContainer.GetObjectAsync( |
|||
new GetOssObjectRequest(bucket, @object, path)); |
|||
} |
|||
|
|||
public static async Task<GetOssObjectsResponse> GetObjectsAsync( |
|||
this IOssContainer ossContainer, |
|||
string name, |
|||
string prefix = null, |
|||
string marker = null, |
|||
string delimiter = null, |
|||
string encodingType = null, |
|||
int maxResultCount = 10) |
|||
{ |
|||
return await ossContainer.GetObjectsAsync( |
|||
new GetOssObjectsRequest(name, prefix, marker, delimiter, encodingType, maxResultCount)); |
|||
} |
|||
} |
|||
} |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.OssManagement |
|||
{ |
|||
public static class IOssContainerExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// 如果不存在容器则创建
|
|||
/// </summary>
|
|||
/// <param name="ossContainer"></param>
|
|||
/// <param name="name"></param>
|
|||
/// <returns>返回容器信息</returns>
|
|||
public static async Task<OssContainer> CreateIfNotExistsAsync( |
|||
this IOssContainer ossContainer, |
|||
string name) |
|||
{ |
|||
if (! await ossContainer.ExistsAsync(name)) |
|||
{ |
|||
await ossContainer.CreateAsync(name); |
|||
} |
|||
|
|||
return await ossContainer.GetAsync(name); |
|||
} |
|||
|
|||
public static async Task DeleteObjectAsync( |
|||
this IOssContainer ossContainer, |
|||
string bucket, |
|||
string @object, |
|||
string path = "") |
|||
{ |
|||
await ossContainer.DeleteObjectAsync( |
|||
new GetOssObjectRequest(bucket, @object, path)); |
|||
} |
|||
|
|||
public static async Task BulkDeleteObjectsAsync( |
|||
this IOssContainer ossContainer, |
|||
string bucketName, |
|||
ICollection<string> objectNames, |
|||
string path = "") |
|||
{ |
|||
await ossContainer.BulkDeleteObjectsAsync( |
|||
new BulkDeleteObjectRequest(bucketName, objectNames, path)); |
|||
} |
|||
|
|||
public static async Task<GetOssContainersResponse> GetListAsync( |
|||
this IOssContainer ossContainer, |
|||
string prefix = null, |
|||
string marker = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10) |
|||
{ |
|||
return await ossContainer.GetListAsync( |
|||
new GetOssContainersRequest(prefix, marker, skipCount, maxResultCount)); |
|||
} |
|||
|
|||
public static async Task<OssObject> GetObjectAsync( |
|||
this IOssContainer ossContainer, |
|||
string bucket, |
|||
string @object, |
|||
string path = "") |
|||
{ |
|||
return await ossContainer.GetObjectAsync( |
|||
new GetOssObjectRequest(bucket, @object, path)); |
|||
} |
|||
|
|||
public static async Task<GetOssObjectsResponse> GetObjectsAsync( |
|||
this IOssContainer ossContainer, |
|||
string name, |
|||
string prefix = null, |
|||
string marker = null, |
|||
string delimiter = null, |
|||
string encodingType = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10) |
|||
{ |
|||
return await ossContainer.GetObjectsAsync( |
|||
new GetOssObjectsRequest(name, prefix, marker, delimiter, encodingType, skipCount, maxResultCount)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue