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';
4
4
export async function compressFile ( file : File , quality : number = 1 ) : Promise < File > {
5
5
if ( file . size < maxSize ) return file ; // if below 10 MB, don't do anything
6
6
const type = imageTypes . JPEG ;
7
+ const newFileExtension = type . split ( '/' ) . at ( - 1 ) ;
7
8
const res = await compressImage ( file , {
8
9
quality,
9
10
type,
10
11
} ) ;
11
12
const lowerQuality = quality - 0.01 ; // NoSonar reduce quality by 1%;
12
13
if ( res . size > maxSize ) return await compressFile ( file , lowerQuality ) ; // compress original file with lower quality setting to avoid double compression
13
14
const fileName = file . name . split ( '.' ) . slice ( 0 , - 1 ) . join ( '.' ) ;
14
- const newFileName = `${ fileName } -min.${ type } ` ;
15
+ const newFileName = `${ fileName } -min.${ newFileExtension } ` ;
15
16
return new File ( [ res ] , newFileName , { type } ) ;
16
17
}
You can’t perform that action at this time.
0 commit comments