-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (31 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const util = require('util')
const {Storage} = require('@google-cloud/storage');
const vision = require('@google-cloud/vision');
const storage = new Storage()
const VALID_PHOTOS_BUCKET = storage.bucket('valid-photos')
exports.personMuffin = function (event, callback) {
const data = event.data
processFile(data.bucket, data.name, callback)
}
function processFile (bucket, file, callback) {
const client = new vision.ImageAnnotatorClient()
client.faceDetection(`gs://${bucket}/${file}`)
.then((result) => {
faces = result[0].faceAnnotations
console.log('number of faces', faces.length)
if (faces.length === 1) {
console.log('moving to valid')
moveToValid(bucket, file, faces, callback)
} else {
console.log('Skipping')
return callback()
}
})
.catch((error) => {
console.log('Error!!!', error)
callback(error)
})
}
function moveToValid (bucket, file, callback) {
storage.bucket(bucket).file(file).move(VALID_PHOTOS_BUCKET, callback)
}