Skip to content

Commit

Permalink
Add extra validation for metadata in organize.js
Browse files Browse the repository at this point in the history
Should fix issue #6
  • Loading branch information
Alamantus authored Apr 29, 2021
1 parent fde66c0 commit 24dd39c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions public/organize.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ function organizeFolder(currentPath, organizeIntoPath, renameStrategy = 'KEEP',
}
let meta = fs.readFileSync(metaPath, 'utf-8');
meta = JSON.parse(meta);
if (typeof meta.photoTakenTime === 'undefined') {
return reject({
removeFileToProcess: true,
});
}
photoTakenTime = meta.photoTakenTime.formatted;

const date = new Date(photoTakenTime);
Expand Down Expand Up @@ -121,7 +126,9 @@ function organizeFolder(currentPath, organizeIntoPath, renameStrategy = 'KEEP',
utimes(newFileName, {
btime: date.getTime(),
atime: Date.now(),
mtime: new Date(meta.modificationTime.formatted).getTime(),
mtime: typeof meta.modificationTime !== 'undefined'
? new Date(meta.modificationTime.formatted).getTime()
: date.getTime(),
}).then(() => {
if (typeof meta.geoData !== 'undefined' && ['.jpg', '.jpeg'].includes(extension) && insertExif) {
// If GPS is available and desired, insert GPS into image.
Expand Down Expand Up @@ -244,4 +251,4 @@ function approxRatio(eps) {
}
}

module.exports = organize;
module.exports = organize;

0 comments on commit 24dd39c

Please sign in to comment.