57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using PlanTempusAdmin.Models;
|
|
using PlanTempusAdmin.Services;
|
|
|
|
namespace PlanTempusAdmin.Pages.Azure;
|
|
|
|
public class ContainerModel : PageModel
|
|
{
|
|
private readonly AzureStorageService _azureService;
|
|
|
|
[BindProperty(SupportsGet = true)]
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
[BindProperty(SupportsGet = true)]
|
|
public string? Prefix { get; set; }
|
|
|
|
public ContainerDetails Details { get; set; } = new();
|
|
public bool IsConnected { get; set; }
|
|
|
|
public ContainerModel(AzureStorageService azureService)
|
|
{
|
|
_azureService = azureService;
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetAsync()
|
|
{
|
|
if (string.IsNullOrEmpty(Name))
|
|
{
|
|
return RedirectToPage("/Azure/Index");
|
|
}
|
|
|
|
IsConnected = await _azureService.TestConnectionAsync();
|
|
if (IsConnected)
|
|
{
|
|
Details = await _azureService.GetContainerDetailsAsync(Name, Prefix, limit: 200);
|
|
}
|
|
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostDeleteAsync(string container, string blob)
|
|
{
|
|
await _azureService.DeleteBlobAsync(container, blob);
|
|
return RedirectToPage(new { name = container, prefix = Prefix });
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetDownloadAsync(string container, string blob)
|
|
{
|
|
var url = await _azureService.GetBlobDownloadUrlAsync(container, blob);
|
|
if (url == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return Redirect(url);
|
|
}
|
|
}
|