Skip to content
This repository was archived by the owner on Jan 30, 2026. It is now read-only.

Commit a589a77

Browse files
fix: disable compressing gif (#1854)
* fix: disable compressing gif * fix: large GIF rejection error message --------- Co-authored-by: James Browning <jamesbrowning91@gmail.com>
1 parent 6b4af6f commit a589a77

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

src/components/CreateContent/Section/_FooterArea.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,22 @@ export default function FooterArea({
152152
}
153153

154154
if (isImage && file.size > maxImageSizeInBytes) {
155+
let loadingAlertId: number | undefined;
155156
try {
156-
const loadingAlertId = addAlert(`Compressing image ${i + 1}/${filesArray.length}...`, 'loading');
157+
loadingAlertId = addAlert(`Compressing image ${i + 1}/${filesArray.length}...`, 'loading');
157158
setIsCompressing(true);
158159
setFilesBeingCompressed && setFilesBeingCompressed((prev) => prev + 1);
159160
const resizedFile = await Utils.resizeImageFile(file, maxImageSizeInBytes);
160161
removeAlert(loadingAlertId);
161162
validFiles.push(resizedFile);
162163
} catch (error) {
163-
addAlert('The maximum allowed size for images is 5 MB', 'warning');
164+
// Remove the loading alert if it exists
165+
if (loadingAlertId) {
166+
removeAlert(loadingAlertId);
167+
}
168+
// Show the actual error message from the compression function
169+
const errorMessage = error instanceof Error ? error.message : String(error);
170+
addAlert(errorMessage, 'warning');
164171
continue;
165172
} finally {
166173
setFilesBeingCompressed && setFilesBeingCompressed((prev) => Math.max(0, prev - 1));

src/components/CreateContent/Section/_InputArea.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,22 @@ export default function InputArea({
136136
}
137137

138138
if (isImage && file.size > maxImageSizeInBytes) {
139+
let loadingAlertId: number | undefined;
139140
try {
140-
const loadingAlertId = addAlert(
141-
`Compressing image ${validFiles.length + 1}/${files.length}...`,
142-
'loading'
143-
);
141+
loadingAlertId = addAlert(`Compressing image ${validFiles.length + 1}/${files.length}...`, 'loading');
144142
setIsCompressing(true);
145143
setFilesBeingCompressed && setFilesBeingCompressed((prev) => prev + 1);
146144
const resizedFile = await Utils.resizeImageFile(file, maxImageSizeInBytes);
147145
removeAlert(loadingAlertId);
148146
validFiles.push(resizedFile);
149147
} catch (error) {
150-
addAlert('The maximum allowed size for images is 5 MB', 'warning');
148+
// Remove the loading alert if it exists
149+
if (loadingAlertId) {
150+
removeAlert(loadingAlertId);
151+
}
152+
// Show the actual error message from the compression function
153+
const errorMessage = error instanceof Error ? error.message : String(error);
154+
addAlert(errorMessage, 'warning');
151155
continue;
152156
} finally {
153157
setFilesBeingCompressed && setFilesBeingCompressed((prev) => Math.max(0, prev - 1));

src/components/CreateContent/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,22 @@ export default function CreateContent({
296296
const isVideo = file.type.startsWith('video/');
297297

298298
if (isImage && file.size > maxImageSizeInBytes) {
299+
let loadingAlertId: number | undefined;
299300
try {
300-
const loadingAlertId = addAlert(`Compressing image ${i + 1}/${filesToProcess.length}...`, 'loading');
301+
loadingAlertId = addAlert(`Compressing image ${i + 1}/${filesToProcess.length}...`, 'loading');
301302
setIsCompressing(true);
302303
setFilesBeingCompressed((prev) => prev + 1);
303304
const resizedFile = await Utils.resizeImageFile(file, maxImageSizeInBytes);
304305
removeAlert(loadingAlertId);
305306
validFiles.push(resizedFile);
306307
} catch (error) {
307-
addAlert('The maximum allowed size for images is 5 MB', 'warning');
308+
// Remove the loading alert if it exists
309+
if (loadingAlertId) {
310+
removeAlert(loadingAlertId);
311+
}
312+
// Show the actual error message from the compression function
313+
const errorMessage = error instanceof Error ? error.message : String(error);
314+
addAlert(errorMessage, 'warning');
308315
continue;
309316
} finally {
310317
setFilesBeingCompressed((prev) => Math.max(0, prev - 1));

src/components/Modal/_CreateArticle/_Content.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ export default function ContentCreateArticle({
244244
processedFile = await Utils.resizeImageFile(file, maxImageSizeInBytes);
245245
removeAlert(loadingAlertId);
246246
} catch (error) {
247-
setErrorFile('The maximum allowed size for images is 5 MB');
247+
// Show the actual error message from the compression function
248+
const errorMessage = error instanceof Error ? error.message : String(error);
249+
addAlert(errorMessage, 'warning');
248250
return;
249251
} finally {
250252
setIsCompressing(false);
@@ -379,7 +381,9 @@ export default function ContentCreateArticle({
379381
processedFile = await Utils.resizeImageFile(file, maxImageSizeInBytes);
380382
removeAlert(loadingAlertId);
381383
} catch (error) {
382-
addAlert('The maximum allowed size for images is 5 MB', 'warning');
384+
// Show the actual error message from the compression function
385+
const errorMessage = error instanceof Error ? error.message : String(error);
386+
addAlert(errorMessage, 'warning');
383387
return;
384388
} finally {
385389
setIsCompressing(false);

src/components/utils-shared/lib/Helper/resizeImageFile.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// Utility to resize an image file to fit within a maximum file size while maintaining aspect ratio
22
export async function resizeImageFile(file: File, maxSizeInBytes: number = 5 * 1024 * 1024): Promise<File> {
33
return new Promise((resolve, reject) => {
4+
// Check if file is a GIF and exceeds size limit
5+
if (file.type === 'image/gif' && file.size > maxSizeInBytes) {
6+
reject('GIF files cannot be compressed as it would lose the animation. Please use a GIF under 5 MB.');
7+
return;
8+
}
9+
410
const img = new window.Image();
511
const reader = new FileReader();
612

0 commit comments

Comments
 (0)