Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions exif-images/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,27 @@ exports.metadata = functions.storage.object().onFinalize((object) => {
return null;
}

let metadata;
// Download file from bucket.
const bucket = gcs.bucket(object.bucket);
return bucket.file(filePath).download({destination: tempLocalFile}).then(() => {
// Get Metadata from image.
return spawn('identify', ['-verbose', tempLocalFile], {capture: ['stdout', 'stderr']});
}).then(() => {
const metadata = imageMagickOutputToObject(result.stdout);
return spawn('identify', ['-verbose', tempLocalFile], {capture: ['stdout', 'stderr']})
}).then((result) => {
// Save metadata to realtime datastore.
return admin.database().ref(makeKeyFirebaseCompatible(filePath)).set(metadata);
metadata = imageMagickOutputToObject(result.stdout);
const safeKey = makeKeyFirebaseCompatible(filePath);
return admin.database().ref(safeKey).set(metadata);
}).then(() => {
return console.log('Wrote to:', filePath, 'data:', metadata);
console.log('Wrote to:', filePath, 'data:', metadata);
return null;
}).then(() => {
// Cleanup temp directory after metadata is extracted
// Remove the file from temp directory
fs.unlinkSync(tempLocalFile);
return console.log('cleanup successful!');
return fs.unlinkSync(tempLocalFile)
}).then(() => {
console.log('cleanup successful!');
return null;
});
});

Expand Down