const pkg = require('../package.json');
const Identify = require('./identifyPeople.js');

function handlers() {
    function index(req, reply) {
        reply.view('index', {
            users: [
                'hello'
            ]
        });
    }

    function version(req, reply) {
        reply({version: pkg.version}).code(200);
    }

    function identifyPeople(req, reply) {
        if (!req.payload || !req.payload.url) {
            reply("Expected 'url' parameter").code(400);
            return;
        }
        let imageUrl = req.payload.url;
        Identify.findFace(imageUrl)
        .then((names) => {
            reply({"Identification results: " : JSON.stringify(names)}).code(200);
        })
        .catch((err) => {
            console.log(JSON.stringify(err, null, 2));
            reply({"Identification results" : []}).code(500);
        });
    }

    return {
        index,
        version,
        identifyPeople
    };
}

module.exports = handlers;

@@ -641,57 +641,27 @@
 y(%7B%22
-I
+i
 denti
-fication results: %22 : JSON.stringify(
+ties%22 : 
 names
-)
 %7D).c
@@ -786,29 +786,17 @@
 y(%7B%22
-I
+i
 denti
-fication result
+tie
 s%22 :

Return names as json array