|
@@ -24,12 +24,12 @@ namespace TEAMModelOS.Controllers
|
|
|
public class FileController:BaseController
|
|
|
{
|
|
|
private readonly AzureStorageFactory azureTableDBRepository;
|
|
|
- private readonly IAzureBlobDBRepository _azureBlobDBRepository;
|
|
|
- public FileController(AzureStorageFactory _azureTableDBRepository, IAzureBlobDBRepository azureBlobDBRepository
|
|
|
+ // private readonly IAzureBlobDBRepository _azureBlobDBRepository;
|
|
|
+ public FileController(AzureStorageFactory _azureTableDBRepository
|
|
|
)
|
|
|
{
|
|
|
azureTableDBRepository = _azureTableDBRepository;
|
|
|
- _azureBlobDBRepository = azureBlobDBRepository;
|
|
|
+ // _azureBlobDBRepository = azureBlobDBRepository;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -133,172 +133,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 获取某个文件夹下所以文件列表
|
|
|
- /// </summary>
|
|
|
- /// <param name="azureBlobSASDto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("GetBlobDirectory")]
|
|
|
- public async Task<BaseResponse> GetBlobDirectory(JosnRequest<string> azureBlobSASDto)
|
|
|
- {
|
|
|
- ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
- string azureBlobSAS = azureBlobSASDto.@params;
|
|
|
- (string, string) a = BlobUrlString(azureBlobSAS);
|
|
|
- string ContainerName = a.Item1;
|
|
|
- string BlobName = a.Item2;
|
|
|
- bool flg = IsBlobName(BlobName);
|
|
|
- List<BlobFileDto> blobProperties = new List<BlobFileDto>();
|
|
|
- if (flg)
|
|
|
- {
|
|
|
- string[] blobstring = BlobName.Split("/");
|
|
|
- //string SAS = _azureBlobDBRepository.GetBlobSasUriRead(ContainerName, BlobName);
|
|
|
- blobProperties =await _azureBlobDBRepository.GetBlobDirectory(ContainerName, blobstring[0]);
|
|
|
-
|
|
|
- }
|
|
|
- return responseBuilder.Data(blobProperties).build();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 获取 blob文件 共享访问签名 (写,新增)
|
|
|
- /// </summary>
|
|
|
- /// <param name="azureBlobSASDto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("getBlobSAS")]
|
|
|
- public async Task<BaseResponse> GetBlobSAS(JosnRequest<string> azureBlobSASDto)
|
|
|
- {
|
|
|
- ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
- string BlobName = azureBlobSASDto.@params;
|
|
|
- bool flg = IsBlobName(BlobName);
|
|
|
- if (flg)
|
|
|
- {
|
|
|
- string SAS =await _azureBlobDBRepository.GetBlobSasUri(BlobName);
|
|
|
- return responseBuilder.Data(SAS).build();
|
|
|
- }
|
|
|
- else {
|
|
|
- return responseBuilder.Error(ResponseCode.PARAMS_ERROR, "文件名错误").build();
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 获取 blob文件 共享访问签名 (读)
|
|
|
- /// </summary>
|
|
|
- /// <param name="azureBlobSASDto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("getBlobSASRead")]
|
|
|
- public async Task<BaseResponse> GetBlobSASRead(JosnRequest<string> azureBlobSASDto)
|
|
|
- {
|
|
|
- ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
- string azureBlobSAS = azureBlobSASDto.@params;
|
|
|
- (string, string) a = BlobUrlString(azureBlobSAS);
|
|
|
- string ContainerName = a.Item1;
|
|
|
- string BlobName = a.Item2;
|
|
|
- bool flg = IsBlobName(BlobName);
|
|
|
- if (flg)
|
|
|
- {
|
|
|
- var SAS =await _azureBlobDBRepository.GetBlobSasUriRead(ContainerName, BlobName);
|
|
|
- return responseBuilder.Data(SAS).build();
|
|
|
- }
|
|
|
- else {
|
|
|
- return responseBuilder.Error(ResponseCode.PARAMS_ERROR, "文件名错误").build();
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 获取 容器 共享访问签名 (写,新增)
|
|
|
- /// </summary>
|
|
|
- /// <param name="azureBlobSASDto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("getContainerSAS")]
|
|
|
- public async Task<BaseResponse> GetContainerSAS(JosnRequest<string> azureBlobSASDto)
|
|
|
- {
|
|
|
- ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
- (string, string, string) aaa =await _azureBlobDBRepository.GetContainerSasUri();
|
|
|
- string Url = aaa.Item1;
|
|
|
- string Container = aaa.Item2;
|
|
|
- string SAS = aaa.Item3;
|
|
|
- return responseBuilder.Data(new Dictionary<string,object> {
|
|
|
- { "Url",Url },
|
|
|
- {"Container",Container },
|
|
|
- { "SAS",SAS},
|
|
|
- }).build();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 获取 容器 共享访问签名 (读)
|
|
|
- /// </summary>
|
|
|
- /// <param name="azureBlobSASDto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("getContainerSASRead")]
|
|
|
- public async Task<BaseResponse> GetContainerSASRead(JosnRequest<string> azureBlobSASDto)
|
|
|
- {
|
|
|
- ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
- string azureBlobSAS = azureBlobSASDto.@params;
|
|
|
- string ContainerName = ContainerUrlString(azureBlobSAS);
|
|
|
- (string, string) aaa =await _azureBlobDBRepository.GetContainerSasUriRead(ContainerName);
|
|
|
-
|
|
|
- string Url = aaa.Item1;
|
|
|
- string SAS = aaa.Item2;
|
|
|
-
|
|
|
- return responseBuilder.Data(new Dictionary<string, object> {
|
|
|
- { "Url",Url },
|
|
|
- { "SAS",SAS}
|
|
|
- }).build();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 创建共享访问策略 (删除权限)
|
|
|
- /// </summary>
|
|
|
- /// <param name="azureBlobSASDto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("CreateSharedAccessPolicy")]
|
|
|
- public async Task<BaseResponse> CreateSharedAccessPolicyAsync(JosnRequest<AzureBlobSASDto> azureBlobSASDto)
|
|
|
- {
|
|
|
- ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
- AzureBlobSASDto azureBlobSAS = azureBlobSASDto.@params;
|
|
|
- bool flg = await _azureBlobDBRepository.CreateSharedAccessPolicyAsync( azureBlobSAS.PolicyName);
|
|
|
- return responseBuilder.Data(flg).build();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 删除共享访问策略
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("DeleteSharedAccessPolicyAsync")]
|
|
|
- public async Task<BaseResponse> DeleteSharedAccessPolicyAsync(JosnRequest<AzureBlobSASDto> azureBlobSASDto)
|
|
|
- {
|
|
|
- ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
- AzureBlobSASDto azureBlobSAS = azureBlobSASDto.@params;
|
|
|
- await _azureBlobDBRepository.DeleteSharedAccessPolicyAsync( azureBlobSAS.PolicyName);
|
|
|
- return responseBuilder.build();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 删除blob
|
|
|
- /// </summary>
|
|
|
- /// <param name="azureBlobSASDto"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("DeleteBlob")]
|
|
|
- public async Task<BaseResponse> DeleteBlobAsync(JosnRequest<string> bloburl)
|
|
|
- {
|
|
|
- ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
- string URL = bloburl.@params;
|
|
|
- if (!string.IsNullOrEmpty(URL))
|
|
|
- {
|
|
|
- await _azureBlobDBRepository.Deleteblob(URL);
|
|
|
- }
|
|
|
- return responseBuilder.build();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
private static (string, string) BlobUrlString( string sasUrl) {
|
|
|
sasUrl= sasUrl.Substring(8);
|
|
|
string[] sasUrls = sasUrl.Split("/");
|