CDN flag change

This commit is contained in:
dingo
2026-03-03 17:05:27 -05:00
parent 551610a8ee
commit ba04911acc
8 changed files with 303 additions and 11 deletions
@@ -15,7 +15,7 @@
</div>
<p class="text-muted">
All assets and animations flagged as AI-generated across the card catalog.
All catalog assets, animation bindings, and generic CDN uploads flagged as AI-generated.
</p>
@if (_loading)
@@ -24,6 +24,54 @@
}
else
{
<!-- Generic CDN Uploads -->
<div class="card shadow-sm mb-4">
<div class="card-header fw-medium d-flex justify-content-between align-items-center">
<span>
<i class="bi bi-hdd-network me-2"></i>Generic CDN Uploads
<span class="badge bg-warning text-dark ms-2">@_cdnUploads.Count AI-generated</span>
</span>
</div>
<div class="card-body p-0">
@if (_cdnUploads.Count == 0)
{
<p class="text-muted p-3 mb-0">No AI-generated generic CDN uploads.</p>
}
else
{
<table class="table table-sm table-hover mb-0">
<thead class="table-light">
<tr>
<th>Prefix</th>
<th>Object Key</th>
<th>MIME</th>
<th>CDN URL</th>
<th>Uploaded</th>
</tr>
</thead>
<tbody>
@foreach (var item in _cdnUploads)
{
<tr>
<td><span class="badge bg-secondary">@(!string.IsNullOrWhiteSpace(item.Prefix) ? item.Prefix : "/")</span></td>
<td class="font-monospace small">@item.ObjectKey</td>
<td class="text-muted small">@(!string.IsNullOrWhiteSpace(item.ContentType) ? item.ContentType : "—")</td>
<td>
<a href="@item.PublicUrl" target="_blank"
class="text-decoration-none small font-monospace">
@TruncateUrl(item.PublicUrl)
<i class="bi bi-box-arrow-up-right ms-1"></i>
</a>
</td>
<td class="text-muted small">@item.UploadedAt.ToString("yyyy-MM-dd")</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
<!-- Static Assets -->
<div class="card shadow-sm mb-4">
<div class="card-header fw-medium d-flex justify-content-between align-items-center">
@@ -166,8 +214,16 @@ else
string? ActionName,
string? CdnUrl);
private record CdnUploadRow(
string Prefix,
string ObjectKey,
string? ContentType,
string PublicUrl,
DateTimeOffset UploadedAt);
private List<AssetRow> _assets = new();
private List<AnimationRow> _animations = new();
private List<CdnUploadRow> _cdnUploads = new();
protected override async Task OnInitializedAsync() => await LoadAsync();
@@ -203,6 +259,18 @@ else
a.AnimationCdnUrl))
.ToListAsync();
_cdnUploads = await Db.CdnUploadRecords
.Where(r => r.IsAiGenerated)
.OrderBy(r => r.Prefix)
.ThenBy(r => r.ObjectKey)
.Select(r => new CdnUploadRow(
r.Prefix,
r.ObjectKey,
r.ContentType,
r.PublicUrl,
r.UploadedAt))
.ToListAsync();
_loading = false;
}
@@ -3,11 +3,14 @@
@using Amazon.S3
@using Amazon.S3.Model
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.EntityFrameworkCore
@using Microsoft.Extensions.Options
@using SOR.Cdn
@using SOR.Database.Contexts
@inject IAmazonS3 S3
@inject IOptions<CdnOptions> CdnOptionsAccessor
@inject IJSRuntime Js
@inject CatalogDbContext Db
<PageTitle>CDN Browser - SOR Admin</PageTitle>
@@ -88,6 +91,10 @@
Upload destination:
<span class="font-monospace">@(_activePrefixDisplay)</span>
</div>
<div class="form-check mb-2">
<input @bind="_uploadIsAiGenerated" class="form-check-input" type="checkbox" id="cdnUploadAi" />
<label class="form-check-label small" for="cdnUploadAi">AI-generated</label>
</div>
<label class="btn btn-sm btn-primary @(_uploading ? "disabled" : "")">
@if (_uploading)
{
@@ -118,6 +125,10 @@
<div class="text-muted">Target Key</div>
<div class="font-monospace text-break">@_replaceTarget.Key</div>
</div>
<div class="form-check mb-2">
<input @bind="_replaceIsAiGenerated" class="form-check-input" type="checkbox" id="cdnReplaceAi" />
<label class="form-check-label small" for="cdnReplaceAi">AI-generated</label>
</div>
<div class="d-flex gap-2">
<label class="btn btn-sm btn-warning @(_replacing ? "disabled" : "")">
@if (_replacing)
@@ -165,6 +176,7 @@
<thead class="sticky-top bg-body">
<tr>
<th>Key</th>
<th style="width:90px">AI</th>
<th style="width:110px">Size</th>
<th style="width:180px">Modified</th>
<th style="width:270px">Actions</th>
@@ -176,6 +188,16 @@
var row = item;
<tr class="@(_replaceTarget?.Key == row.Key ? "table-warning" : "")">
<td class="font-monospace small text-break align-middle">@row.Key</td>
<td class="align-middle">
@if (row.IsAiGenerated)
{
<span class="badge bg-warning text-dark">AI</span>
}
else
{
<span class="text-muted small">No</span>
}
</td>
<td class="align-middle">@FormatBytes(row.Size)</td>
<td class="align-middle text-muted small">@row.LastModified.ToString("yyyy-MM-dd HH:mm UTC")</td>
<td class="align-middle">
@@ -251,6 +273,8 @@
private bool _loading;
private bool _uploading;
private bool _replacing;
private bool _uploadIsAiGenerated;
private bool _replaceIsAiGenerated;
private bool _hasMore;
private CdnObjectRow? _replaceTarget;
@@ -317,6 +341,17 @@
};
var response = await S3.ListObjectsV2Async(request);
var keys = response.S3Objects
.Where(o => !string.IsNullOrWhiteSpace(o.Key) && !o.Key.EndsWith('/'))
.Select(o => o.Key)
.ToList();
var aiFlags = keys.Count == 0
? new Dictionary<string, bool>(StringComparer.Ordinal)
: await Db.CdnUploadRecords
.Where(r => keys.Contains(r.ObjectKey))
.ToDictionaryAsync(r => r.ObjectKey, r => r.IsAiGenerated);
foreach (var obj in response.S3Objects)
{
if (string.IsNullOrWhiteSpace(obj.Key) || obj.Key.EndsWith('/'))
@@ -328,6 +363,7 @@
Size = obj.Size,
LastModified = obj.LastModified.ToUniversalTime(),
PublicUrl = BuildPublicUrl(obj.Key),
IsAiGenerated = aiFlags.GetValueOrDefault(obj.Key, false),
});
}
@@ -358,6 +394,7 @@
{
var key = $"{_activePrefix}{file.Name}";
await UploadFileToKeyAsync(key, file);
await UpsertUploadRecordAsync(key, file.ContentType, _uploadIsAiGenerated);
_message = $"Uploaded {file.Name}.";
_isError = false;
await LoadAsync(reset: true);
@@ -385,6 +422,7 @@
try
{
await UploadFileToKeyAsync(_replaceTarget.Key, file);
await UpsertUploadRecordAsync(_replaceTarget.Key, file.ContentType, _replaceIsAiGenerated);
_message = $"Replaced {_replaceTarget.Key}.";
_isError = false;
await LoadAsync(reset: true);
@@ -410,6 +448,13 @@
var options = CdnOptionsAccessor.Value;
await S3.DeleteObjectAsync(options.BucketName, item.Key);
var record = await Db.CdnUploadRecords.FirstOrDefaultAsync(r => r.ObjectKey == item.Key);
if (record is not null)
{
Db.CdnUploadRecords.Remove(record);
await Db.SaveChangesAsync();
}
_items.Remove(item);
if (_replaceTarget?.Key == item.Key)
_replaceTarget = null;
@@ -446,12 +491,14 @@
private void SelectReplaceTarget(CdnObjectRow item)
{
_replaceTarget = item;
_replaceIsAiGenerated = item.IsAiGenerated;
_message = null;
}
private void ClearReplaceTarget()
{
_replaceTarget = null;
_replaceIsAiGenerated = false;
}
private async Task UploadFileToKeyAsync(string key, IBrowserFile file)
@@ -476,6 +523,28 @@
await S3.PutObjectAsync(request);
}
private async Task UpsertUploadRecordAsync(string key, string? contentType, bool isAiGenerated)
{
var record = await Db.CdnUploadRecords.FirstOrDefaultAsync(r => r.ObjectKey == key);
if (record is null)
{
record = new SOR.Database.Entities.Catalog.CdnUploadRecord
{
Id = Guid.NewGuid(),
ObjectKey = key,
};
Db.CdnUploadRecords.Add(record);
}
record.Prefix = ExtractPrefix(key);
record.PublicUrl = BuildPublicUrl(key);
record.ContentType = string.IsNullOrWhiteSpace(contentType) ? null : contentType;
record.IsAiGenerated = isAiGenerated;
record.UploadedAt = DateTimeOffset.UtcNow;
await Db.SaveChangesAsync();
}
private string NormalizePrefix(string raw)
{
var prefix = raw.Trim().Trim('/');
@@ -486,7 +555,20 @@
private string BuildPublicUrl(string key)
{
return $"{CdnOptionsAccessor.Value.PublicBaseUrl.TrimEnd('/')}/{key}";
var options = CdnOptionsAccessor.Value;
var baseUrl = options.PublicBaseUrl.TrimEnd('/');
var bucketSegment = options.BucketName.Trim('/');
if (baseUrl.EndsWith("/" + bucketSegment, StringComparison.OrdinalIgnoreCase))
return $"{baseUrl}/{key}";
return $"{baseUrl}/{bucketSegment}/{key}";
}
private string ExtractPrefix(string key)
{
var slash = key.LastIndexOf('/');
return slash <= 0 ? string.Empty : key[..slash];
}
private string FormatBytes(long bytes)
@@ -506,5 +588,6 @@
public long Size { get; set; }
public DateTime LastModified { get; set; }
public string PublicUrl { get; set; } = string.Empty;
public bool IsAiGenerated { get; set; }
}
}
@@ -25,6 +25,7 @@ public sealed class CatalogDbContext : DbContext
public DbSet<CardDefinition> CardDefinitions => Set<CardDefinition>();
public DbSet<CardAsset> CardAssets => Set<CardAsset>();
public DbSet<CardAnimationBinding> AnimationBindings => Set<CardAnimationBinding>();
public DbSet<CdnUploadRecord> CdnUploadRecords => Set<CdnUploadRecord>();
protected override void OnModelCreating(ModelBuilder builder)
{
@@ -114,5 +115,17 @@ public sealed class CatalogDbContext : DbContext
// One action name per card — no duplicate "attack" bindings.
e.HasIndex(a => new { a.CardDefinitionId, a.ActionName }).IsUnique();
});
builder.Entity<CdnUploadRecord>(e =>
{
e.ToTable("cdn_upload_records");
e.HasKey(r => r.Id);
e.Property(r => r.ObjectKey).IsRequired();
e.Property(r => r.Prefix).IsRequired();
e.Property(r => r.PublicUrl).IsRequired();
e.HasIndex(r => r.ObjectKey).IsUnique();
e.HasIndex(r => r.Prefix);
e.HasIndex(r => r.IsAiGenerated);
});
}
}
@@ -0,0 +1,29 @@
namespace SOR.Database.Entities.Catalog;
/// <summary>
/// Tracks generic CDN uploads made through the admin portal.
/// This is separate from card-linked asset records so arbitrary files
/// (UI graphics, config data, music, SFX, models, etc.) can still carry
/// provenance metadata such as whether they were AI-generated.
/// </summary>
public sealed class CdnUploadRecord
{
public Guid Id { get; set; } = Guid.NewGuid();
/// <summary>S3 object key within the configured bucket.</summary>
public string ObjectKey { get; set; } = string.Empty;
/// <summary>Logical top-level or nested folder prefix, e.g. "graphics" or "models/ui".</summary>
public string Prefix { get; set; } = string.Empty;
/// <summary>Publicly accessible CDN URL for the uploaded object.</summary>
public string PublicUrl { get; set; } = string.Empty;
/// <summary>Best-known MIME type for the object.</summary>
public string? ContentType { get; set; }
/// <summary>Whether the object was AI-generated.</summary>
public bool IsAiGenerated { get; set; }
public DateTimeOffset UploadedAt { get; set; }
}
+7 -7
View File
@@ -23,14 +23,14 @@ public enum Affinity
// ── Standard non-basic (two-basic combinations) ───────────────────────
Ocean, // Lake + Lake
Island, // Lake + Hill
Marsh, // Lake + Forest
Swamp, // Lake + Field
Marsh, // Lake + Field
Swamp, // Lake + Forest
Mountain, // Hill + Hill
Steppe, // Hill + Forest
Fort, // Hill + Field
Plains, // Forest + Field
Grove, // Forest + Forest
Jungle, // Field + Field
Steppe, // Field + Forest
Fort, // Hill + forest
Plains, // Field + Field
Grove, // Field + Forest
Jungle, // Forest + Forest
// ── Aether combinations ───────────────────────────────────────────────
UnstableAether, // Aether + any non-Aether (tile-only, cannot appear on cards)
@@ -0,0 +1,60 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SOR.Database.Migrations.Catalog
{
/// <inheritdoc />
public partial class AddCdnUploadRecords : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "cdn_upload_records",
schema: "catalog",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
ObjectKey = table.Column<string>(type: "text", nullable: false),
Prefix = table.Column<string>(type: "text", nullable: false),
PublicUrl = table.Column<string>(type: "text", nullable: false),
ContentType = table.Column<string>(type: "text", nullable: true),
IsAiGenerated = table.Column<bool>(type: "boolean", nullable: false),
UploadedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_cdn_upload_records", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_cdn_upload_records_IsAiGenerated",
schema: "catalog",
table: "cdn_upload_records",
column: "IsAiGenerated");
migrationBuilder.CreateIndex(
name: "IX_cdn_upload_records_ObjectKey",
schema: "catalog",
table: "cdn_upload_records",
column: "ObjectKey",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_cdn_upload_records_Prefix",
schema: "catalog",
table: "cdn_upload_records",
column: "Prefix");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "cdn_upload_records",
schema: "catalog");
}
}
}
@@ -244,6 +244,45 @@ namespace SOR.Database.Migrations.Catalog
b.ToTable("card_definitions", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CdnUploadRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ContentType")
.HasColumnType("text");
b.Property<bool>("IsAiGenerated")
.HasColumnType("boolean");
b.Property<string>("ObjectKey")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Prefix")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PublicUrl")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("UploadedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("IsAiGenerated");
b.HasIndex("ObjectKey")
.IsUnique();
b.HasIndex("Prefix");
b.ToTable("cdn_upload_records", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardSet", b =>
{
b.Property<Guid>("Id")
+2 -2
View File
@@ -55,12 +55,12 @@ public static class AffinitySystem
// ── Hill pairings ─────────────────────────────────────────────────
(Affinity.Hill, Affinity.Hill) => Affinity.Mountain,
(Affinity.Hill, Affinity.Field) or (Affinity.Field, Affinity.Hill) => Affinity.Steppe,
(Affinity.Hill, Affinity.Field) or (Affinity.Field, Affinity.Hill) => Affinity.Grove,
(Affinity.Hill, Affinity.Forest) or (Affinity.Forest, Affinity.Hill) => Affinity.Fort,
// ── Field pairings ────────────────────────────────────────────────
(Affinity.Field, Affinity.Field) => Affinity.Plains,
(Affinity.Field, Affinity.Forest) or (Affinity.Forest, Affinity.Field) => Affinity.Grove,
(Affinity.Field, Affinity.Forest) or (Affinity.Forest, Affinity.Field) => Affinity.Steppe,
// ── Forest pairings ───────────────────────────────────────────────
(Affinity.Forest, Affinity.Forest) => Affinity.Jungle,