From d12974b585919270666cdbcf88b9b3c2cb411b06 Mon Sep 17 00:00:00 2001 From: FrancoNeto Date: Mon, 17 Nov 2014 12:24:07 -0200 Subject: [PATCH] Adiciona nova versao da API do wikilibras --- endpoints/sinal.js | 6 +++--- package.json | 4 +++- server.js | 32 ++++++++++++++++---------------- views/index.html | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/endpoints/sinal.js b/endpoints/sinal.js index 5a3a274..8f839c1 100644 --- a/endpoints/sinal.js +++ b/endpoints/sinal.js @@ -3,15 +3,15 @@ var API = require('../db/api'); function init_endpoint(req, res, Sign) { /* Verifica se o paramêtro [name] existe ou possui algum valor */ - if ((req.body.name === '') || (req.body.name === undefined)) { - res.send(500, { 'error': 'Especifique o nome do sinal' }); + if ((req.body.userId === '') || (req.body.userId === undefined)) { + res.send(500, { 'error': 'Especifique o usuário'}); return; } var array = ['Sucesso', 'Falhou', 'Processando'] var sign_object = new Sign({ - name: req.body.name, + name: req.body.userId, uuid: uuid.v4(), created_at: new Date(), updated_at: new Date(), diff --git a/package.json b/package.json index de41871..e0883ae 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,11 @@ "author": "LAViD", "license": "MIT", "dependencies": { + "body-parser": "^1.9.2", "express": "~3.5.1", "mkdirp": "^0.5.0", "mongoose": "^3.8.16", - "node-uuid": "^1.4.1" + "node-uuid": "^1.4.1", + "python-shell": "0.0.3" } } diff --git a/server.js b/server.js index a41c8c0..2eccb70 100644 --- a/server.js +++ b/server.js @@ -7,8 +7,16 @@ var endpoint_sinal = require('./endpoints/sinal'); /* Environment */ var path = require('path'); var express = require('express'); +var bodyParser = require('body-parser'); +var PythonShell = require('python-shell'); var app = express(); +var options = { + pythonPath: 'python3', + scriptPath: __dirname + '/../ScriptsPython_Blender_2_70', + args: [] +}; + /* Database */ var mongoose = require('mongoose'); require('./db/config').connect(mongoose); @@ -26,23 +34,15 @@ app.get('/signs', function(req, res) { res.sendfile('views/index.html'); }); -app.post('/api', function(req, res) { - /* Verifica se o paramêtro [servico] existe ou possui algum valor */ - if ((req.body.servico === '') || (req.body.servico === undefined)) { - res.send(500, { 'error': 'Especifique o tipo do serviço' }); - return; - } - - /* Analisa o tipo de serviço requisitado */ - switch(req.body.servico) { - case 'sinal': - endpoint_sinal.init(req, res, Sign); - break; +app.post('/sinal', function(req, res) { + options.args = JSON.stringify(req.body); + PythonShell.run('Controller.py', options, function (err, results) { + if (err) { console.log(err); res.send(400); return; } + // results is an array consisting of messages collected during execution + endpoint_sinal.init(req, res, Sign); + res.send(200); + }); - default: - res.send(500, { 'error': 'Tipo do serviço inválido.'}); - break; - } }); app.get('/api/signs', function(req, res) { diff --git a/views/index.html b/views/index.html index f5091b3..fed605c 100644 --- a/views/index.html +++ b/views/index.html @@ -25,7 +25,7 @@ # - Nome + UserId Hash Criado em Atualizado em -- libgit2 0.21.2