Rearrange

This commit is contained in:
Manav Rathi 2024-04-25 14:41:48 +05:30
parent 3ac81df561
commit 72b1df0b75
No known key found for this signature in database

View file

@ -709,19 +709,10 @@ const computeHash = async (
const readAsset = async ( const readAsset = async (
fileTypeInfo: FileTypeInfo, fileTypeInfo: FileTypeInfo,
{ isLivePhoto, file, livePhotoAssets }: UploadAsset2, { isLivePhoto, file, livePhotoAssets }: UploadAsset2,
) => { ) =>
return isLivePhoto isLivePhoto
? await readLivePhoto(livePhotoAssets, fileTypeInfo) ? await readLivePhoto(livePhotoAssets, fileTypeInfo)
: await readImageOrVideo(file, fileTypeInfo); : await readImageOrVideo(file, fileTypeInfo);
};
const readImageOrVideo = async (
fileOrPath: File | string,
fileTypeInfo: FileTypeInfo,
) => {
const { dataOrStream, fileSize } = await readFileOrPath(fileOrPath);
return withThumbnail(fileOrPath, fileTypeInfo, dataOrStream, fileSize);
};
const readLivePhoto = async ( const readLivePhoto = async (
livePhotoAssets: LivePhotoAssets2, livePhotoAssets: LivePhotoAssets2,
@ -743,12 +734,12 @@ const readLivePhoto = async (
); );
const readVideo = await readFileOrPath(livePhotoAssets.video); const readVideo = await readFileOrPath(livePhotoAssets.video);
// We can revisit this later, but the existing code always read the // We can revisit this later, but the existing code always read the entire
// full files into memory here, and to avoid changing the rest of // file into memory here, and to avoid changing the rest of the scaffolding
// the scaffolding retain the same behaviour. // retain the same behaviour.
// //
// This is a reasonable assumption too, since the videos // This is a reasonable assumption too, since the videos corresponding to
// corresponding to live photos are only a couple of seconds long. // live photos are only a couple of seconds long.
const toData = async (dataOrStream: Uint8Array | DataStream) => const toData = async (dataOrStream: Uint8Array | DataStream) =>
dataOrStream instanceof Uint8Array dataOrStream instanceof Uint8Array
? dataOrStream ? dataOrStream
@ -766,6 +757,14 @@ const readLivePhoto = async (
}; };
}; };
const readImageOrVideo = async (
fileOrPath: File | string,
fileTypeInfo: FileTypeInfo,
) => {
const { dataOrStream, fileSize } = await readFileOrPath(fileOrPath);
return withThumbnail(fileOrPath, fileTypeInfo, dataOrStream, fileSize);
};
// TODO(MR): Merge with the uploader // TODO(MR): Merge with the uploader
class ModuleState { class ModuleState {
/** /**