create a POC working model of live photo upload
This commit is contained in:
parent
2260374fa0
commit
eb23444853
|
@ -151,3 +151,22 @@ export async function getUint8ArrayView(
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export function getFileTypeFromFileObject(file: globalThis.File) {
|
||||
const typeParts = file.type.split('/');
|
||||
let fileType;
|
||||
if (typeParts?.length !== 2) {
|
||||
throw Error(CustomError.TYPE_DETECTION_FAILED);
|
||||
}
|
||||
switch (typeParts[0]) {
|
||||
case TYPE_IMAGE:
|
||||
fileType = FILE_TYPE.IMAGE;
|
||||
break;
|
||||
case TYPE_VIDEO:
|
||||
fileType = FILE_TYPE.VIDEO;
|
||||
break;
|
||||
default:
|
||||
fileType = FILE_TYPE.OTHERS;
|
||||
}
|
||||
return fileType;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ export interface FileWithCollection {
|
|||
key?: string;
|
||||
isLivePhoto?: boolean;
|
||||
file?: globalThis.File;
|
||||
livePhotoAsset?: [globalThis.File, globalThis.File];
|
||||
livePhotoAsset?: { image: globalThis.File; video: globalThis.File };
|
||||
collection?: Collection;
|
||||
collectionID?: number;
|
||||
}
|
||||
|
|
|
@ -68,21 +68,7 @@ export default async function uploader(
|
|||
};
|
||||
let imageFile: globalThis.File;
|
||||
let videoFile: globalThis.File;
|
||||
if (
|
||||
file1TypeInfo.fileType === FILE_TYPE.IMAGE &&
|
||||
file2TypeInfo.fileType === FILE_TYPE.VIDEO
|
||||
) {
|
||||
imageFile = livePhotoAsset[0];
|
||||
videoFile = livePhotoAsset[1];
|
||||
} else if (
|
||||
file1TypeInfo.fileType === FILE_TYPE.VIDEO &&
|
||||
file2TypeInfo.fileType === FILE_TYPE.IMAGE
|
||||
) {
|
||||
imageFile = livePhotoAsset[1];
|
||||
videoFile = livePhotoAsset[0];
|
||||
} else {
|
||||
throw Error(CustomError.UNSUPPORTED_FILE_FORMAT);
|
||||
}
|
||||
|
||||
const imageMetadata = await uploadService.getFileMetadata(
|
||||
imageFile,
|
||||
collection,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { FileWithCollection } from 'services/upload/uploadManager';
|
||||
import { MetadataObject } from 'services/upload/uploadService';
|
||||
import { File } from 'services/fileService';
|
||||
import { File, FILE_TYPE } from 'services/fileService';
|
||||
import { splitFilenameAndExtension } from 'utils/file';
|
||||
import { getFileTypeFromFileObject } from 'services/upload/readFileService';
|
||||
const TYPE_JSON = 'json';
|
||||
|
||||
export function fileAlreadyInCollection(
|
||||
|
@ -63,15 +64,35 @@ export function segregateFiles(
|
|||
const collectionID = mediaFiles[i].collectionID;
|
||||
const file1 = mediaFile1.file;
|
||||
const file2 = mediaFile2.file;
|
||||
const file1Type = getFileTypeFromFileObject(file1);
|
||||
const file2Type = getFileTypeFromFileObject(file2);
|
||||
if (
|
||||
splitFilenameAndExtension(file1.name)[0] ===
|
||||
splitFilenameAndExtension(file2.name)[0]
|
||||
file1Type !== FILE_TYPE.OTHERS &&
|
||||
file2Type !== FILE_TYPE.OTHERS
|
||||
) {
|
||||
livePhotoFiles.push({
|
||||
collectionID: collectionID,
|
||||
isLivePhoto: true,
|
||||
livePhotoAsset: [file1, file2],
|
||||
});
|
||||
let imageFile;
|
||||
let videoFile;
|
||||
if (
|
||||
file1Type !== file2Type &&
|
||||
splitFilenameAndExtension(file1.name)[0] ===
|
||||
splitFilenameAndExtension(file2.name)[0]
|
||||
) {
|
||||
if (
|
||||
file1Type === FILE_TYPE.IMAGE &&
|
||||
file2Type === FILE_TYPE.VIDEO
|
||||
) {
|
||||
imageFile = file1;
|
||||
videoFile = file2;
|
||||
} else {
|
||||
imageFile = file2;
|
||||
videoFile = file1;
|
||||
}
|
||||
livePhotoFiles.push({
|
||||
collectionID: collectionID,
|
||||
isLivePhoto: true,
|
||||
livePhotoAsset: { image: imageFile, video: videoFile },
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
normalFiles.push(mediaFile1);
|
||||
|
|
Loading…
Reference in a new issue