Skip to content

Commit 5b80eaa

Browse files
committed
Enhance WernstromService to detect actual MIME type from image bytes, improving accuracy over Discord's reported type
1 parent aff18de commit 5b80eaa

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

.github/instructions/saneai.instructions.md renamed to .github/instructions/copilot-instructions.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
---
2-
applyTo: 'src/RSBotWorks/SaneAI/**,src/RSBotWorks.Tests/SaneAI/**,src/RSBotWorks.Tests/Explicit/SaneAI/**,src/SaneAI.Demo/**'
3-
---
4-
51
# SaneAI — Raw JSON AI Abstraction
62

73
SaneAI is a custom AI API abstraction layer that bypasses third-party SDKs entirely. It talks directly to provider REST APIs using raw JSON, so new model features/settings can be added immediately without waiting for SDK updates.

src/Wernstrom/WernstromService.Images.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ public partial class WernstromService
5050
mimeType = "image/jpeg"; // Assume JPEG after processing
5151
isResized = true;
5252
}
53+
else
54+
{
55+
// Detect actual MIME type from image bytes — Discord's ContentType can be wrong
56+
var detectedFormat = SixLabors.ImageSharp.Image.DetectFormat(imageData);
57+
if (detectedFormat != null && detectedFormat.DefaultMimeType != mimeType)
58+
{
59+
Logger.LogWarning("Discord reported MIME type {DiscordMimeType} but image bytes indicate {DetectedMimeType} for {Filename}. Using detected type.",
60+
mimeType, detectedFormat.DefaultMimeType, attachment.Filename);
61+
mimeType = detectedFormat.DefaultMimeType;
62+
}
63+
}
5364
if (imageData == null || imageData.Length == 0)
5465
{
5566
Logger.LogWarning($"Failed to download or process image: {attachment.Filename}");

0 commit comments

Comments
 (0)