|
@@ -22,13 +22,13 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
public class BlobController : BaseController
|
|
|
{
|
|
|
|
|
|
- private readonly AzureStorageFactory _azureCosmos;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly SnowflakeId _snowflakeId;
|
|
|
private readonly IHttpClientFactory _clientFactory;
|
|
|
|
|
|
- public BlobController(AzureStorageFactory azureCosmos, SnowflakeId snowflakeId, IHttpClientFactory clientFactory)
|
|
|
+ public BlobController(AzureStorageFactory azureStorage, SnowflakeId snowflakeId, IHttpClientFactory clientFactory)
|
|
|
{
|
|
|
- _azureCosmos = azureCosmos;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
_snowflakeId = snowflakeId;
|
|
|
_clientFactory = clientFactory;
|
|
|
}
|
|
@@ -45,7 +45,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
ResponseBuilder builder = new ResponseBuilder();
|
|
|
// Dictionary<string, object> dict = await azureBlobDBRepository.GetBlobSasUri(request.@params,true);
|
|
|
// dict.Add(d.Key, d.Value);
|
|
|
- return builder.Data(_azureCosmos.GetContainerSasUri(request, true)).build();
|
|
|
+ return builder.Data(_azureStorage.GetContainerSasUri(request, true)).build();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 某个文件的上传SAS rcw权限
|
|
@@ -60,7 +60,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
// Dictionary<string,object> dict= await azureBlobDBRepository.GetBlobSasUri(request.@params,false);
|
|
|
// Dictionary<string, object> dict = ;
|
|
|
//dict.Add(d.Key, d.Value);
|
|
|
- return builder.Data(_azureCosmos.GetContainerSasUri(request, false)).build();
|
|
|
+ return builder.Data(_azureStorage.GetContainerSasUri(request, false)).build();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 链接只读(读)
|
|
@@ -79,7 +79,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
bool flg = IsBlobName(BlobName);
|
|
|
if (flg)
|
|
|
{
|
|
|
- return responseBuilder.Data(_azureCosmos.GetBlobSasUriRead(ContainerName, BlobName)).build();
|
|
|
+ return responseBuilder.Data(_azureStorage.GetBlobSasUriRead(ContainerName, BlobName)).build();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -103,10 +103,12 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
bool flg = IsBlobName(BlobName);
|
|
|
if (flg)
|
|
|
{
|
|
|
- BlobAuth blobAuth= azureBlobDBRepository.GetBlobSasUriRead(ContainerName, BlobName);
|
|
|
- string text= await HttpHelper.HttpGetAsync(blobAuth.url + blobAuth.sas);
|
|
|
- JsonElement json = text.FromApiJson<JsonElement>();
|
|
|
- return responseBuilder.Data(json).build();
|
|
|
+ //TODO 需驗證
|
|
|
+ BlobAuth blobAuth= _azureStorage.GetBlobSasUriRead(ContainerName, BlobName);
|
|
|
+ var response= await _clientFactory.CreateClient().GetAsync(new Uri(blobAuth.url + blobAuth.sas));
|
|
|
+ response.EnsureSuccessStatusCode();
|
|
|
+ using var json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
|
|
|
+ return responseBuilder.Data(json.RootElement).build();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -124,7 +126,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
public async Task<BaseResponse> UploadText(JsonElement request)
|
|
|
{
|
|
|
ResponseBuilder responseBuilder = new ResponseBuilder();
|
|
|
- return responseBuilder.Data(await azureBlobDBRepository.UploadFileByContainer("hbcn", request, "exam", SnowflakeId.NextId() + ".json")).build();
|
|
|
+ return responseBuilder.Data(await _azureStorage.UploadFileByContainer("hbcn", request.ToJsonString(), "exam", _snowflakeId.NextId() + ".json")).build();
|
|
|
|
|
|
}
|
|
|
|