From 7dbe74822ca67413113f7f06cdc942430d20ea1a Mon Sep 17 00:00:00 2001 From: Luciana Regina Lino Date: Wed, 7 Feb 2024 17:29:08 -0300 Subject: [PATCH] feat(BlobStorageAdapter.cs): includes AbsoluteUri in adapter results. --- .../BlobStorageAdapter.cs | 22 +++++++++++++------ .../ILiquidBlobStorageAdapter.cs | 2 +- .../Liquid.Adapter.AzureStorage.csproj | 2 +- src/Liquid.Adapter.AzureStorage/LiquidBlob.cs | 6 +++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs b/src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs index 5a3ff4c..3673a80 100644 --- a/src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs +++ b/src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs @@ -61,7 +61,9 @@ public async Task> GetAllBlobs(string containerName) var item = new LiquidBlob { Blob = blob.Value.Content.ToArray(), - Name = blobItem.Name + Tags = blockBlob.GetTags().Value.Tags, + Name = blobItem.Name, + AbsoluteUri = blockBlob.Uri.AbsoluteUri }; results.Add(item); } @@ -100,7 +102,8 @@ public async Task> ReadBlobsByTags(IDictionary { Blob = blob.Value.Content.ToArray(), Tags = blockBlob.GetTags().Value.Tags, - Name = blobItem.BlobName + Name = blobItem.BlobName, + AbsoluteUri = blockBlob.Uri.AbsoluteUri }; results.Add(item); } @@ -108,7 +111,7 @@ public async Task> ReadBlobsByTags(IDictionary } /// - public async Task UploadBlob(byte[] data, string name, string containerName, IDictionary? tags = null) + public async Task UploadBlob(byte[] data, string name, string containerName, IDictionary? tags = null) { var client = _factory.GetContainerClient(containerName); @@ -119,6 +122,8 @@ public async Task UploadBlob(byte[] data, string name, string containerName, IDi Tags = tags }; await blockBlob.UploadAsync(new MemoryStream(data), options); + + return blockBlob.Uri.AbsoluteUri; } /// @@ -132,7 +137,8 @@ public async Task ReadBlobsByName(string blobName, string containerN { Blob = blob.Value.Content.ToArray(), Tags = blockBlob.GetTags().Value.Tags, - Name = blobName + Name = blobName, + AbsoluteUri = blockBlob.Uri.AbsoluteUri }; return item; @@ -143,6 +149,8 @@ public async Task ReadBlobsByName(string blobName, string containerN { var blobClient = _factory.GetContainerClient(containerName); + var blockBlob = blobClient.GetBlockBlobClient(blobName); + if (!blobClient.CanGenerateSasUri) { return null; @@ -152,15 +160,15 @@ public async Task ReadBlobsByName(string blobName, string containerN { BlobContainerName = blobClient.Name, BlobName = blobName, - Resource = "b" + Resource = "b", }; sasBuilder.ExpiresOn = expiresOn; sasBuilder.SetPermissions(permissions); - var sasURI = blobClient.GenerateSasUri(sasBuilder); + var sasURI = blockBlob.GenerateSasUri(sasBuilder); - return sasURI.AbsolutePath; + return sasURI.AbsoluteUri; } } } diff --git a/src/Liquid.Adapter.AzureStorage/ILiquidBlobStorageAdapter.cs b/src/Liquid.Adapter.AzureStorage/ILiquidBlobStorageAdapter.cs index 80212fa..75e0452 100644 --- a/src/Liquid.Adapter.AzureStorage/ILiquidBlobStorageAdapter.cs +++ b/src/Liquid.Adapter.AzureStorage/ILiquidBlobStorageAdapter.cs @@ -14,7 +14,7 @@ public interface ILiquidBlobStorageAdapter /// Blob path. /// Blob container name. /// Blob list of tags. - Task UploadBlob(byte[] data, string name, string containerName, IDictionary? tags = null); + Task UploadBlob(byte[] data, string name, string containerName, IDictionary? tags = null); /// /// Remove blob by id. diff --git a/src/Liquid.Adapter.AzureStorage/Liquid.Adapter.AzureStorage.csproj b/src/Liquid.Adapter.AzureStorage/Liquid.Adapter.AzureStorage.csproj index 356a8e1..f4cf27c 100644 --- a/src/Liquid.Adapter.AzureStorage/Liquid.Adapter.AzureStorage.csproj +++ b/src/Liquid.Adapter.AzureStorage/Liquid.Adapter.AzureStorage.csproj @@ -8,7 +8,7 @@ Avanade Inc. Liquid - Modern Application Framework Avanade 2019 - 6.0.0-preview-20221201-02 + 6.0.0-preview-20221201-03 true true diff --git a/src/Liquid.Adapter.AzureStorage/LiquidBlob.cs b/src/Liquid.Adapter.AzureStorage/LiquidBlob.cs index 7685d61..1f9489b 100644 --- a/src/Liquid.Adapter.AzureStorage/LiquidBlob.cs +++ b/src/Liquid.Adapter.AzureStorage/LiquidBlob.cs @@ -22,5 +22,11 @@ public class LiquidBlob /// Nome do arquivo no Storage. /// public string Name { get; set; } + + /// + /// Caminho do blob. + /// + public string AbsoluteUri { get; set; } + } }