rename motionPhoto to livePhoto
This commit is contained in:
parent
0b73cb71c1
commit
8acdbe30e8
|
@ -27,7 +27,7 @@ import downloadManager from './downloadManager';
|
|||
import { getLocalFiles } from './fileService';
|
||||
import { EnteFile } from 'types/file';
|
||||
|
||||
import { decodeMotionPhoto } from './motionPhotoService';
|
||||
import { decodeLivePhoto } from './livePhotoService';
|
||||
import {
|
||||
generateStreamFromArrayBuffer,
|
||||
getFileExtension,
|
||||
|
@ -539,7 +539,7 @@ class ExportService {
|
|||
fileStream = updatedFileBlob.stream();
|
||||
}
|
||||
if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {
|
||||
await this.exportMotionPhoto(fileStream, file, collectionPath);
|
||||
await this.exportLivePhoto(fileStream, file, collectionPath);
|
||||
} else {
|
||||
await this.saveMediaFile(
|
||||
collectionPath,
|
||||
|
@ -554,26 +554,26 @@ class ExportService {
|
|||
}
|
||||
}
|
||||
|
||||
private async exportMotionPhoto(
|
||||
private async exportLivePhoto(
|
||||
fileStream: ReadableStream<any>,
|
||||
file: EnteFile,
|
||||
collectionPath: string
|
||||
) {
|
||||
const fileBlob = await new Response(fileStream).blob();
|
||||
const motionPhoto = await decodeMotionPhoto(file, fileBlob);
|
||||
const imageStream = generateStreamFromArrayBuffer(motionPhoto.image);
|
||||
const livePhoto = await decodeLivePhoto(file, fileBlob);
|
||||
const imageStream = generateStreamFromArrayBuffer(livePhoto.image);
|
||||
const imageSaveName = getUniqueFileSaveName(
|
||||
collectionPath,
|
||||
motionPhoto.imageNameTitle,
|
||||
livePhoto.imageNameTitle,
|
||||
file.id
|
||||
);
|
||||
await this.saveMediaFile(collectionPath, imageSaveName, imageStream);
|
||||
await this.saveMetadataFile(collectionPath, imageSaveName, file);
|
||||
|
||||
const videoStream = generateStreamFromArrayBuffer(motionPhoto.video);
|
||||
const videoStream = generateStreamFromArrayBuffer(livePhoto.video);
|
||||
const videoSaveName = getUniqueFileSaveName(
|
||||
collectionPath,
|
||||
motionPhoto.videoNameTitle,
|
||||
livePhoto.videoNameTitle,
|
||||
file.id
|
||||
);
|
||||
await this.saveMediaFile(collectionPath, videoSaveName, videoStream);
|
||||
|
|
|
@ -2,45 +2,41 @@ import JSZip from 'jszip';
|
|||
import { EnteFile } from 'types/file';
|
||||
import { fileExtensionWithDot, fileNameWithoutExtension } from 'utils/file';
|
||||
|
||||
class MotionPhoto {
|
||||
class LivePhoto {
|
||||
image: Uint8Array;
|
||||
video: Uint8Array;
|
||||
imageNameTitle: string;
|
||||
videoNameTitle: string;
|
||||
}
|
||||
|
||||
export const decodeMotionPhoto = async (file: EnteFile, zipBlob: Blob) => {
|
||||
export const decodeLivePhoto = async (file: EnteFile, zipBlob: Blob) => {
|
||||
const originalName = fileNameWithoutExtension(file.metadata.title);
|
||||
const zip = await JSZip.loadAsync(zipBlob, { createFolders: true });
|
||||
|
||||
const motionPhoto = new MotionPhoto();
|
||||
const livePhoto = new LivePhoto();
|
||||
for (const zipFilename in zip.files) {
|
||||
if (zipFilename.startsWith('image')) {
|
||||
motionPhoto.imageNameTitle =
|
||||
livePhoto.imageNameTitle =
|
||||
originalName + fileExtensionWithDot(zipFilename);
|
||||
motionPhoto.image = await zip.files[zipFilename].async(
|
||||
'uint8array'
|
||||
);
|
||||
livePhoto.image = await zip.files[zipFilename].async('uint8array');
|
||||
} else if (zipFilename.startsWith('video')) {
|
||||
motionPhoto.videoNameTitle =
|
||||
livePhoto.videoNameTitle =
|
||||
originalName + fileExtensionWithDot(zipFilename);
|
||||
motionPhoto.video = await zip.files[zipFilename].async(
|
||||
'uint8array'
|
||||
);
|
||||
livePhoto.video = await zip.files[zipFilename].async('uint8array');
|
||||
}
|
||||
}
|
||||
return motionPhoto;
|
||||
return livePhoto;
|
||||
};
|
||||
|
||||
export const encodeMotionPhoto = async (motionPhoto: MotionPhoto) => {
|
||||
export const encodeLivePhoto = async (livePhoto: LivePhoto) => {
|
||||
const zip = new JSZip();
|
||||
zip.file(
|
||||
'image' + fileExtensionWithDot(motionPhoto.imageNameTitle),
|
||||
motionPhoto.image
|
||||
'image' + fileExtensionWithDot(livePhoto.imageNameTitle),
|
||||
livePhoto.image
|
||||
);
|
||||
zip.file(
|
||||
'video' + fileExtensionWithDot(motionPhoto.videoNameTitle),
|
||||
motionPhoto.video
|
||||
'video' + fileExtensionWithDot(livePhoto.videoNameTitle),
|
||||
livePhoto.video
|
||||
);
|
||||
return await zip.generateAsync({ type: 'uint8array' });
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
import { FILE_TYPE } from 'constants/file';
|
||||
import { LIVE_PHOTO_ASSET_SIZE_LIMIT } from 'constants/upload';
|
||||
import { encodeMotionPhoto } from 'services/motionPhotoService';
|
||||
import { encodeLivePhoto } from 'services/livePhotoService';
|
||||
import { getFileType } from 'services/typeDetectionService';
|
||||
import {
|
||||
ElectronFile,
|
||||
|
@ -99,7 +99,7 @@ export async function readLivePhoto(
|
|||
const video = await getUint8ArrayView(livePhotoAssets.video);
|
||||
|
||||
return {
|
||||
filedata: await encodeMotionPhoto({
|
||||
filedata: await encodeLivePhoto({
|
||||
image,
|
||||
video,
|
||||
imageNameTitle: livePhotoAssets.image.name,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { SelectedState } from 'types/gallery';
|
||||
import { EnteFile, EncryptedEnteFile } from 'types/file';
|
||||
import { decodeMotionPhoto } from 'services/motionPhotoService';
|
||||
import { decodeLivePhoto } from 'services/livePhotoService';
|
||||
import { getFileType } from 'services/typeDetectionService';
|
||||
import DownloadManager from 'services/downloadManager';
|
||||
import { logError } from 'utils/sentry';
|
||||
|
@ -82,25 +82,19 @@ export async function downloadFile(
|
|||
}
|
||||
|
||||
if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {
|
||||
const motionPhoto = await decodeMotionPhoto(file, fileBlob);
|
||||
const image = new File(
|
||||
[motionPhoto.image],
|
||||
motionPhoto.imageNameTitle
|
||||
);
|
||||
const livePhoto = await decodeLivePhoto(file, fileBlob);
|
||||
const image = new File([livePhoto.image], livePhoto.imageNameTitle);
|
||||
const imageType = await getFileType(image);
|
||||
const tempImageURL = URL.createObjectURL(
|
||||
new Blob([motionPhoto.image], { type: imageType.mimeType })
|
||||
);
|
||||
const video = new File(
|
||||
[motionPhoto.video],
|
||||
motionPhoto.videoNameTitle
|
||||
new Blob([livePhoto.image], { type: imageType.mimeType })
|
||||
);
|
||||
const video = new File([livePhoto.video], livePhoto.videoNameTitle);
|
||||
const videoType = await getFileType(video);
|
||||
const tempVideoURL = URL.createObjectURL(
|
||||
new Blob([motionPhoto.video], { type: videoType.mimeType })
|
||||
new Blob([livePhoto.video], { type: videoType.mimeType })
|
||||
);
|
||||
downloadUsingAnchor(tempImageURL, motionPhoto.imageNameTitle);
|
||||
downloadUsingAnchor(tempVideoURL, motionPhoto.videoNameTitle);
|
||||
downloadUsingAnchor(tempImageURL, livePhoto.imageNameTitle);
|
||||
downloadUsingAnchor(tempVideoURL, livePhoto.videoNameTitle);
|
||||
} else {
|
||||
const fileType = await getFileType(
|
||||
new File([fileBlob], file.metadata.title)
|
||||
|
@ -315,11 +309,11 @@ async function getRenderableLivePhoto(
|
|||
file: EnteFile,
|
||||
fileBlob: Blob
|
||||
): Promise<Blob[]> {
|
||||
const motionPhoto = await decodeMotionPhoto(file, fileBlob);
|
||||
const imageBlob = new Blob([motionPhoto.image]);
|
||||
const livePhoto = await decodeLivePhoto(file, fileBlob);
|
||||
const imageBlob = new Blob([livePhoto.image]);
|
||||
return await Promise.all([
|
||||
getRenderableImage(motionPhoto.imageNameTitle, imageBlob),
|
||||
getPlayableVideo(motionPhoto.videoNameTitle, motionPhoto.video),
|
||||
getRenderableImage(livePhoto.imageNameTitle, imageBlob),
|
||||
getPlayableVideo(livePhoto.videoNameTitle, livePhoto.video),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ import {
|
|||
} from './faceCrop';
|
||||
import { CACHES } from 'constants/cache';
|
||||
import { FILE_TYPE } from 'constants/file';
|
||||
import { decodeMotionPhoto } from 'services/motionPhotoService';
|
||||
import { decodeLivePhoto } from 'services/livePhotoService';
|
||||
import { addLogLine } from 'utils/logging';
|
||||
import { Remote } from 'comlink';
|
||||
import { DedicatedCryptoWorker } from 'worker/crypto.worker';
|
||||
|
@ -361,10 +361,10 @@ async function getOriginalConvertedFile(
|
|||
if (file.metadata.fileType === FILE_TYPE.IMAGE) {
|
||||
return await getRenderableImage(file.metadata.title, fileBlob);
|
||||
} else {
|
||||
const motionPhoto = await decodeMotionPhoto(file, fileBlob);
|
||||
const livePhoto = await decodeLivePhoto(file, fileBlob);
|
||||
return await getRenderableImage(
|
||||
motionPhoto.imageNameTitle,
|
||||
new Blob([motionPhoto.image])
|
||||
livePhoto.imageNameTitle,
|
||||
new Blob([livePhoto.image])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue