This commit is contained in:
Manav Rathi
2024-04-24 16:14:10 +05:30
parent 2b82c61853
commit 6f6ade1901
2 changed files with 10 additions and 16 deletions

View File

@@ -46,8 +46,6 @@ export const WHITELISTED_FILE_FORMATS: FileTypeInfo[] = [
export const KNOWN_NON_MEDIA_FORMATS = ["xmp", "html", "txt"];
export const EXIFLESS_FORMATS = ["gif", "bmp"];
// this is the chunk size of the un-encrypted file which is read and encrypted before uploading it as a single part.
export const MULTIPART_PART_SIZE = 20 * 1024 * 1024;

View File

@@ -1,13 +1,11 @@
import log from "@/next/log";
import { CustomError } from "@ente/shared/error";
import { validateAndGetCreationUnixTimeInMicroSeconds } from "@ente/shared/time";
import { EXIFLESS_FORMATS, NULL_LOCATION } from "constants/upload";
import { NULL_LOCATION } from "constants/upload";
import exifr from "exifr";
import piexif from "piexifjs";
import { FileTypeInfo, Location } from "types/upload";
const EXIFR_UNSUPPORTED_FILE_FORMAT_MESSAGE = "Unknown file format";
type ParsedEXIFData = Record<string, any> &
Partial<{
DateTimeOriginal: Date;
@@ -38,11 +36,14 @@ type RawEXIFData = Record<string, any> &
export async function getParsedExifData(
receivedFile: File,
fileTypeInfo: FileTypeInfo,
{ exactType }: FileTypeInfo,
tags?: string[],
): Promise<ParsedEXIFData> {
const exifLessFormats = ["gif", "bmp"];
const exifrUnsupportedFileFormatMessage = "Unknown file format";
try {
if (EXIFLESS_FORMATS.includes(fileTypeInfo.exactType)) {
if (exifLessFormats.includes(exactType)) {
return null;
}
const exifData: RawEXIFData = await exifr.parse(receivedFile, {
@@ -66,16 +67,11 @@ export async function getParsedExifData(
: exifData;
return parseExifData(filteredExifData);
} catch (e) {
if (e.message === EXIFR_UNSUPPORTED_FILE_FORMAT_MESSAGE) {
log.error(
`exif library unsupported format ${fileTypeInfo.exactType}`,
e,
);
if (e.message == exifrUnsupportedFileFormatMessage) {
log.error(`EXIFR does not support format ${exactType}`, e);
return undefined;
} else {
log.error(
`get parsed exif data failed for file type ${fileTypeInfo.exactType}`,
e,
);
log.error(`Failed to parse EXIF data of ${exactType} file`, e);
throw e;
}
}