diff --git a/src/services/fileService.ts b/src/services/fileService.ts index 0c0b2861d..af794e892 100644 --- a/src/services/fileService.ts +++ b/src/services/fileService.ts @@ -2,11 +2,7 @@ import { getEndpoint } from 'utils/common/apiUtil'; import localForage from 'utils/storage/localForage'; import { getToken } from 'utils/common/key'; -import { - DataStream, - EncryptionResult, - MetadataObject, -} from './upload/uploadService'; +import { DataStream, EncryptionResult, MetadataObject } from 'types/upload'; import { Collection } from './collectionService'; import HTTPService from './HTTPService'; import { logError } from 'utils/sentry'; diff --git a/src/services/migrateThumbnailService.ts b/src/services/migrateThumbnailService.ts index 4245a4538..07bec18cd 100644 --- a/src/services/migrateThumbnailService.ts +++ b/src/services/migrateThumbnailService.ts @@ -7,10 +7,11 @@ import { getEndpoint } from 'utils/common/apiUtil'; import HTTPService from 'services/HTTPService'; import CryptoWorker from 'utils/crypto'; import uploadHttpClient from 'services/upload/uploadHttpClient'; -import { EncryptionResult, UploadURL } from 'services/upload/uploadService'; +import { UploadURL } from 'services/upload/uploadService'; import { SetProgressTracker } from 'components/FixLargeThumbnail'; import { getFileType } from './upload/readFileService'; import { getLocalTrash, getTrashedFiles } from './trashService'; +import { EncryptionResult } from 'types/upload'; const ENDPOINT = getEndpoint(); const REPLACE_THUMBNAIL_THRESHOLD = 500 * 1024; // 500KB diff --git a/src/services/upload/encryptionService.ts b/src/services/upload/encryptionService.ts index 3ea654cf0..512bff778 100644 --- a/src/services/upload/encryptionService.ts +++ b/src/services/upload/encryptionService.ts @@ -1,4 +1,5 @@ -import { DataStream, EncryptionResult, isDataStream } from './uploadService'; +import { DataStream, EncryptionResult } from 'types/upload'; +import { isDataStream } from './uploadService'; async function encryptFileStream(worker, fileData: DataStream) { const { stream, chunkCount } = fileData; diff --git a/src/services/upload/metadataService.ts b/src/services/upload/metadataService.ts index 305b0b202..f0e045e70 100644 --- a/src/services/upload/metadataService.ts +++ b/src/services/upload/metadataService.ts @@ -2,7 +2,7 @@ import { FILE_TYPE } from 'services/fileService'; import { logError } from 'utils/sentry'; import { getExifData } from './exifService'; import { FileTypeInfo } from './readFileService'; -import { MetadataObject } from './uploadService'; +import { MetadataObject } from 'types/upload'; export interface Location { latitude: number; diff --git a/src/services/upload/multiPartUploadService.ts b/src/services/upload/multiPartUploadService.ts index be082ba7a..020b50c50 100644 --- a/src/services/upload/multiPartUploadService.ts +++ b/src/services/upload/multiPartUploadService.ts @@ -1,11 +1,9 @@ -import { - FILE_CHUNKS_COMBINED_FOR_A_UPLOAD_PART, - DataStream, -} from './uploadService'; +import { FILE_CHUNKS_COMBINED_FOR_A_UPLOAD_PART } from './uploadService'; import UploadHttpClient from './uploadHttpClient'; import * as convert from 'xml-js'; import UIService, { RANDOM_PERCENTAGE_PROGRESS_FOR_PUT } from './uiService'; import { CustomError } from 'utils/common/errorUtil'; +import { DataStream } from 'types/upload'; interface PartEtag { PartNumber: number; diff --git a/src/services/upload/readFileService.ts b/src/services/upload/readFileService.ts index 3342fd572..7d85b2b5f 100644 --- a/src/services/upload/readFileService.ts +++ b/src/services/upload/readFileService.ts @@ -3,7 +3,7 @@ import { FORMAT_MISSED_BY_FILE_TYPE_LIB, } from 'services/fileService'; import { logError } from 'utils/sentry'; -import { FILE_READER_CHUNK_SIZE, MULTIPART_PART_SIZE } from './uploadService'; +import { FILE_READER_CHUNK_SIZE, MULTIPART_PART_SIZE } from 'types/upload'; import FileType from 'file-type/browser'; import { CustomError } from 'utils/common/errorUtil'; diff --git a/src/services/upload/uploadService.ts b/src/services/upload/uploadService.ts index a14682772..b45ec71d2 100644 --- a/src/services/upload/uploadService.ts +++ b/src/services/upload/uploadService.ts @@ -1,4 +1,4 @@ -import { fileAttribute, FILE_TYPE } from '../fileService'; +import { fileAttribute } from '../fileService'; import { Collection } from '../collectionService'; import { logError } from 'utils/sentry'; import UploadHttpClient from './uploadHttpClient'; @@ -14,16 +14,17 @@ import { FileTypeInfo, } from './readFileService'; import { encryptFiledata } from './encryptionService'; -import { ENCRYPTION_CHUNK_SIZE } from 'types'; import { uploadStreamUsingMultipart } from './multiPartUploadService'; import UIService from './uiService'; import { handleUploadError } from 'utils/common/errorUtil'; import { MetadataMap } from './uploadManager'; - -// this is the chunk size of the un-encrypted file which is read and encrypted before uploading it as a single part. -export const MULTIPART_PART_SIZE = 20 * 1024 * 1024; - -export const FILE_READER_CHUNK_SIZE = ENCRYPTION_CHUNK_SIZE; +import { + DataStream, + EncryptionResult, + FILE_READER_CHUNK_SIZE, + MetadataObject, + MULTIPART_PART_SIZE, +} from 'types/upload'; export const FILE_CHUNKS_COMBINED_FOR_A_UPLOAD_PART = Math.floor( MULTIPART_PART_SIZE / FILE_READER_CHUNK_SIZE @@ -34,34 +35,15 @@ export interface UploadURL { objectKey: string; } -export interface DataStream { - stream: ReadableStream; - chunkCount: number; -} - export function isDataStream(object: any): object is DataStream { return 'stream' in object; } -export interface EncryptionResult { - file: fileAttribute; - key: string; -} export interface B64EncryptionResult { encryptedData: string; key: string; nonce: string; } -export interface MetadataObject { - title: string; - creationTime: number; - modificationTime: number; - latitude: number; - longitude: number; - fileType: FILE_TYPE; - hasStaticThumbnail?: boolean; -} - export interface FileInMemory { filedata: Uint8Array | DataStream; thumbnail: Uint8Array; diff --git a/src/services/upload/uploader.ts b/src/services/upload/uploader.ts index aef8bd962..7e9204309 100644 --- a/src/services/upload/uploader.ts +++ b/src/services/upload/uploader.ts @@ -12,11 +12,11 @@ import UploadService, { EncryptedFile, FileInMemory, FileWithMetadata, - MetadataObject, UploadFile, } from './uploadService'; import uploadService from './uploadService'; import { FileTypeInfo, getFileType } from './readFileService'; +import { MetadataObject } from 'types/upload'; const TwoSecondInMillSeconds = 2000; const FIVE_GB_IN_BYTES = 5 * 1024 * 1024 * 1024; diff --git a/src/types/upload/index.ts b/src/types/upload/index.ts new file mode 100644 index 000000000..a91a8ad3d --- /dev/null +++ b/src/types/upload/index.ts @@ -0,0 +1,27 @@ +import { fileAttribute, FILE_TYPE } from 'services/fileService'; +import { ENCRYPTION_CHUNK_SIZE } from 'types'; + +// this is the chunk size of the un-encrypted file which is read and encrypted before uploading it as a single part. +export const MULTIPART_PART_SIZE = 20 * 1024 * 1024; + +export const FILE_READER_CHUNK_SIZE = ENCRYPTION_CHUNK_SIZE; + +export interface DataStream { + stream: ReadableStream; + chunkCount: number; +} + +export interface EncryptionResult { + file: fileAttribute; + key: string; +} + +export interface MetadataObject { + title: string; + creationTime: number; + modificationTime: number; + latitude: number; + longitude: number; + fileType: FILE_TYPE; + hasStaticThumbnail?: boolean; +} diff --git a/src/utils/export/index.ts b/src/utils/export/index.ts index 1aca1446b..c8f7448bc 100644 --- a/src/utils/export/index.ts +++ b/src/utils/export/index.ts @@ -1,6 +1,6 @@ import { ExportRecord } from 'services/exportService'; import { File } from 'services/fileService'; -import { MetadataObject } from 'services/upload/uploadService'; +import { MetadataObject } from 'types/upload'; import { formatDate } from 'utils/file'; export const getExportRecordFileUID = (file: File) => diff --git a/src/utils/upload/index.ts b/src/utils/upload/index.ts index ded536051..bbc15c8b6 100644 --- a/src/utils/upload/index.ts +++ b/src/utils/upload/index.ts @@ -1,5 +1,5 @@ import { FileWithCollection } from 'services/upload/uploadManager'; -import { MetadataObject } from 'services/upload/uploadService'; +import { MetadataObject } from 'types/upload'; import { File } from 'services/fileService'; const TYPE_JSON = 'json';