Commit d12974b585919270666cdbcf88b9b3c2cb411b06

Authored by FrancoNeto
1 parent 07ab929c
Exists in master

Adiciona nova versao da API do wikilibras

endpoints/sinal.js
@@ -3,15 +3,15 @@ var API = require('../db/api'); @@ -3,15 +3,15 @@ var API = require('../db/api');
3 3
4 function init_endpoint(req, res, Sign) { 4 function init_endpoint(req, res, Sign) {
5 /* Verifica se o paramêtro [name] existe ou possui algum valor */ 5 /* Verifica se o paramêtro [name] existe ou possui algum valor */
6 - if ((req.body.name === '') || (req.body.name === undefined)) {  
7 - res.send(500, { 'error': 'Especifique o nome do sinal' }); 6 + if ((req.body.userId === '') || (req.body.userId === undefined)) {
  7 + res.send(500, { 'error': 'Especifique o usuário'});
8 return; 8 return;
9 } 9 }
10 10
11 var array = ['Sucesso', 'Falhou', 'Processando'] 11 var array = ['Sucesso', 'Falhou', 'Processando']
12 12
13 var sign_object = new Sign({ 13 var sign_object = new Sign({
14 - name: req.body.name, 14 + name: req.body.userId,
15 uuid: uuid.v4(), 15 uuid: uuid.v4(),
16 created_at: new Date(), 16 created_at: new Date(),
17 updated_at: new Date(), 17 updated_at: new Date(),
@@ -10,9 +10,11 @@ @@ -10,9 +10,11 @@
10 "author": "LAViD", 10 "author": "LAViD",
11 "license": "MIT", 11 "license": "MIT",
12 "dependencies": { 12 "dependencies": {
  13 + "body-parser": "^1.9.2",
13 "express": "~3.5.1", 14 "express": "~3.5.1",
14 "mkdirp": "^0.5.0", 15 "mkdirp": "^0.5.0",
15 "mongoose": "^3.8.16", 16 "mongoose": "^3.8.16",
16 - "node-uuid": "^1.4.1" 17 + "node-uuid": "^1.4.1",
  18 + "python-shell": "0.0.3"
17 } 19 }
18 } 20 }
@@ -7,8 +7,16 @@ var endpoint_sinal = require('./endpoints/sinal'); @@ -7,8 +7,16 @@ var endpoint_sinal = require('./endpoints/sinal');
7 /* Environment */ 7 /* Environment */
8 var path = require('path'); 8 var path = require('path');
9 var express = require('express'); 9 var express = require('express');
  10 +var bodyParser = require('body-parser');
  11 +var PythonShell = require('python-shell');
10 var app = express(); 12 var app = express();
11 13
  14 +var options = {
  15 + pythonPath: 'python3',
  16 + scriptPath: __dirname + '/../ScriptsPython_Blender_2_70',
  17 + args: []
  18 +};
  19 +
12 /* Database */ 20 /* Database */
13 var mongoose = require('mongoose'); 21 var mongoose = require('mongoose');
14 require('./db/config').connect(mongoose); 22 require('./db/config').connect(mongoose);
@@ -26,23 +34,15 @@ app.get('/signs', function(req, res) { @@ -26,23 +34,15 @@ app.get('/signs', function(req, res) {
26 res.sendfile('views/index.html'); 34 res.sendfile('views/index.html');
27 }); 35 });
28 36
29 -app.post('/api', function(req, res) {  
30 - /* Verifica se o paramêtro [servico] existe ou possui algum valor */  
31 - if ((req.body.servico === '') || (req.body.servico === undefined)) {  
32 - res.send(500, { 'error': 'Especifique o tipo do serviço' });  
33 - return;  
34 - }  
35 -  
36 - /* Analisa o tipo de serviço requisitado */  
37 - switch(req.body.servico) {  
38 - case 'sinal':  
39 - endpoint_sinal.init(req, res, Sign);  
40 - break; 37 +app.post('/sinal', function(req, res) {
  38 + options.args = JSON.stringify(req.body);
  39 + PythonShell.run('Controller.py', options, function (err, results) {
  40 + if (err) { console.log(err); res.send(400); return; }
  41 + // results is an array consisting of messages collected during execution
  42 + endpoint_sinal.init(req, res, Sign);
  43 + res.send(200);
  44 + });
41 45
42 - default:  
43 - res.send(500, { 'error': 'Tipo do serviço inválido.'});  
44 - break;  
45 - }  
46 }); 46 });
47 47
48 app.get('/api/signs', function(req, res) { 48 app.get('/api/signs', function(req, res) {
views/index.html
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 <thead> 25 <thead>
26 <tr> 26 <tr>
27 <th>#</th> 27 <th>#</th>
28 - <th>Nome</th> 28 + <th>UserId</th>
29 <th>Hash</th> 29 <th>Hash</th>
30 <th>Criado em</th> 30 <th>Criado em</th>
31 <th>Atualizado em</th> 31 <th>Atualizado em</th>