From 8d85f76180fdbc3483679330b5d2f94f8de4f2fa Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 16 Mar 2026 12:05:28 -0400 Subject: [PATCH] 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 Co-Authored-By: Happy --- .../Components/Pages/Cards/CardEditor.razor | 20 ++++++++++++------- Server/src/SOR.Cdn/HttpCdnClient.cs | 3 +++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor b/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor index 04ed2fc..226d43f 100644 --- a/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor +++ b/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor @@ -118,7 +118,7 @@ else -
Null = 1.0 (no change)
+
null = 1.0 (no change)
@@ -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 diff --git a/Server/src/SOR.Cdn/HttpCdnClient.cs b/Server/src/SOR.Cdn/HttpCdnClient.cs index 7eb6326..74ba84f 100644 --- a/Server/src/SOR.Cdn/HttpCdnClient.cs +++ b/Server/src/SOR.Cdn/HttpCdnClient.cs @@ -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);