Initial commit
This commit is contained in:
commit
77d35ff965
51 changed files with 5591 additions and 0 deletions
287
Pages/Azure/Container.cshtml
Normal file
287
Pages/Azure/Container.cshtml
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
@page
|
||||
@model PlanTempusAdmin.Pages.Azure.ContainerModel
|
||||
@{
|
||||
ViewData["Title"] = $"Container: {Model.Name}";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<div class="breadcrumb">
|
||||
<a href="/Azure">Azure Storage</a>
|
||||
<span class="separator">/</span>
|
||||
@if (string.IsNullOrEmpty(Model.Prefix))
|
||||
{
|
||||
<span>@Model.Name</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a href="/Azure/Container?name=@Model.Name">@Model.Name</a>
|
||||
var parts = Model.Prefix.Split('/').Where(p => !string.IsNullOrEmpty(p)).ToList();
|
||||
var currentPath = "";
|
||||
foreach (var part in parts)
|
||||
{
|
||||
currentPath += part + "/";
|
||||
<span class="separator">/</span>
|
||||
if (currentPath == Model.Prefix + "/")
|
||||
{
|
||||
<span>@part</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a href="/Azure/Container?name=@Model.Name&prefix=@currentPath">@part</a>
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<h1 class="page-title">@Model.Name</h1>
|
||||
<p class="page-subtitle">@Model.Details.BlobCount filer · @FormatBytes(Model.Details.TotalSize)</p>
|
||||
</div>
|
||||
|
||||
@if (!Model.IsConnected)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="text-danger">Kan ikke forbinde til Azure Storage</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<!-- Directories -->
|
||||
@if (Model.Details.Prefixes.Count > 0)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="card-header">Mapper</div>
|
||||
<div class="folder-grid">
|
||||
@foreach (var prefix in Model.Details.Prefixes)
|
||||
{
|
||||
var folderName = prefix.Split('/').Last(p => !string.IsNullOrEmpty(p));
|
||||
<a href="/Azure/Container?name=@Model.Name&prefix=@(prefix)/" class="folder-item">
|
||||
<span class="folder-icon">📁</span>
|
||||
<span class="folder-name">@folderName</span>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Files -->
|
||||
<div class="card mt-2">
|
||||
<div class="card-header">
|
||||
Filer
|
||||
<span class="header-meta">@Model.Details.Blobs.Count filer</span>
|
||||
</div>
|
||||
@if (Model.Details.Blobs.Count == 0)
|
||||
{
|
||||
<div class="card-body">
|
||||
<p class="text-muted">Ingen filer i denne mappe</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Navn</th>
|
||||
<th>Størrelse</th>
|
||||
<th>Type</th>
|
||||
<th>Tier</th>
|
||||
<th>Ændret</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var blob in Model.Details.Blobs)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<span class="file-icon">@GetFileIcon(blob.Name)</span>
|
||||
<code class="blob-name" title="@blob.Name">@blob.FileName</code>
|
||||
</td>
|
||||
<td>@FormatBytes(blob.Size)</td>
|
||||
<td><span class="badge">@(blob.ContentType ?? "-")</span></td>
|
||||
<td>
|
||||
@if (!string.IsNullOrEmpty(blob.AccessTier))
|
||||
{
|
||||
<span class="badge badge-tier @GetTierClass(blob.AccessTier)">@blob.AccessTier</span>
|
||||
}
|
||||
</td>
|
||||
<td>@FormatTimeAgo(blob.LastModified)</td>
|
||||
<td class="actions">
|
||||
<a href="/Azure/Container?name=@Model.Name&blob=@blob.Name&handler=Download"
|
||||
class="btn btn-sm" title="Download">⬇️</a>
|
||||
<form method="post" asp-page-handler="Delete" style="display:inline;">
|
||||
<input type="hidden" name="container" value="@Model.Name" />
|
||||
<input type="hidden" name="blob" value="@blob.Name" />
|
||||
<button type="submit" class="btn btn-sm btn-danger"
|
||||
onclick="return confirm('Slet @blob.FileName?')" title="Slet">🗑️</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="mt-2">
|
||||
<a href="/Azure" class="btn">← Tilbage til oversigt</a>
|
||||
</div>
|
||||
}
|
||||
|
||||
<style>
|
||||
.breadcrumb {
|
||||
font-size: 12px;
|
||||
color: var(--muted-color);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.breadcrumb a {
|
||||
color: var(--primary-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.breadcrumb a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.breadcrumb .separator {
|
||||
margin: 0 6px;
|
||||
color: var(--muted-color);
|
||||
}
|
||||
|
||||
.folder-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 8px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.folder-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 12px;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 4px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.folder-item:hover {
|
||||
background: var(--border-color);
|
||||
}
|
||||
|
||||
.folder-icon {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.folder-name {
|
||||
font-size: 12px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.file-icon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.blob-name {
|
||||
max-width: 300px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.header-meta {
|
||||
float: right;
|
||||
font-weight: normal;
|
||||
font-size: 11px;
|
||||
color: var(--muted-color);
|
||||
}
|
||||
|
||||
.badge-tier {
|
||||
font-size: 9px;
|
||||
padding: 2px 6px;
|
||||
}
|
||||
|
||||
.badge-tier.hot {
|
||||
background: rgba(240, 165, 0, 0.2);
|
||||
color: var(--warning-color);
|
||||
}
|
||||
|
||||
.badge-tier.cool {
|
||||
background: rgba(0, 123, 255, 0.2);
|
||||
color: #007bff;
|
||||
}
|
||||
|
||||
.badge-tier.archive {
|
||||
background: rgba(108, 117, 125, 0.2);
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.actions {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.actions .btn {
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: transparent;
|
||||
border-color: var(--danger-color);
|
||||
color: var(--danger-color);
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: var(--danger-color);
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
@functions {
|
||||
string FormatBytes(long bytes)
|
||||
{
|
||||
if (bytes == 0) return "0 B";
|
||||
var sizes = new[] { "B", "KB", "MB", "GB", "TB" };
|
||||
var i = (int)Math.Floor(Math.Log(bytes) / Math.Log(1024));
|
||||
return $"{Math.Round(bytes / Math.Pow(1024, i), 1)} {sizes[i]}";
|
||||
}
|
||||
|
||||
string FormatTimeAgo(DateTimeOffset? time)
|
||||
{
|
||||
if (!time.HasValue) return "-";
|
||||
var diff = DateTimeOffset.Now - time.Value;
|
||||
if (diff.TotalMinutes < 1) return "lige nu";
|
||||
if (diff.TotalMinutes < 60) return $"{(int)diff.TotalMinutes}m siden";
|
||||
if (diff.TotalHours < 24) return $"{(int)diff.TotalHours}t siden";
|
||||
if (diff.TotalDays < 7) return $"{(int)diff.TotalDays}d siden";
|
||||
return time.Value.ToString("dd/MM HH:mm");
|
||||
}
|
||||
|
||||
string GetFileIcon(string name)
|
||||
{
|
||||
if (name.EndsWith(".tar.gz")) return "📦";
|
||||
if (name.EndsWith(".gz") || name.EndsWith(".zip") || name.EndsWith(".7z")) return "📦";
|
||||
if (name.EndsWith(".sql")) return "🐘";
|
||||
if (name.EndsWith(".bak")) return "💾";
|
||||
if (name.EndsWith(".log")) return "📜";
|
||||
if (name.EndsWith(".json")) return "📋";
|
||||
if (name.EndsWith(".xml")) return "📄";
|
||||
return "📄";
|
||||
}
|
||||
|
||||
string GetTierClass(string tier)
|
||||
{
|
||||
var t = tier.ToLower();
|
||||
if (t == "hot") return "hot";
|
||||
if (t == "cool") return "cool";
|
||||
if (t == "archive") return "archive";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
57
Pages/Azure/Container.cshtml.cs
Normal file
57
Pages/Azure/Container.cshtml.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
235
Pages/Azure/Index.cshtml
Normal file
235
Pages/Azure/Index.cshtml
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
@page
|
||||
@model PlanTempusAdmin.Pages.Azure.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Azure Storage";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Azure Blob Storage</h1>
|
||||
<p class="page-subtitle">@Model.Dashboard.AccountName</p>
|
||||
</div>
|
||||
|
||||
@if (!Model.IsConnected)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="text-danger">Kan ikke forbinde til Azure Storage</p>
|
||||
<p class="text-muted">Tjek at <code>ConnectionStrings:AzureStorage</code> er konfigureret i appsettings.json</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
var d = Model.Dashboard;
|
||||
|
||||
<!-- Hero Stats -->
|
||||
<div class="status-grid">
|
||||
<div class="status-item">
|
||||
<div class="status-label">Status</div>
|
||||
<div class="status-value success">ONLINE</div>
|
||||
<div class="status-detail">@d.AccountName</div>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<div class="status-label">Containers</div>
|
||||
<div class="status-value">@d.TotalContainers</div>
|
||||
<div class="status-detail">@d.TotalBlobs blobs total</div>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<div class="status-label">Total Størrelse</div>
|
||||
<div class="status-value">@FormatBytes(d.TotalSize)</div>
|
||||
<div class="status-detail">Backup: @FormatBytes(d.BackupTotalSize)</div>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<div class="status-label">Sidste Upload</div>
|
||||
<div class="status-value @(d.LastBackupUpload.HasValue && (DateTimeOffset.Now - d.LastBackupUpload.Value).TotalHours < 24 ? "success" : "warning")">
|
||||
@FormatTimeAgo(d.LastBackupUpload)
|
||||
</div>
|
||||
<div class="status-detail">@d.BackupFileCount backup filer</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-grid mt-2">
|
||||
<!-- Containers -->
|
||||
<div class="card">
|
||||
<div class="card-header">Containers</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Navn</th>
|
||||
<th>Blobs</th>
|
||||
<th>Størrelse</th>
|
||||
<th>Ændret</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var container in d.Containers)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@if (container.Name.Contains("backup", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
<span class="container-icon">💾</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="container-icon">📦</span>
|
||||
}
|
||||
<code>@container.Name</code>
|
||||
</td>
|
||||
<td>@container.BlobCount</td>
|
||||
<td>@FormatBytes(container.TotalSize)</td>
|
||||
<td>@FormatTimeAgo(container.LastModified)</td>
|
||||
<td>
|
||||
<a href="/Azure/Container?name=@container.Name" class="btn btn-sm">Åbn</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Recent Uploads -->
|
||||
<div class="card">
|
||||
<div class="card-header">Seneste Uploads</div>
|
||||
<div class="card-body compact-list">
|
||||
@if (d.RecentBlobs.Count == 0)
|
||||
{
|
||||
<p class="text-muted">Ingen filer endnu</p>
|
||||
}
|
||||
@foreach (var blob in d.RecentBlobs)
|
||||
{
|
||||
<div class="list-item">
|
||||
<div class="item-main">
|
||||
<span class="file-icon">@GetFileIcon(blob.Name)</span>
|
||||
<code class="blob-name" title="@blob.Name">@blob.FileName</code>
|
||||
@if (!string.IsNullOrEmpty(blob.AccessTier))
|
||||
{
|
||||
<span class="badge badge-tier">@blob.AccessTier</span>
|
||||
}
|
||||
</div>
|
||||
<div class="item-meta">
|
||||
@FormatBytes(blob.Size) · @FormatTimeAgo(blob.LastModified)
|
||||
@if (!string.IsNullOrEmpty(blob.Directory))
|
||||
{
|
||||
<text>· @blob.Directory</text>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Last Updated -->
|
||||
<div class="last-updated mt-2">
|
||||
Opdateret: @DateTime.Now.ToString("HH:mm:ss")
|
||||
</div>
|
||||
}
|
||||
|
||||
<style>
|
||||
.status-detail {
|
||||
font-size: 10px;
|
||||
color: var(--muted-color);
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.dashboard-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.container-icon, .file-icon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.compact-list {
|
||||
padding: 8px 16px !important;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.list-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.item-main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.item-meta {
|
||||
font-size: 10px;
|
||||
color: var(--muted-color);
|
||||
margin-top: 4px;
|
||||
padding-left: 28px;
|
||||
}
|
||||
|
||||
.blob-name {
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.badge-tier {
|
||||
background: var(--border-color);
|
||||
color: var(--muted-color);
|
||||
font-size: 9px;
|
||||
padding: 2px 6px;
|
||||
}
|
||||
|
||||
.last-updated {
|
||||
text-align: center;
|
||||
font-size: 10px;
|
||||
color: var(--muted-color);
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.success { color: var(--success-color); }
|
||||
.warning { color: var(--warning-color); }
|
||||
|
||||
@@media (max-width: 1000px) {
|
||||
.dashboard-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@functions {
|
||||
string FormatBytes(long bytes)
|
||||
{
|
||||
if (bytes == 0) return "0 B";
|
||||
var sizes = new[] { "B", "KB", "MB", "GB", "TB" };
|
||||
var i = (int)Math.Floor(Math.Log(bytes) / Math.Log(1024));
|
||||
return $"{Math.Round(bytes / Math.Pow(1024, i), 1)} {sizes[i]}";
|
||||
}
|
||||
|
||||
string FormatTimeAgo(DateTimeOffset? time)
|
||||
{
|
||||
if (!time.HasValue) return "-";
|
||||
var diff = DateTimeOffset.Now - time.Value;
|
||||
if (diff.TotalMinutes < 1) return "lige nu";
|
||||
if (diff.TotalMinutes < 60) return $"{(int)diff.TotalMinutes}m siden";
|
||||
if (diff.TotalHours < 24) return $"{(int)diff.TotalHours}t siden";
|
||||
if (diff.TotalDays < 7) return $"{(int)diff.TotalDays}d siden";
|
||||
return time.Value.ToString("dd/MM");
|
||||
}
|
||||
|
||||
string GetFileIcon(string name)
|
||||
{
|
||||
if (name.EndsWith(".tar.gz")) return "📦";
|
||||
if (name.EndsWith(".gz") || name.EndsWith(".zip") || name.EndsWith(".7z")) return "📦";
|
||||
if (name.EndsWith(".sql")) return "🐘";
|
||||
if (name.EndsWith(".bak")) return "💾";
|
||||
if (name.EndsWith(".log")) return "📜";
|
||||
if (name.EndsWith(".json")) return "📋";
|
||||
if (name.EndsWith(".xml")) return "📄";
|
||||
return "📄";
|
||||
}
|
||||
}
|
||||
27
Pages/Azure/Index.cshtml.cs
Normal file
27
Pages/Azure/Index.cshtml.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using PlanTempusAdmin.Models;
|
||||
using PlanTempusAdmin.Services;
|
||||
|
||||
namespace PlanTempusAdmin.Pages.Azure;
|
||||
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly AzureStorageService _azureService;
|
||||
|
||||
public bool IsConnected { get; set; }
|
||||
public AzureStorageDashboard Dashboard { get; set; } = new();
|
||||
|
||||
public IndexModel(AzureStorageService azureService)
|
||||
{
|
||||
_azureService = azureService;
|
||||
}
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
IsConnected = await _azureService.TestConnectionAsync();
|
||||
if (IsConnected)
|
||||
{
|
||||
Dashboard = await _azureService.GetDashboardAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue