Created
February 3, 2019 19:18
-
-
Save gantrim/5c5e264c3eb45f8df132430f98342ffe to your computer and use it in GitHub Desktop.
Firebase Part 6 - Moderate User Profile Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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