Commit c809d6c35ca029703e5a54a02652f127a81ed909
1 parent
de519bce
Exists in
master
and in
1 other branch
fix postRequest and add url to test
Showing
6 changed files
with
66 additions
and
29 deletions
Show diff stats
endpoints/legenda.js
@@ -28,7 +28,7 @@ function init(req, res) { | @@ -28,7 +28,7 @@ function init(req, res) { | ||
28 | } | 28 | } |
29 | 29 | ||
30 | /* Checa se o arquivo de legenda submetivo possui uma extensão válida */ | 30 | /* Checa se o arquivo de legenda submetivo possui uma extensão válida */ |
31 | - if (parameters.checkSubtitle(req.files.legenda.name) == false) { | 31 | + if (parameters.checkSubtitle(req.files.legenda.name) === false) { |
32 | res.send(500, parameters.errorMessage('Legenda com Extensão Inválida')); | 32 | res.send(500, parameters.errorMessage('Legenda com Extensão Inválida')); |
33 | return; | 33 | return; |
34 | } | 34 | } |
endpoints/videornp.js
@@ -12,6 +12,11 @@ var _ = require('lodash'); | @@ -12,6 +12,11 @@ var _ = require('lodash'); | ||
12 | var kue = require('kue'), | 12 | var kue = require('kue'), |
13 | queue = kue.createQueue(); | 13 | queue = kue.createQueue(); |
14 | var logger = require('../logsystem/main.js'); | 14 | var logger = require('../logsystem/main.js'); |
15 | +var url = require('url'); | ||
16 | +var requests = require('../helpers/requests'); | ||
17 | +var querystring = require('querystring'); | ||
18 | + | ||
19 | + | ||
15 | 20 | ||
16 | 21 | ||
17 | function init(req, res, Request) { | 22 | function init(req, res, Request) { |
@@ -183,7 +188,7 @@ function callCoreSubtitle(id, subtitle, req, res, Request, request_object) { | @@ -183,7 +188,7 @@ function callCoreSubtitle(id, subtitle, req, res, Request, request_object) { | ||
183 | } | 188 | } |
184 | 189 | ||
185 | var command_line = 'vlibras_user/vlibras-core/./vlibras -S ' + ' uploads/' + id + '/' + | 190 | var command_line = 'vlibras_user/vlibras-core/./vlibras -S ' + ' uploads/' + id + '/' + |
186 | - legenda_name + ' -l portugues -b opaco --id' + id + ' --mode devel > /tmp/core_log 2>&1'; | 191 | + legenda_name + ' -l portugues -b opaco --id ' + id + ' --mode devel > /tmp/core_log 2>&1'; |
187 | 192 | ||
188 | 193 | ||
189 | var child; | 194 | var child; |
@@ -203,26 +208,44 @@ function callCoreSubtitle(id, subtitle, req, res, Request, request_object) { | @@ -203,26 +208,44 @@ function callCoreSubtitle(id, subtitle, req, res, Request, request_object) { | ||
203 | // console.log(stdout); | 208 | // console.log(stdout); |
204 | }); | 209 | }); |
205 | 210 | ||
211 | + var data, path; | ||
212 | + // Endereço do callback | ||
213 | + if (req.body.callback !== undefined) { | ||
214 | + path = url.parse(req.body.callback); | ||
215 | + } | ||
216 | + | ||
206 | /* Listener que dispara quando a requisição ao core finaliza */ | 217 | /* Listener que dispara quando a requisição ao core finaliza */ |
207 | child.on('close', function(code, signal){ | 218 | child.on('close', function(code, signal){ |
208 | - | ||
209 | - // res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.flv' }); | ||
210 | - | ||
211 | - // Se o core executou com erro | ||
212 | - if (code !== 0) { | ||
213 | - db.update(Request, request_object.id, 'Error', function (result) {}); | ||
214 | - console.log("Erro no retorno do core. Código: " + code); | ||
215 | - logger.incrementError('core', "Erro no retorno do core. Código: " + code); | ||
216 | - } else { | ||
217 | - // Se o core executou normal | ||
218 | - db.update(Request, request_object.id, 'Completed', function (result) {}); | ||
219 | - res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.mp4'}); | ||
220 | - logger.incrementService("videos", "traducoes"); | ||
221 | - } | ||
222 | - }); | ||
223 | - | ||
224 | - | ||
225 | - }); | 219 | + // Se o core executou com erro |
220 | + if (code !== 0) { | ||
221 | + db.update(Request, request_object.id, 'Error', function (result) {}); | ||
222 | + console.log("Erro no retorno do core. Código: " + code); | ||
223 | + logger.incrementError('core', "Erro no retorno do core. Código: " + code); | ||
224 | + data = { | ||
225 | + 'error' : "Erro no Core", | ||
226 | + 'code' : code, | ||
227 | + 'id' : id | ||
228 | + }; | ||
229 | + } else { | ||
230 | + // Se o core executou normal | ||
231 | + db.update(Request, request_object.id, 'Completed', function (result) {}); | ||
232 | + res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.mp4'}); | ||
233 | + logger.incrementService("videos", "traducoes"); | ||
234 | + data = { | ||
235 | + 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.mp4', | ||
236 | + 'versao' : '1.0', | ||
237 | + 'legenda' : '' | ||
238 | + }; | ||
239 | + } | ||
240 | + | ||
241 | + if (req.body.callback !== undefined) { | ||
242 | + data = querystring.stringify(data); | ||
243 | + requests.postRequest(path, data); | ||
244 | + } | ||
245 | + }); | ||
246 | + | ||
247 | + | ||
248 | + }); | ||
226 | 249 | ||
227 | /* Listener que dispara quando a requisição ao core da erro */ | 250 | /* Listener que dispara quando a requisição ao core da erro */ |
228 | child.on('error', function(code, signal){ | 251 | child.on('error', function(code, signal){ |
helpers/core.js
@@ -68,7 +68,7 @@ function call(id, command_line, req, res, Request, request_object, req_type) { | @@ -68,7 +68,7 @@ function call(id, command_line, req, res, Request, request_object, req_type) { | ||
68 | 68 | ||
69 | // Se a chamada foi feita com sucesso | 69 | // Se a chamada foi feita com sucesso |
70 | child.on('close', function(code, signal) { | 70 | child.on('close', function(code, signal) { |
71 | - var data; | 71 | + var data; |
72 | 72 | ||
73 | // Endereço do callback | 73 | // Endereço do callback |
74 | var path = url.parse(req.body.callback); | 74 | var path = url.parse(req.body.callback); |
@@ -87,15 +87,24 @@ function call(id, command_line, req, res, Request, request_object, req_type) { | @@ -87,15 +87,24 @@ function call(id, command_line, req, res, Request, request_object, req_type) { | ||
87 | }); | 87 | }); |
88 | console.log("Erro no retorno do core. Código: " + code); | 88 | console.log("Erro no retorno do core. Código: " + code); |
89 | logger.incrementError('core', "Erro no retorno do core. Código: " + code); | 89 | logger.incrementError('core', "Erro no retorno do core. Código: " + code); |
90 | + data = { | ||
91 | + 'error' : code | ||
92 | + }; | ||
90 | } else { | 93 | } else { |
91 | // Se o core executou normal | 94 | // Se o core executou normal |
92 | db.update(Request, request_object.id, 'Completed', function (result) {}); | 95 | db.update(Request, request_object.id, 'Completed', function (result) {}); |
93 | res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.mp4'}); | 96 | res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.mp4'}); |
94 | logger.incrementService(req_type, "traducoes"); | 97 | logger.incrementService(req_type, "traducoes"); |
95 | - } | ||
96 | 98 | ||
97 | - // Chama o callback | ||
98 | - requests.postRequest(path, data); | 99 | + data = { |
100 | + 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + id + '.mp4', | ||
101 | + 'versao' : '1.0', | ||
102 | + 'legenda' : '' | ||
103 | + }; | ||
104 | + } | ||
105 | + console.log("Path == " + path); | ||
106 | + data = querystring.stringify(data); | ||
107 | + requests.postRequest(path, data); | ||
99 | }); | 108 | }); |
100 | 109 | ||
101 | // Se a chamada deu erro | 110 | // Se a chamada deu erro |
helpers/requests.js
@@ -14,8 +14,8 @@ function postRequest(path, data) { | @@ -14,8 +14,8 @@ function postRequest(path, data) { | ||
14 | 14 | ||
15 | var requesting = http.request(options, function(res) { | 15 | var requesting = http.request(options, function(res) { |
16 | /* Debugging */ | 16 | /* Debugging */ |
17 | - | ||
18 | - console.log('== Chamando callback: ' + path.hostname) | 17 | + |
18 | + console.log('=== Chamando callback: ' + path.hostname); | ||
19 | console.log('=== Response status: ' + res.statusCode); | 19 | console.log('=== Response status: ' + res.statusCode); |
20 | console.log('=== Response headers: ' + JSON.stringify(res.headers)); | 20 | console.log('=== Response headers: ' + JSON.stringify(res.headers)); |
21 | 21 | ||
@@ -24,7 +24,7 @@ function postRequest(path, data) { | @@ -24,7 +24,7 @@ function postRequest(path, data) { | ||
24 | res.on('data', function (chunk) { | 24 | res.on('data', function (chunk) { |
25 | console.log('=== Response body: ' + chunk); | 25 | console.log('=== Response body: ' + chunk); |
26 | }); | 26 | }); |
27 | - | 27 | + |
28 | }); | 28 | }); |
29 | 29 | ||
30 | requesting.on('error', function (e) { | 30 | requesting.on('error', function (e) { |
@@ -35,4 +35,4 @@ function postRequest(path, data) { | @@ -35,4 +35,4 @@ function postRequest(path, data) { | ||
35 | requesting.end(); | 35 | requesting.end(); |
36 | } | 36 | } |
37 | 37 | ||
38 | -module.exports.postRequest = postRequest; | ||
39 | \ No newline at end of file | 38 | \ No newline at end of file |
39 | +module.exports.postRequest = postRequest; |
logsystem/errors.log
server.js
@@ -41,6 +41,11 @@ app.get('/', function(req, res){ | @@ -41,6 +41,11 @@ app.get('/', function(req, res){ | ||
41 | res.send(200, { 'status': 'server is running!' } ); | 41 | res.send(200, { 'status': 'server is running!' } ); |
42 | }); | 42 | }); |
43 | 43 | ||
44 | +app.post('/testcallback', function(req, res) { | ||
45 | + console.log(req.body); | ||
46 | + res.send(200, { 'status': 'Callback OK' } ); | ||
47 | +}); | ||
48 | + | ||
44 | app.post('/api', function(req, res) { | 49 | app.post('/api', function(req, res) { |
45 | console.log("\n\n\n============================================="); | 50 | console.log("\n\n\n============================================="); |
46 | console.log("[" + new Date().toISOString() + "] Requisição do IP: " + req.ip); | 51 | console.log("[" + new Date().toISOString() + "] Requisição do IP: " + req.ip); |