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;
|
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;
|
key?: string;
|
||||||
isLivePhoto?: boolean;
|
isLivePhoto?: boolean;
|
||||||
file?: globalThis.File;
|
file?: globalThis.File;
|
||||||
livePhotoAsset?: [globalThis.File, globalThis.File];
|
livePhotoAsset?: { image: globalThis.File; video: globalThis.File };
|
||||||
collection?: Collection;
|
collection?: Collection;
|
||||||
collectionID?: number;
|
collectionID?: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,21 +68,7 @@ export default async function uploader(
|
||||||
};
|
};
|
||||||
let imageFile: globalThis.File;
|
let imageFile: globalThis.File;
|
||||||
let videoFile: 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(
|
const imageMetadata = await uploadService.getFileMetadata(
|
||||||
imageFile,
|
imageFile,
|
||||||
collection,
|
collection,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { FileWithCollection } from 'services/upload/uploadManager';
|
import { FileWithCollection } from 'services/upload/uploadManager';
|
||||||
import { MetadataObject } from 'services/upload/uploadService';
|
import { MetadataObject } from 'services/upload/uploadService';
|
||||||
import { File } from 'services/fileService';
|
import { File, FILE_TYPE } from 'services/fileService';
|
||||||
import { splitFilenameAndExtension } from 'utils/file';
|
import { splitFilenameAndExtension } from 'utils/file';
|
||||||
|
import { getFileTypeFromFileObject } from 'services/upload/readFileService';
|
||||||
const TYPE_JSON = 'json';
|
const TYPE_JSON = 'json';
|
||||||
|
|
||||||
export function fileAlreadyInCollection(
|
export function fileAlreadyInCollection(
|
||||||
|
@ -63,15 +64,35 @@ export function segregateFiles(
|
||||||
const collectionID = mediaFiles[i].collectionID;
|
const collectionID = mediaFiles[i].collectionID;
|
||||||
const file1 = mediaFile1.file;
|
const file1 = mediaFile1.file;
|
||||||
const file2 = mediaFile2.file;
|
const file2 = mediaFile2.file;
|
||||||
|
const file1Type = getFileTypeFromFileObject(file1);
|
||||||
|
const file2Type = getFileTypeFromFileObject(file2);
|
||||||
if (
|
if (
|
||||||
splitFilenameAndExtension(file1.name)[0] ===
|
file1Type !== FILE_TYPE.OTHERS &&
|
||||||
splitFilenameAndExtension(file2.name)[0]
|
file2Type !== FILE_TYPE.OTHERS
|
||||||
) {
|
) {
|
||||||
livePhotoFiles.push({
|
let imageFile;
|
||||||
collectionID: collectionID,
|
let videoFile;
|
||||||
isLivePhoto: true,
|
if (
|
||||||
livePhotoAsset: [file1, file2],
|
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 {
|
} else {
|
||||||
normalFiles.push(mediaFile1);
|
normalFiles.push(mediaFile1);
|
||||||
|
|
Loading…
Reference in a new issue