Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.blurOffensiveImages = functions.storage.object().onChange(event => {
- const object = event.data;
- console.log(event)
- // Exit if this is a move or deletion event.
- if (object.resourceState === 'not_exists') {
- return -1
- }
- if (event.data.metadata.isModerateOperation) {
- console.log("Side-effect")
- return -1
- }
- // Check the image content using the Cloud Vision API.
- return visionClient.safeSearchDetection(`gs://happyin-8708e.appspot.com/${object.name}`).then(data => {
- const { adult, violence } = data[0].safeSearchAnnotation;
- console.log("Flags: ", adult, violence)
- const _flags = ["VERY_UNLIKELY", "UNLIKELY", "POSSIBLE", "LIKELY", "VERY_LIKELY"]
- if (_flags.includes(adult) || _flags.includes(violence)) {
- let _moderatedImage = admin.storage().bucket().file('/assets/forbidden-photo.jpg')
- console.log("Copying to: " + object.name)
- return _moderatedImage.copy({
- destination: `gs://happyin-8708e.appspot.com/${object.name}`,
- metadata: {
- isModerateOperation: true
- }
- })
- }
- else
- return true
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement