11import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
22// @ts -ignore
3- import Uppy , { UploadResult } from '@uppy/core' ;
3+ import Uppy , { BasePlugin , UploadResult , UppyFile } from '@uppy/core' ;
44// @ts -ignore
55import { useFetch } from '@gitroom/helpers/utils/custom.fetch' ;
66import { getUppyUploadPlugin } from '@gitroom/react/helpers/uppy.upload' ;
@@ -14,6 +14,27 @@ import { useToaster } from '@gitroom/react/toaster/toaster';
1414import { useLaunchStore } from '@gitroom/frontend/components/new-launch/store' ;
1515import { uniq } from 'lodash' ;
1616
17+ export class CompressionWrapper < M = any , B = any > extends Compressor < M , B > {
18+ override async prepareUpload ( fileIDs : string [ ] ) {
19+ const { files } = this . uppy . getState ( ) ;
20+
21+ // 1) Skip GIFs (and anything missing)
22+ const filteredIDs = fileIDs . filter ( ( id ) => {
23+ const f = files [ id ] ;
24+ if ( ! f ) return false ;
25+
26+ const type = f . type ?? '' ;
27+ const name = ( f . name ?? '' ) . toLowerCase ( ) ;
28+ const isGif = type === 'image/gif' || name . endsWith ( '.gif' ) ;
29+
30+ return ! isGif ;
31+ } ) ;
32+
33+ // 2) Let @uppy/compressor do its work (convert/resize/etc)
34+ return super . prepareUpload ( filteredIDs ) ;
35+ }
36+ }
37+
1738export function MultipartFileUploader ( {
1839 onUploadSuccess,
1940 allowedFileTypes,
@@ -88,7 +109,13 @@ export function useUppyUploader(props: {
88109 // Expand generic types to specific ones
89110 const expandedTypes = allowedTypes . flatMap ( ( type ) => {
90111 if ( type === 'image/*' ) {
91- return [ 'image/png' , 'image/jpeg' , 'image/jpg' , 'image/gif' , 'image/webp' ] ;
112+ return [
113+ 'image/png' ,
114+ 'image/jpeg' ,
115+ 'image/jpg' ,
116+ 'image/gif' ,
117+ 'image/webp' ,
118+ ] ;
92119 }
93120 if ( type === 'video/*' ) {
94121 return [ 'video/mp4' , 'video/mpeg' ] ;
@@ -182,8 +209,8 @@ export function useUppyUploader(props: {
182209
183210 uppy2 . use ( plugin , options ) ;
184211 if ( ! disableImageCompression ) {
185- uppy2 . use ( Compressor , {
186- convertTypes : [ 'image/jpeg' ] ,
212+ uppy2 . use ( CompressionWrapper , {
213+ convertTypes : [ 'image/jpeg' , 'image/png' , 'image/webp' ] ,
187214 maxWidth : 1000 ,
188215 maxHeight : 1000 ,
189216 quality : 1 ,
0 commit comments