mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +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:
parent
dff10e89fe
commit
3e4a14b299
4 changed files with 45 additions and 75 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue