Skip to content

Commit 585f1c6

Browse files
committed
fix file extension
1 parent 2cde26d commit 585f1c6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/functions/imageCompression.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { maxSize } from '@/variables/constants';
44
export 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
}

0 commit comments

Comments
 (0)