fix: client-side image type guard and deselect affordance on TrackEdit

This commit is contained in:
daniel-c-harvey
2026-06-07 16:41:02 -04:00
parent 5703ac2752
commit c4dc382bd7
2 changed files with 24 additions and 2 deletions
@@ -79,6 +79,18 @@
aria-label="Clear cover art" /> aria-label="Clear cover art" />
</MudStack> </MudStack>
} }
else if (_selectedImageFile is not null)
{
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
<MudText Typo="Typo.body2" Color="Color.Default">New image selected (not yet saved).</MudText>
<MudIconButton Icon="@Icons.Material.Filled.Clear"
Color="Color.Error"
Size="Size.Small"
Disabled="_busy"
OnClick="ClearImage"
aria-label="Cancel image selection" />
</MudStack>
}
else else
{ {
<MudText Typo="Typo.body2" Color="Color.Default">No cover art set.</MudText> <MudText Typo="Typo.body2" Color="Color.Default">No cover art set.</MudText>
+12 -2
View File
@@ -241,16 +241,26 @@ public class CmsTrackService : ICmsTrackService
} }
} }
private static readonly HashSet<string> KnownImageMimeTypes = new(StringComparer.OrdinalIgnoreCase)
{
"image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml", "image/bmp"
};
public async Task<ResultContainer<string>> UploadImageAsync( public async Task<ResultContainer<string>> UploadImageAsync(
Stream imageStream, Stream imageStream,
string fileName, string fileName,
string contentType, string contentType,
CancellationToken ct = default) CancellationToken ct = default)
{ {
if (string.IsNullOrWhiteSpace(contentType) || !KnownImageMimeTypes.Contains(contentType))
{
_logger.LogWarning("UploadImageAsync rejected: unsupported or missing content type '{ContentType}'", contentType);
return ResultContainer<string>.CreateFailResult($"Unsupported image type: {contentType}. Accepted: JPEG, PNG, GIF, WebP, SVG, BMP.");
}
using var multipart = new MultipartFormDataContent(); using var multipart = new MultipartFormDataContent();
var imageContent = new StreamContent(imageStream); var imageContent = new StreamContent(imageStream);
imageContent.Headers.ContentType = new MediaTypeHeaderValue( imageContent.Headers.ContentType = new MediaTypeHeaderValue(contentType);
string.IsNullOrWhiteSpace(contentType) ? "application/octet-stream" : contentType);
multipart.Add(imageContent, "image", fileName); multipart.Add(imageContent, "image", fileName);
var client = _httpClientFactory.CreateClient(ContentCmsClientName); var client = _httpClientFactory.CreateClient(ContentCmsClientName);