From c4dc382bd7721fa3f4271f25e2af3a542cd63b24 Mon Sep 17 00:00:00 2001 From: daniel-c-harvey Date: Sun, 7 Jun 2026 16:41:02 -0400 Subject: [PATCH] fix: client-side image type guard and deselect affordance on TrackEdit --- .../Components/Pages/Tracks/TrackEdit.razor | 12 ++++++++++++ DeepDrftManager/Services/CmsTrackService.cs | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/DeepDrftManager/Components/Pages/Tracks/TrackEdit.razor b/DeepDrftManager/Components/Pages/Tracks/TrackEdit.razor index 7352b35..f5a95aa 100644 --- a/DeepDrftManager/Components/Pages/Tracks/TrackEdit.razor +++ b/DeepDrftManager/Components/Pages/Tracks/TrackEdit.razor @@ -79,6 +79,18 @@ aria-label="Clear cover art" /> } + else if (_selectedImageFile is not null) + { + + New image selected (not yet saved). + + + } else { No cover art set. diff --git a/DeepDrftManager/Services/CmsTrackService.cs b/DeepDrftManager/Services/CmsTrackService.cs index 12a314e..c6fb909 100644 --- a/DeepDrftManager/Services/CmsTrackService.cs +++ b/DeepDrftManager/Services/CmsTrackService.cs @@ -241,16 +241,26 @@ public class CmsTrackService : ICmsTrackService } } + private static readonly HashSet KnownImageMimeTypes = new(StringComparer.OrdinalIgnoreCase) + { + "image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml", "image/bmp" + }; + public async Task> UploadImageAsync( Stream imageStream, string fileName, string contentType, CancellationToken ct = default) { + if (string.IsNullOrWhiteSpace(contentType) || !KnownImageMimeTypes.Contains(contentType)) + { + _logger.LogWarning("UploadImageAsync rejected: unsupported or missing content type '{ContentType}'", contentType); + return ResultContainer.CreateFailResult($"Unsupported image type: {contentType}. Accepted: JPEG, PNG, GIF, WebP, SVG, BMP."); + } + using var multipart = new MultipartFormDataContent(); var imageContent = new StreamContent(imageStream); - imageContent.Headers.ContentType = new MediaTypeHeaderValue( - string.IsNullOrWhiteSpace(contentType) ? "application/octet-stream" : contentType); + imageContent.Headers.ContentType = new MediaTypeHeaderValue(contentType); multipart.Add(imageContent, "image", fileName); var client = _httpClientFactory.CreateClient(ContentCmsClientName);