This repository was archived by the owner on Jan 30, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +39
-11
lines changed
Expand file tree Collapse file tree 5 files changed +39
-11
lines changed Original file line number Diff line number Diff 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 ) ) ;
Original file line number Diff line number Diff 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 ) ) ;
Original file line number Diff line number Diff 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 ) ) ;
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff line change 11// Utility to resize an image file to fit within a maximum file size while maintaining aspect ratio
22export 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
You can’t perform that action at this time.
0 commit comments