Skip to content

Instantly share code, notes, and snippets.

@gantrim
Created February 3, 2019 19:18
Show Gist options
  • Save gantrim/5c5e264c3eb45f8df132430f98342ffe to your computer and use it in GitHub Desktop.
Save gantrim/5c5e264c3eb45f8df132430f98342ffe to your computer and use it in GitHub Desktop.
Firebase Part 6 - Moderate User Profile Image
module.exports.moderateUserProfileImage = function(object) {
const userId = object.name.split('/')[1];
const userDocRef = admin.firestore().collection('users').doc(userId);
return userDocRef.get()
.then(doc => {
const user = doc.data();
// The image has already been moderated.
if (user.locked === true) {
console.log('already moderated!');
return;
}
// Check the image content using the Cloud Vision API.
return visionClient.safeSearchDetection(`gs://${object.bucket}/${object.name}`);
})
.then((results) => {
if (!results) {
return;
}
const detections = results[0].safeSearchAnnotation;
if (detections.adult || detections.violence) {
console.log('The image', object.name, 'has been detected as inappropriate.');
return blurImage(object, userDocRef);
}
else {
console.log('The image', object.name, ' has been detected as OK.');
return null;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment