Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(BlobStorageAdapter.cs): includes AbsoluteUri in adapter results. #207

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

foreach (var tag in tags)
{
stringFilter += @$"""{tag.Key}"" = '{tag.Value}' AND ";

Check warning on line 36 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Use a StringBuilder instead.

Check warning on line 36 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Use a StringBuilder instead.
}

stringFilter = stringFilter.Substring(0, stringFilter.Length - 4);
Expand All @@ -43,7 +43,7 @@
var blockBlob = client.GetBlockBlobClient(blobItem.BlobName);

await blockBlob.DeleteAsync();
};

Check warning on line 46 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Remove this empty statement.

Check warning on line 46 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Remove this empty statement.
}

///<inheritdoc/>
Expand All @@ -61,7 +61,9 @@
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);
}
Expand All @@ -87,7 +89,7 @@
var stringFilter = string.Empty;
foreach (var tag in tags)
{
stringFilter += @$"""{tag.Key}"" = '{tag.Value}' AND ";

Check warning on line 92 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Use a StringBuilder instead.

Check warning on line 92 in src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs

View workflow job for this annotation

GitHub Actions / call-reusable-build-workflow / build

Use a StringBuilder instead.
}
stringFilter = stringFilter.Substring(0, stringFilter.Length - 4);

Expand All @@ -100,15 +102,16 @@
{
Blob = blob.Value.Content.ToArray(),
Tags = blockBlob.GetTags().Value.Tags,
Name = blobItem.BlobName
Name = blobItem.BlobName,
AbsoluteUri = blockBlob.Uri.AbsoluteUri
};
results.Add(item);
}
return results;
}

///<inheritdoc/>
public async Task UploadBlob(byte[] data, string name, string containerName, IDictionary<string, string>? tags = null)
public async Task<string> UploadBlob(byte[] data, string name, string containerName, IDictionary<string, string>? tags = null)
{
var client = _factory.GetContainerClient(containerName);

Expand All @@ -119,6 +122,8 @@
Tags = tags
};
await blockBlob.UploadAsync(new MemoryStream(data), options);

return blockBlob.Uri.AbsoluteUri;
}

///<inheritdoc/>
Expand All @@ -132,7 +137,8 @@
{
Blob = blob.Value.Content.ToArray(),
Tags = blockBlob.GetTags().Value.Tags,
Name = blobName
Name = blobName,
AbsoluteUri = blockBlob.Uri.AbsoluteUri
};

return item;
Expand All @@ -143,6 +149,8 @@
{
var blobClient = _factory.GetContainerClient(containerName);

var blockBlob = blobClient.GetBlockBlobClient(blobName);

if (!blobClient.CanGenerateSasUri)
{
return null;
Expand All @@ -152,15 +160,15 @@
{
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ILiquidBlobStorageAdapter
/// <param name="name">Blob path.</param>
/// <param name="containerName">Blob container name.</param>
/// <param name="tags">Blob list of tags.</param>
Task UploadBlob(byte[] data, string name, string containerName, IDictionary<string, string>? tags = null);
Task<string> UploadBlob(byte[] data, string name, string containerName, IDictionary<string, string>? tags = null);

/// <summary>
/// Remove blob by id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Company>Avanade Inc.</Company>
<Product>Liquid - Modern Application Framework</Product>
<Copyright>Avanade 2019</Copyright>
<Version>6.0.0-preview-20221201-02</Version>
<Version>6.0.0-preview-20221201-03</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
<Description>
Expand Down
6 changes: 6 additions & 0 deletions src/Liquid.Adapter.AzureStorage/LiquidBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ public class LiquidBlob
/// Nome do arquivo no Storage.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Caminho do blob.
/// </summary>
public string AbsoluteUri { get; set; }

}
}
Loading