Commit aee6c82790cc081c9d5acafaa1b0a952b5abd555
1 parent
027e855a
Exists in
master
and in
1 other branch
Refatora requisições post em video_legenda
Showing
1 changed file
with
8 additions
and
70 deletions
Show diff stats
endpoints/video_legenda.js
| 1 | 1 | var parameters = require('../helpers/parameters'); |
| 2 | 2 | var properties = require('../helpers/properties'); |
| 3 | +var requests = require('../helpers/requests'); | |
| 3 | 4 | |
| 4 | 5 | var exec = require('child_process').exec, child; |
| 5 | 6 | var querystring = require('querystring'); |
| ... | ... | @@ -56,7 +57,7 @@ function init(req, res) { |
| 56 | 57 | var command_line = 'vlibras_user/vlibras-core/./vlibras ' + parameters.getServiceType(req.body.servico) + ' uploads/' + id + '/' + |
| 57 | 58 | req.files.video.name + ' uploads/' + id + '/' + req.files.legenda.name + ' ' + parameters.getLanguage(req.body.linguagem) + |
| 58 | 59 | ' ' + parameters.getPosition(req.body.posicao) + ' ' + parameters.getSize(req.body.tamanho) + ' ' + |
| 59 | - parameters.getTransparency(req.body.transparencia) + ' ' + id + '> /tmp/core_log 2>&1'; | |
| 60 | + parameters.getTransparency(req.body.transparencia) + ' ' + id + ' > /tmp/core_log 2>&1'; | |
| 60 | 61 | |
| 61 | 62 | console.log(command_line); |
| 62 | 63 | |
| ... | ... | @@ -86,91 +87,28 @@ function init(req, res) { |
| 86 | 87 | child.on('close', function(code, signal){ |
| 87 | 88 | if (code !== 0) { |
| 88 | 89 | var path = url.parse(req.body.callback); |
| 89 | - | |
| 90 | 90 | var data = querystring.stringify( { 'error': 'Erro no Core', 'code': code } ); |
| 91 | 91 | |
| 92 | - var options = { | |
| 93 | - host: path.hostname, | |
| 94 | - port: path.port, | |
| 95 | - path: path.path, | |
| 96 | - method: 'POST', | |
| 97 | - headers: { | |
| 98 | - 'Content-Type': 'application/x-www-form-urlencoded', | |
| 99 | - 'Content-Length': Buffer.byteLength(data) | |
| 100 | - } | |
| 101 | - }; | |
| 102 | - | |
| 103 | - var requesting = http.request(options, function(res) { | |
| 104 | - res.setEncoding('utf8'); | |
| 105 | - }); | |
| 106 | - | |
| 107 | - requesting.on('error', function (e) { | |
| 108 | - console.log("The callback URL can not be reachable"); | |
| 109 | - }); | |
| 110 | - | |
| 111 | - requesting.write(data); | |
| 112 | - requesting.end(); | |
| 92 | + requests.postRequest(path, data); | |
| 113 | 93 | |
| 114 | 94 | return; |
| 115 | 95 | } |
| 116 | 96 | |
| 117 | 97 | var path = url.parse(req.body.callback); |
| 118 | - | |
| 119 | 98 | var data = querystring.stringify({ 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.flv' }); |
| 120 | 99 | |
| 121 | - var options = { | |
| 122 | - host: path.hostname, | |
| 123 | - port: path.port, | |
| 124 | - path: path.path, | |
| 125 | - method: 'POST', | |
| 126 | - headers: { | |
| 127 | - 'Content-Type': 'application/x-www-form-urlencoded', | |
| 128 | - 'Content-Length': Buffer.byteLength(data) | |
| 129 | - } | |
| 130 | - }; | |
| 131 | - | |
| 132 | - var requesting = http.request(options, function(res) { | |
| 133 | - res.setEncoding('utf8'); | |
| 134 | - }); | |
| 135 | - | |
| 136 | - requesting.on('error', function (e) { | |
| 137 | - console.log("The callback URL can not be reachable"); | |
| 138 | - }); | |
| 139 | - | |
| 140 | - requesting.write(data); | |
| 141 | - requesting.end(); | |
| 100 | + requests.postRequest(path, data); | |
| 142 | 101 | }); |
| 143 | 102 | |
| 144 | 103 | /* Listener que dispara quando a requisição ao core da erro */ |
| 145 | 104 | child.on('error', function(code, signal){ |
| 146 | - var path = url.parse(req.body.callback); | |
| 105 | + var path = url.parse(req.body.callback); | |
| 106 | + var data = querystring.stringify( { 'error': 'Erro na chamada ao core', 'code': code, 'id': id } ); | |
| 147 | 107 | |
| 148 | - var data = querystring.stringify( { 'error': 'Erro na chamada ao Core', 'code': code } ); | |
| 149 | - | |
| 150 | - var options = { | |
| 151 | - host: path.hostname, | |
| 152 | - port: path.port, | |
| 153 | - path: path.path, | |
| 154 | - method: 'POST', | |
| 155 | - headers: { | |
| 156 | - 'Content-Type': 'application/x-www-form-urlencoded', | |
| 157 | - 'Content-Length': Buffer.byteLength(data) | |
| 158 | - } | |
| 159 | - }; | |
| 160 | - | |
| 161 | - var requesting = http.request(options, function(res) { | |
| 162 | - res.setEncoding('utf8'); | |
| 163 | - }); | |
| 164 | - | |
| 165 | - requesting.on('error', function (e) { | |
| 166 | - console.log("The callback URL can not be reachable"); | |
| 167 | - }); | |
| 168 | - | |
| 169 | - requesting.write(data); | |
| 170 | - requesting.end(); | |
| 108 | + requests.postRequest(path, data); | |
| 171 | 109 | }); |
| 172 | 110 | |
| 173 | - res.send(200); | |
| 111 | + res.send(200, JSON.stringify({ 'id': id })); | |
| 174 | 112 | } |
| 175 | 113 | }); |
| 176 | 114 | }; | ... | ... |