Skip to content

Commit

Permalink
fix a list bug on the download page.
Browse files Browse the repository at this point in the history
Improve the logging a bit
  • Loading branch information
paule96 committed Oct 8, 2023
1 parent 4bfb79f commit 33ba2f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
11 changes: 6 additions & 5 deletions src/CZ.Azure.FileExchange/Pages/Download.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using global::Azure.Storage.Blobs
@using global::Azure.Storage.Blobs.Models
@inject HttpClient http
@inject ILogger<Download> logger

<PageTitle>Download - Azure File Exchange</PageTitle>

Expand All @@ -17,25 +18,25 @@
<input type="text" id="txtguid" @bind="Code" @bind:event="oninput" />
<button class="glass" disabled="@(!(Guid.TryParse( Code, out _)))" @onclick="LoadFiles">Load files</button>
</section>

<section>
@foreach (var blob in blobs)
{
<div class="file">
<div class="name">@blob.Name</div>
<div class="size">@AutoFileSize(blob.Properties.ContentLength)</div>
<div class="archive" title="If true, it can take up to 15h to retrive the data!">Archived: @(blob.Properties.AccessTier == AccessTier.Archive)</div>
<div class="archive" title="If true, it can take up to 15h to retrive the data!">Archived:
@(blob.Properties.AccessTier == AccessTier.Archive)</div>
@if (blob.Properties.AccessTier == AccessTier.Archive)
{
<button @onclick="async () => await StartRetrivalFromArchive(blob.Name)"
disabled="@(blob.Properties.ArchiveStatus == ArchiveStatus.RehydratePendingToHot ||
<button @onclick="async () => await StartRetrivalFromArchive(blob.Name)" disabled="@(blob.Properties.ArchiveStatus == ArchiveStatus.RehydratePendingToHot ||
blob.Properties.ArchiveStatus == ArchiveStatus.RehydratePendingToCool)">
Retrive from archive
</button>
}
else
{
<div class="link"><a href="@GetFileLink(blob.Name, (blob.Properties.AccessTier == AccessTier.Archive))"><i class="gg-software-download"></i></a></div>
<div class="link"><a href="@GetFileLink(blob.Name, (blob.Properties.AccessTier == AccessTier.Archive))"><i
class="gg-software-download"></i></a></div>
}

</div>
Expand Down
22 changes: 13 additions & 9 deletions src/CZ.Azure.FileExchange/Pages/Download.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CZ.Azure.FileExchange.Pages;
public partial class Download
{
private string Code { get; set; } = string.Empty;
private List<BlobItem> blobs = new();
private readonly List<BlobItem> blobs = new();
private Uri? sasUrl;
private async Task LoadFiles()
{
Expand All @@ -14,19 +14,16 @@ private async Task LoadFiles()
throw new ArgumentException("You must enter a code");
}

if (this.sasUrl == null)
{
this.sasUrl = new Uri(await this.http.GetStringAsync($"api/GenerateSas?filecode={this.Code}"));
}
// until we don't find a solution to map a SAS uri to a code, we should always get a new uri. (something like a dictionary is maybe to overkill here)
this.sasUrl = new Uri(await this.http.GetStringAsync($"api/GenerateSas?filecode={this.Code}"));

if (this.sasUrl is null)
{
throw new ArgumentException("Sas uri is null");
}

var blobContainerClient = new BlobContainerClient(this.sasUrl);
// Clear the list before using it again.
this.blobs = new();
this.blobs.Clear();
await foreach (var singleBlob in blobContainerClient.GetBlobsAsync())
{
this.blobs.Add(singleBlob);
Expand Down Expand Up @@ -54,7 +51,10 @@ private async Task StartRetrivalFromArchive(string blobName)

if (blob.Properties.AccessTier != AccessTier.Archive)
{
/// TODO: make a message that a not archived blob can't be retrieved
this.logger.LogWarning($"User tried to retrieve a blob from archive, " +
$"but the blob was not in the archive tier." +
$"The blob: '{blob.Name}', tier: '{blob.Properties.AccessTier}'");
/// TODO: make a user visible message that a not archived blob can't be retrieved
return;
}
var blobContainerClient = new BlobContainerClient(this.sasUrl);
Expand All @@ -65,7 +65,9 @@ private async Task StartRetrivalFromArchive(string blobName)
string.Equals(blobProperties.Value.ArchiveStatus, "rehydrate-pending-to-cool", StringComparison.OrdinalIgnoreCase)
)
{
/// TODO: make some message that the blob can't be double retrieved
this.logger.LogWarning($"The blob '{blob.Name}' can't be retrieved because the " +
$"status is {blobProperties.Value.ArchiveStatus}.");
/// TODO: make a user visible message that the blob can't be double retrieved
/// and return
}
await blobClient.SetAccessTierAsync(AccessTier.Hot);
Expand All @@ -79,13 +81,15 @@ private async Task StartRetrivalFromArchive(string blobName)
if (foundBlobs > 0)
{
// TODO: something weird happend. We found for our blob we are looking for, more then one real blob.
this.logger.LogWarning($"The blob '{blobName}' exist more then ones. 🫨");
}
this.blobs[blobListEntryLocation] = updatedBlob;
}
}
else
{
//TODO: some odd state happend. We change the state of the blob but we can't find it in our blobs list
this.logger.LogWarning($"The blob '{blobName}' doesn't exist. 🫨");
}


Expand Down

0 comments on commit 33ba2f1

Please sign in to comment.