Commit 477fb7f2e1f637732ca8bb7ab31296c7108743d0
1 parent
238dc58a
Exists in
master
and in
1 other branch
Adicionado funcao no endpoints text de cadastrar/alterar requisicao no banco
Showing
1 changed file
with
23 additions
and
3 deletions
Show diff stats
| 1 | 1 | var parameters = require('../helpers/parameters'); |
| 2 | 2 | var properties = require('../helpers/properties'); |
| 3 | - | |
| 3 | +var db = require('../db/api'); | |
| 4 | 4 | var exec = require('child_process').exec, child; |
| 5 | 5 | var uuid = require('node-uuid'); |
| 6 | 6 | var fs = require('fs'); |
| 7 | 7 | |
| 8 | -function init(req, res) { | |
| 8 | +function init(req, res, Request) { | |
| 9 | 9 | |
| 10 | 10 | var id = uuid.v4(); |
| 11 | 11 | |
| ... | ... | @@ -21,6 +21,22 @@ function init(req, res) { |
| 21 | 21 | return; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | + var request_object = new Request({ | |
| 25 | + id: id, | |
| 26 | + type: req.body.servico, | |
| 27 | + status: 'Submitted', | |
| 28 | + created_at: new Date(), | |
| 29 | + updated_at: new Date(), | |
| 30 | + }); | |
| 31 | + | |
| 32 | + db.create(request_object, function(result) { | |
| 33 | + if (result !== null) { | |
| 34 | + res.send(200, { 'status': 'Requisição ' + result.id + ' cadastrada com sucesso.'}); | |
| 35 | + } else { | |
| 36 | + res.send(500, { 'error': 'Erro na criação da requisição.'}); | |
| 37 | + } | |
| 38 | + }); | |
| 39 | + | |
| 24 | 40 | /* Cria a linha de comando */ |
| 25 | 41 | var command_line = 'echo ' + req.body.texto + ' >> text_files/' + id + ' && mkdir uploads/' + id + ' && vlibras_user/vlibras-core/./vlibras ' + parameters.getServiceType(req.body.servico) + ' text_files/' + |
| 26 | 42 | id + ' ' + parameters.getTransparency(req.body.transparencia) + ' ' + id + ' WEB > /tmp/core_log 2>&1'; |
| ... | ... | @@ -34,12 +50,16 @@ function init(req, res) { |
| 34 | 50 | |
| 35 | 51 | /* Listener que dispara quando a requisição ao core finaliza */ |
| 36 | 52 | child.on('close', function(code, signal){ |
| 37 | - res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.webm' }); | |
| 53 | +// res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.webm' }); | |
| 54 | + db.update(request_object, 'Completed', function(result) { | |
| 55 | + }); | |
| 38 | 56 | }); |
| 39 | 57 | |
| 40 | 58 | /* Listener que dispara quando a requisição ao core da erro */ |
| 41 | 59 | child.on('error', function(code, signal){ |
| 42 | 60 | res.send(500, parameters.errorMessage('Erro na chamada ao core')); |
| 61 | + db.update(request_object, 'Error', function(result) { | |
| 62 | + }); | |
| 43 | 63 | }); |
| 44 | 64 | }; |
| 45 | 65 | ... | ... |