From 3e0b5f5863a88500aef27c88ff3581ea13d0a7cb Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 14 Dec 2022 16:32:39 +0530 Subject: [PATCH] move video file extension to along with the livePhoto util --- src/constants/file/index.ts | 28 ----------------- src/services/upload/livePhotoService.ts | 21 ++++++------- src/utils/file/index.ts | 11 ------- src/utils/file/livePhoto.ts | 41 +++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 50 deletions(-) create mode 100644 src/utils/file/livePhoto.ts diff --git a/src/constants/file/index.ts b/src/constants/file/index.ts index a0f0e987c..306b2a4fb 100644 --- a/src/constants/file/index.ts +++ b/src/constants/file/index.ts @@ -16,31 +16,3 @@ export enum FILE_TYPE { LIVE_PHOTO, OTHERS, } - -export const IMAGE_EXTENSIONS = [ - 'heic', - 'heif', - 'jpeg', - 'jpg', - 'png', - 'gif', - 'bmp', - 'tiff', - 'webp', -]; - -export const VIDEO_EXTENSIONS = [ - 'mov', - 'mp4', - 'm4v', - 'avi', - 'wmv', - 'flv', - 'mkv', - 'webm', - '3gp', - '3g2', - 'avi', - 'ogv', - 'mpg', -]; diff --git a/src/services/upload/livePhotoService.ts b/src/services/upload/livePhotoService.ts index ab21cc11f..13ca8b667 100644 --- a/src/services/upload/livePhotoService.ts +++ b/src/services/upload/livePhotoService.ts @@ -10,11 +10,8 @@ import { ParsedMetadataJSONMap, } from 'types/upload'; import { CustomError } from 'utils/error'; -import { - getFileTypeFromExtension, - isImageOrVideo, - splitFilenameAndExtension, -} from 'utils/file'; +import { getFileTypeFromExtensionForLivePhotoClustering } from 'utils/file/livePhoto'; +import { splitFilenameAndExtension, isImageOrVideo } from 'utils/file'; import { logError } from 'utils/sentry'; import { getUint8ArrayView } from '../readerService'; import { extractFileMetadata } from './fileService'; @@ -137,12 +134,14 @@ export async function clusterLivePhotoFiles(mediaFiles: FileWithCollection[]) { } const firstMediaFile = mediaFiles[index]; const secondMediaFile = mediaFiles[index + 1]; - const firstFileType = getFileTypeFromExtension( - firstMediaFile.file.name - ); - const secondFileType = getFileTypeFromExtension( - secondMediaFile.file.name - ); + const firstFileType = + getFileTypeFromExtensionForLivePhotoClustering( + firstMediaFile.file.name + ); + const secondFileType = + getFileTypeFromExtensionForLivePhotoClustering( + secondMediaFile.file.name + ); const firstFileIdentifier: LivePhotoIdentifier = { collectionID: firstMediaFile.collectionID, fileType: firstFileType, diff --git a/src/utils/file/index.ts b/src/utils/file/index.ts index 18e3e4e40..9c3ff6c54 100644 --- a/src/utils/file/index.ts +++ b/src/utils/file/index.ts @@ -19,8 +19,6 @@ import { TYPE_HEIC, TYPE_HEIF, FILE_TYPE, - IMAGE_EXTENSIONS, - VIDEO_EXTENSIONS, } from 'constants/file'; import PublicCollectionDownloadManager from 'services/publicCollectionDownloadManager'; import heicConversionService from 'services/heicConversionService'; @@ -273,15 +271,6 @@ export function getFileExtension(filename: string) { return splitFilenameAndExtension(filename)[1]?.toLocaleLowerCase(); } -export function getFileTypeFromExtension(filename: string) { - const extension = getFileExtension(filename); - if (IMAGE_EXTENSIONS.includes(extension)) { - return FILE_TYPE.IMAGE; - } else if (VIDEO_EXTENSIONS.includes(extension)) { - return FILE_TYPE.VIDEO; - } -} - export function generateStreamFromArrayBuffer(data: Uint8Array) { return new ReadableStream({ async start(controller: ReadableStreamDefaultController) { diff --git a/src/utils/file/livePhoto.ts b/src/utils/file/livePhoto.ts new file mode 100644 index 000000000..da0fb4f32 --- /dev/null +++ b/src/utils/file/livePhoto.ts @@ -0,0 +1,41 @@ +import { FILE_TYPE } from 'constants/file'; +import { getFileExtension } from 'utils/file'; + +const IMAGE_EXTENSIONS = [ + 'heic', + 'heif', + 'jpeg', + 'jpg', + 'png', + 'gif', + 'bmp', + 'tiff', + 'webp', +]; + +const VIDEO_EXTENSIONS = [ + 'mov', + 'mp4', + 'm4v', + 'avi', + 'wmv', + 'flv', + 'mkv', + 'webm', + '3gp', + '3g2', + 'avi', + 'ogv', + 'mpg', +]; + +export function getFileTypeFromExtensionForLivePhotoClustering( + filename: string +) { + const extension = getFileExtension(filename); + if (IMAGE_EXTENSIONS.includes(extension)) { + return FILE_TYPE.IMAGE; + } else if (VIDEO_EXTENSIONS.includes(extension)) { + return FILE_TYPE.VIDEO; + } +}