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

Delete image when the corresponding model is deleted #69

Merged
merged 1 commit into from
Jan 10, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public async Task<IActionResult> Delete(string deviceModelID)
}
}

// Image deletion
await this.deviceModelImageManager.DeleteDeviceModelImageAsync(deviceModelID);

var result = await this.tableClientFactory
.GetDeviceTemplates()
.DeleteEntityAsync(DefaultPartitionKey, deviceModelID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ public async Task<Uri> ChangeDeviceModelImageAsync(string deviceModelId, Stream
return blobClient.Uri;
}

public async Task DeleteDeviceModelImageAsync(string deviceModelId)
{
var blobContainer = this.blobService.GetBlobContainerClient(ImageContainerName);

var blobClient = blobContainer.GetBlobClient(deviceModelId);

this.logger.LogInformation($"Deleting from Blob storage :\n\t {blobClient.Uri}\n");

await blobClient.DeleteAsync();
}

public Uri ComputeImageUri(string deviceModelId)
{
var imageName = string.IsNullOrWhiteSpace(deviceModelId) ? DefaultImageName : deviceModelId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ namespace AzureIoTHub.Portal.Server.Managers

public interface IDeviceModelImageManager
{
Uri ComputeImageUri(string deviceModelId);

Task<Uri> ChangeDeviceModelImageAsync(string deviceModelId, Stream stream);

Task DeleteDeviceModelImageAsync(string deviceModelId);

Uri ComputeImageUri(string deviceModelId);

Task InitializeDefaultImageBlob();
}
}