This commit is contained in:
Manav Rathi 2024-05-11 11:24:07 +05:30
parent 6f82881ac3
commit 550ad94257
No known key found for this signature in database

View file

@ -485,6 +485,13 @@ async function getRenderableFileURL(
originalFileURL: string,
forceConvert: boolean,
): Promise<SourceURLs> {
const existingOrNewObjectURL = (convertedBlob: Blob) =>
convertedBlob
? convertedBlob === fileBlob
? originalFileURL
: URL.createObjectURL(convertedBlob)
: undefined;
let srcURLs: SourceURLs["url"];
let mimeType: string | undefined;
switch (file.metadata.fileType) {
@ -493,13 +500,9 @@ async function getRenderableFileURL(
file.metadata.title,
fileBlob,
);
const convertedURL = getFileObjectURL(
originalFileURL,
fileBlob,
convertedBlob,
);
const convertedURL = existingOrNewObjectURL(convertedBlob);
srcURLs = convertedURL;
mimeType = convertedBlob.type;
mimeType = convertedBlob?.type;
break;
}
case FILE_TYPE.LIVE_PHOTO: {
@ -516,13 +519,9 @@ async function getRenderableFileURL(
fileBlob,
forceConvert,
);
const convertedURL = getFileObjectURL(
originalFileURL,
fileBlob,
convertedBlob,
);
const convertedURL = existingOrNewObjectURL(convertedBlob);
srcURLs = convertedURL;
mimeType = convertedBlob.type;
mimeType = convertedBlob?.type;
break;
}
default: {
@ -551,19 +550,6 @@ async function getRenderableFileURL(
};
}
const getFileObjectURL = (
originalFileURL: string,
originalBlob: Blob,
convertedBlob: Blob,
) => {
const convertedURL = convertedBlob
? convertedBlob === originalBlob
? originalFileURL
: URL.createObjectURL(convertedBlob)
: null;
return convertedURL;
};
async function getRenderableLivePhotoURL(
file: EnteFile,
fileBlob: Blob,