fix(media): preserve GIF animation, skip JPEG optimization

- Skip JPEG optimization for image/gif content type (both local and URL)
- Preserves animation in uploaded GIFs to Discord/other providers
- Added tests for GIF preservation from local files and URLs
- Updated changelog
This commit is contained in:
Peter Steinberger
2026-01-02 00:55:52 +00:00
parent 4c2812b429
commit 76e24653e9
3 changed files with 79 additions and 0 deletions

View File

@@ -74,6 +74,17 @@ export async function loadWebMedia(
maxBytesForKind(kind),
);
if (kind === "image") {
// Skip optimization for GIFs to preserve animation
if (contentType === "image/gif") {
if (array.length > cap) {
throw new Error(
`GIF exceeds ${(cap / (1024 * 1024)).toFixed(0)}MB limit (got ${(
array.length / (1024 * 1024)
).toFixed(2)}MB)`,
);
}
return { buffer: array, contentType, kind, fileName };
}
return { ...(await optimizeAndClampImage(array, cap)), fileName };
}
if (array.length > cap) {
@@ -105,6 +116,17 @@ export async function loadWebMedia(
maxBytesForKind(kind),
);
if (kind === "image") {
// Skip optimization for GIFs to preserve animation
if (mime === "image/gif") {
if (data.length > cap) {
throw new Error(
`GIF exceeds ${(cap / (1024 * 1024)).toFixed(0)}MB limit (got ${(
data.length / (1024 * 1024)
).toFixed(2)}MB)`,
);
}
return { buffer: data, contentType: mime, kind, fileName };
}
return { ...(await optimizeAndClampImage(data, cap)), fileName };
}
if (data.length > cap) {