Skip to content

Commit b44ddce

Browse files
use heic-to/csp for CSP fixes
1 parent a4db383 commit b44ddce

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • src/libs/fileDownload/heicConverter

src/libs/fileDownload/heicConverter/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import type {HeicConverterFunction} from './types';
22

3+
type HeicConverter = {
4+
heicTo: (options: {blob: Blob; type: string}) => Promise<Blob>;
5+
isHeic: (file: File) => Promise<boolean>;
6+
};
7+
8+
const getHeicConverter = () => {
9+
// Use the CSP variant to ensure the library is loaded in a secure context. See https://github.com/hoppergee/heic-to?tab=readme-ov-file#cotent-security-policy
10+
// @ts-expect-error - heic-to/csp is not correctly typed but exists
11+
return import(/* webpackMode: "eager" */ 'heic-to/csp').then(({heicTo, isHeic}: HeicConverter) => ({heicTo, isHeic}));
12+
};
13+
314
/**
415
* Web implementation for converting HEIC/HEIF images to JPEG
516
* @param file - The file to check and potentially convert
@@ -23,7 +34,7 @@ const convertHeicImage: HeicConverterFunction = (file, {onSuccess = () => {}, on
2334
}
2435

2536
// Start loading the conversion library in parallel with fetching the file
26-
const libraryPromise = import(/* webpackMode: "eager" */ 'heic-to').catch((importError) => {
37+
const libraryPromise = getHeicConverter().catch((importError) => {
2738
console.error('Error loading heic-to library:', importError);
2839
// Re-throw a normalized error so the outer catch can handle it uniformly
2940
throw new Error('HEIC conversion library unavailable');

0 commit comments

Comments
 (0)