File tree Expand file tree Collapse file tree 1 file changed +2
-1
lines changed
Expand file tree Collapse file tree 1 file changed +2
-1
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,14 @@ import { maxSize } from '@/variables/constants';
44export async function compressFile ( file : File , quality : number = 1 ) : Promise < File > {
55 if ( file . size < maxSize ) return file ; // if below 10 MB, don't do anything
66 const type = imageTypes . JPEG ;
7+ const newFileExtension = type . split ( '/' ) . at ( - 1 ) ;
78 const res = await compressImage ( file , {
89 quality,
910 type,
1011 } ) ;
1112 const lowerQuality = quality - 0.01 ; // NoSonar reduce quality by 1%;
1213 if ( res . size > maxSize ) return await compressFile ( file , lowerQuality ) ; // compress original file with lower quality setting to avoid double compression
1314 const fileName = file . name . split ( '.' ) . slice ( 0 , - 1 ) . join ( '.' ) ;
14- const newFileName = `${ fileName } -min.${ type } ` ;
15+ const newFileName = `${ fileName } -min.${ newFileExtension } ` ;
1516 return new File ( [ res ] , newFileName , { type } ) ;
1617}
You can’t perform that action at this time.
0 commit comments