diff --git a/src/pages/credentials/index.tsx b/src/pages/credentials/index.tsx index 1c20f5861b0c4625c99bc9e5a19b11ffeed10441..cfd124b7acd7833ed7fbb99907fd18d08e177735 100644 --- a/src/pages/credentials/index.tsx +++ b/src/pages/credentials/index.tsx @@ -11,11 +11,7 @@ import { useRouter } from 'next/router'; import * as Yup from 'yup'; import { keyAttributes } from 'types'; import { setKey, SESSION_KEYS, getKey } from 'utils/storage/sessionStorage'; -import * as Comlink from 'comlink'; - -const CryptoWorker: any = - typeof window !== 'undefined' && - Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' })); +import CryptoWorker from 'utils/crypto/cryptoWorker'; const Image = styled.img` width: 200px; diff --git a/src/pages/generate/index.tsx b/src/pages/generate/index.tsx index e68656b89a689ab7ef12508b5955ce3e9334cfcd..c83d947ba429cb0082f7cbaad0f22d7162e8664e 100644 --- a/src/pages/generate/index.tsx +++ b/src/pages/generate/index.tsx @@ -11,12 +11,8 @@ import { putAttributes } from 'services/userService'; import { getData, LS_KEYS, setData } from 'utils/storage/localStorage'; import { useRouter } from 'next/router'; import { getKey, SESSION_KEYS, setKey } from 'utils/storage/sessionStorage'; -import * as Comlink from 'comlink'; import { B64EncryptionResult } from 'services/uploadService'; - -const CryptoWorker: any = - typeof window !== 'undefined' && - Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' })); +import CryptoWorker from 'utils/crypto/cryptoWorker'; const Image = styled.img` width: 200px; diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index b75812b5993ab9e081a7a3aec6af5948d7206e42..26fe9e974f1132877da399b33ffc08e750ba3fa0 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -4,14 +4,11 @@ import { file } from './fileService'; import localForage from 'localforage'; import HTTPService from './HTTPService'; -import * as Comlink from 'comlink'; import { B64EncryptionResult } from './uploadService'; import { getActualKey, getToken } from 'utils/common/key'; import { user } from './userService'; +import CryptoWorker from 'utils/crypto/cryptoWorker'; -const CryptoWorker: any = - typeof window !== 'undefined' && - Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' })); const ENDPOINT = getEndpoint(); enum CollectionType { diff --git a/src/services/downloadManager.ts b/src/services/downloadManager.ts index 2652b8b02fffe91f75121a4af432c1d4d3bb1e50..30e3947ffec43a12dc89642d47b634fd8b2d19ad 100644 --- a/src/services/downloadManager.ts +++ b/src/services/downloadManager.ts @@ -2,13 +2,11 @@ import { getToken } from 'utils/common/key'; import { file } from './fileService'; import HTTPService from './HTTPService'; import { getEndpoint } from 'utils/common/apiUtil'; -import * as Comlink from 'comlink'; import { getFileExtension } from 'utils/common/utilFunctions'; +import CryptoWorker from 'utils/crypto/cryptoWorker'; const ENDPOINT = getEndpoint(); -const CryptoWorker: any = - typeof window !== 'undefined' && - Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' })); + const heic2any = typeof window !== 'undefined' && require('heic2any'); const TYPE_HEIC = 'heic'; diff --git a/src/services/fileService.ts b/src/services/fileService.ts index add87f5cc6ec97cf4d79c1cadea34c1a8cb6f58f..8a27b4d7dfb8d2a10ec9cf5bc5f4eae25012275a 100644 --- a/src/services/fileService.ts +++ b/src/services/fileService.ts @@ -1,13 +1,10 @@ import { getEndpoint } from 'utils/common/apiUtil'; import HTTPService from './HTTPService'; -import * as Comlink from 'comlink'; import localForage from 'localforage'; import { collection } from './collectionService'; import { MetadataObject } from './uploadService'; +import CryptoWorker from 'utils/crypto/cryptoWorker'; -const CryptoWorker: any = - typeof window !== 'undefined' && - Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' })); const ENDPOINT = getEndpoint(); const DIFF_LIMIT: number = 2500; diff --git a/src/services/uploadService.ts b/src/services/uploadService.ts index 0e8976e4aff20592408b62c50104812668954924..bae0b8f6a4fac3c15c68d7d2be2948d97ae5c8f3 100644 --- a/src/services/uploadService.ts +++ b/src/services/uploadService.ts @@ -1,15 +1,12 @@ import { getEndpoint } from 'utils/common/apiUtil'; import HTTPService from './HTTPService'; -import * as Comlink from 'comlink'; import EXIF from 'exif-js'; import { fileAttribute } from './fileService'; import { collection, CollectionAndItsLatestFile } from './collectionService'; import { FILE_TYPE } from 'pages/gallery'; import { checkConnectivity } from 'utils/common/utilFunctions'; import { ErrorHandler } from 'utils/common/errorUtil'; -const CryptoWorker: any = - typeof window !== 'undefined' && - Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' })); +import CryptoWorker from 'utils/crypto/cryptoWorker'; const ENDPOINT = getEndpoint(); const THUMBNAIL_HEIGHT = 720; diff --git a/src/utils/common/key.ts b/src/utils/common/key.ts index 12c122af2f27598052ba60afed6cf8b595e221a6..eab610eda9c8cd3b3e8db2f9b9bd9751394c0aee 100644 --- a/src/utils/common/key.ts +++ b/src/utils/common/key.ts @@ -1,10 +1,6 @@ +import CryptoWorker from 'utils/crypto/cryptoWorker'; import { getData, LS_KEYS } from 'utils/storage/localStorage'; import { getKey, SESSION_KEYS } from 'utils/storage/sessionStorage'; -import * as Comlink from 'comlink'; - -const CryptoWorker: any = - typeof window !== 'undefined' && - Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' })); export const getActualKey = async () => { const session = getData(LS_KEYS.SESSION); diff --git a/src/utils/crypto/cryptoWorker.ts b/src/utils/crypto/cryptoWorker.ts new file mode 100644 index 0000000000000000000000000000000000000000..c5e37f8bbf5ee43573d1005523dc8bc229766882 --- /dev/null +++ b/src/utils/crypto/cryptoWorker.ts @@ -0,0 +1,7 @@ +import * as Comlink from 'comlink'; + +const CryptoWorker: any = + typeof window !== 'undefined' && + Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' })); + +export default CryptoWorker;