mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
chore(server) harden EXIF extraction (#1347)
* chore(server) Harden EXIF extraction * Remove unused function in timeutil * Remove deadcode
This commit is contained in:
@@ -1,12 +1,4 @@
|
||||
// This is needed as resolving for the vendored
|
||||
// exiftool fails in tests otherwise but as it's not meant to be a requirement
|
||||
// of a project directly I had to include the line below the comment.
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
import { exiftool } from 'exiftool-vendored.pl';
|
||||
|
||||
function createTimeUtils() {
|
||||
const floatRegex = /[+-]?([0-9]*[.])?[0-9]+/;
|
||||
const checkValidTimestamp = (timestamp: string): boolean => {
|
||||
const parsedTimestamp = Date.parse(timestamp);
|
||||
|
||||
@@ -23,32 +15,7 @@ function createTimeUtils() {
|
||||
return date.getFullYear() > 0;
|
||||
};
|
||||
|
||||
const getTimestampFromExif = async (originalPath: string): Promise<string> => {
|
||||
try {
|
||||
const exifData = await exiftool.read(originalPath);
|
||||
|
||||
if (exifData && exifData['DateTimeOriginal']) {
|
||||
await exiftool.end();
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return exifData['DateTimeOriginal'].toString()!;
|
||||
} else {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
} catch (error) {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
};
|
||||
|
||||
const parseStringToNumber = async (original: string | undefined): Promise<number | null> => {
|
||||
const match = original?.match(floatRegex)?.[0];
|
||||
if (match) {
|
||||
return parseFloat(match);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return { checkValidTimestamp, getTimestampFromExif, parseStringToNumber };
|
||||
return { checkValidTimestamp };
|
||||
}
|
||||
|
||||
export const timeUtils = createTimeUtils();
|
||||
|
||||
Reference in New Issue
Block a user