-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathface-api.js
70 lines (66 loc) · 2.94 KB
/
face-api.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Import required modules
const input_node = require('./app/nodes/input_node')
const recognise_node = require('./app/nodes/recognise_node')
const add_descriptors = require('./app/endpoints/add_descriptors');
const check_descriptors = require('./app/endpoints/check_descriptors');
const delete_descriptors = require('./app/endpoints/delete_descriptors');
const create_descriptor_location = require('./app/helpers/create_descriptor_location');
// Set the global variables for the app
global.descriptor_location = require('path').join(__dirname, 'app/descriptors')
create_descriptor_location(global.descriptor_location);
// Export the nodes
module.exports = function (RED) {
// Recognise Node Constructor
function recognise_node_creator(config) {
recognise_node(RED, config, this)
}
RED.nodes.registerType("face-api-recognise", recognise_node_creator);
// Input Node constructor
function input_node_creator(config) {
input_node(RED, config, this);
}
RED.nodes.registerType("face-api-input", input_node_creator)
// HTTP Endpoints for use with the front end
RED.httpAdmin.get('/faceapi/:id/check', RED.auth.needsPermission('face-api-recognise.upload'), async function (req, res) {
RED.log.debug("Finding descriptors for " + req.params.id);
check_descriptors(RED, req.params.id)
.then((value) => {
res.status(200).send(String(value)).end();
})
.catch((err) => {
RED.log.error(err);
res.status(200).send("0").end();
})
});
RED.httpAdmin.post('/faceapi/:id/create', RED.auth.needsPermission('face-api-recognise.upload'), async function (req, res) {
RED.log.debug("Attempting to create descriptors for " + req.params.id);
add_descriptors(RED, req, res)
.then((code) => {
RED.log.info("Successfully created descriptors for " + req.params.id);
res.status(code).send('OK').end();
})
.catch((err) => {
RED.log.error(err);
res.status(400).send(err).end();
})
});
RED.httpAdmin.get('/faceapi/:id/delete', RED.auth.needsPermission('face-api-recognise.upload'), async function (req, res) {
RED.log.debug("Attempting to delete descriptors for " + req.params.id);
delete_descriptors(RED, req.params.id)
.then((code) => {
RED.log.info("Successfully deleted descriptors for " + req.params.id);
res.status(201).send('OK').end();
})
.catch((err) => {
RED.log.error(err);
switch (err) {
case 400:
res.status(400).send('OK').end();
break;
case 404:
res.send("No node found matching " + req.params.id).status(404).end();
break;
}
})
});
}