Fix: unique CDN URLs per upload to bust browser + disk model cache

Uploading a replacement GLB with changed animation names to the same
folder/fileName path silently overwrote the S3 object but left the URL
unchanged.  ModelCache keyed its disk cache and in-memory cache by URL,
so all clients continued loading the stale model indefinitely.

Fix (CardEditor.razor):
- Asset uploads: append _yyyyMMddHHmmss timestamp to the filename stem
  before calling UploadAsync, e.g. merlock_20260316_143022.glb.
- Animation uploads: same treatment.
- Result: every upload produces a unique URL; the card asset record is
  updated to that URL; ModelCache sees a new key and fetches fresh bytes.

Fix (HttpCdnClient.cs):
- Set Cache-Control: public, max-age=31536000, immutable on uploaded
  objects.  Since keys are now unique-per-upload, aggressive caching is
  safe and avoids unnecessary re-downloads of unchanged assets.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-16 12:05:28 -04:00
co-authored by Claude Happy
parent f1f6183f85
commit 8d85f76180
2 changed files with 16 additions and 7 deletions
@@ -118,7 +118,7 @@ else
<label class="form-label">Scale</label>
<input @bind="_card.ModelScale" type="number" step="0.01" min="0.01" class="form-control"
placeholder="1.0" />
<div class="form-text">Null = 1.0 (no change)</div>
<div class="form-text">null = 1.0 (no change)</div>
</div>
<div class="col-md-3">
<label class="form-label">Tint Colour</label>
@@ -569,10 +569,13 @@ else
StateHasChanged();
try
{
var file = e.File;
var folder = $"cards/{_card!.Id}/assets";
var file = e.File;
var folder = $"cards/{_card!.Id}/assets";
var stem = Path.GetFileNameWithoutExtension(file.Name);
var ext = Path.GetExtension(file.Name);
var uniqueName = $"{stem}_{DateTimeOffset.UtcNow:yyyyMMddHHmmss}{ext}";
await using var stream = file.OpenReadStream(maxAllowedSize: 100 * 1024 * 1024);
var result = await Cdn.UploadAsync(folder, file.Name, file.ContentType, stream);
var result = await Cdn.UploadAsync(folder, uniqueName, file.ContentType, stream);
if (result.Success)
{
asset.CdnUrl = result.PublicUrl ?? string.Empty;
@@ -601,10 +604,13 @@ else
StateHasChanged();
try
{
var file = e.File;
var folder = $"cards/{_card!.Id}/animations";
var file = e.File;
var folder = $"cards/{_card!.Id}/animations";
var stem = Path.GetFileNameWithoutExtension(file.Name);
var ext = Path.GetExtension(file.Name);
var uniqueName = $"{stem}_{DateTimeOffset.UtcNow:yyyyMMddHHmmss}{ext}";
await using var stream = file.OpenReadStream(maxAllowedSize: 100 * 1024 * 1024);
var result = await Cdn.UploadAsync(folder, file.Name, file.ContentType, stream);
var result = await Cdn.UploadAsync(folder, uniqueName, file.ContentType, stream);
if (result.Success)
anim.AnimationCdnUrl = result.PublicUrl ?? string.Empty;
else
+3
View File
@@ -47,6 +47,9 @@ public sealed class S3CdnClient : ICdnClient
CannedACL = S3CannedACL.PublicRead,
DisableDefaultChecksumValidation = true,
};
// Immutable URLs: each upload gets a unique timestamped key, so browsers
// and CDN edges can cache aggressively without ever serving stale bytes.
request.Headers["Cache-Control"] = "public, max-age=31536000, immutable";
await _s3.PutObjectAsync(request, ct);