Commit 1e01b8368f71aeaef162c64c47069682504edea8
1 parent
5c05d88f
Exists in
master
Atualiza endpoints
Showing
3 changed files
with
373 additions
and
47 deletions
Show diff stats
Makefile
| @@ -5,6 +5,7 @@ SCRIPT_PATH_ETC := /etc/init.d/${SCRIPT_NAME} | @@ -5,6 +5,7 @@ SCRIPT_PATH_ETC := /etc/init.d/${SCRIPT_NAME} | ||
| 5 | NPM := $(shell which npm) | 5 | NPM := $(shell which npm) |
| 6 | 6 | ||
| 7 | install: | 7 | install: |
| 8 | + @ sudo chmod -R 777 $$HOME/tmp/ | ||
| 8 | @ npm install | 9 | @ npm install |
| 9 | @ sudo npm install -g supervisor | 10 | @ sudo npm install -g supervisor |
| 10 | 11 | ||
| @@ -26,12 +27,12 @@ clean: | @@ -26,12 +27,12 @@ clean: | ||
| 26 | @ find ./public/users/ -type d -empty -delete | 27 | @ find ./public/users/ -type d -empty -delete |
| 27 | 28 | ||
| 28 | distclean: | 29 | distclean: |
| 29 | - @ sudo rm -rf ./public/users/ ./uploads/ | 30 | + @ sudo rm -rf ./public/users/* ./uploads/* |
| 30 | 31 | ||
| 31 | run: | 32 | run: |
| 32 | @ sudo ${NPM} start | 33 | @ sudo ${NPM} start |
| 33 | 34 | ||
| 34 | -unistall: distclean | 35 | +uninstall: distclean |
| 35 | @ rm -rf ./node_modules/ | 36 | @ rm -rf ./node_modules/ |
| 36 | 37 | ||
| 37 | ROLENAME := wikilibras | 38 | ROLENAME := wikilibras |
routes/index.js
| @@ -125,22 +125,187 @@ router.get("/listall", function(req, res, next) | @@ -125,22 +125,187 @@ router.get("/listall", function(req, res, next) | ||
| 125 | { | 125 | { |
| 126 | var response = {}; | 126 | var response = {}; |
| 127 | // db.query('SELECT s."nome", s."data", s.cidade, s.estado, s.file, s.avatar, s.blender, ts."nomeSelo", s."version" FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo"') | 127 | // db.query('SELECT s."nome", s."data", s.cidade, s.estado, s.file, s.avatar, s.blender, ts."nomeSelo", s."version" FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo"') |
| 128 | - db.query('SELECT s."data", s."usuario", s."idSinal", s."idSelo", s."nome", s."classe", s."frase", s."estado", s."cidade", s."file" FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo"') | ||
| 129 | - .then(function(result) | 128 | + db.query('SELECT s."data", s."usuario", s."idSinal", s.idtask, s."idSelo", ts."nomeSelo", s."version", s."nome", s."classe", s."frase", s."estado", s."cidade", s."file", s."avatar", s."blender" FROM "sinal" s INNER JOIN "tipoSelo" ts ON (s."idSelo" = ts."idSelo")') |
| 129 | + .then(function(result) | ||
| 130 | + { | ||
| 131 | + response = result; | ||
| 132 | + res.status(203); | ||
| 133 | + }) | ||
| 134 | + .catch(function(error) | ||
| 135 | + { | ||
| 136 | + response = error; | ||
| 137 | + res.status(500); | ||
| 138 | + }) | ||
| 139 | + .finally(function() | ||
| 140 | + { | ||
| 141 | + res.send(response); | ||
| 142 | + pgp.end(); | ||
| 143 | + }); | ||
| 144 | +}); | ||
| 145 | + | ||
| 146 | +/** | ||
| 147 | + * Atualiza o campo selo com base no idSinal ou idTask | ||
| 148 | + */ | ||
| 149 | +router.put("/updateselo", function(req, res, next) | ||
| 150 | +{ | ||
| 151 | + var response = {}; | ||
| 152 | + var idTask = req.body["idtask"]; | ||
| 153 | + var idSinal = req.body["idsinal"]; | ||
| 154 | + var selo = req.body["selo"]; | ||
| 155 | + | ||
| 156 | + console.log(JSON.stringify(req.body, null, 4)); | ||
| 157 | + var query = ""; | ||
| 158 | + if (_.isEmpty(selo)) | ||
| 159 | + { | ||
| 160 | + res.status(500); | ||
| 161 | + response.status = false; | ||
| 162 | + response.error = "O campo 'selo' é obrigatório"; | ||
| 163 | + return res.send(response); | ||
| 164 | + } | ||
| 165 | + else | ||
| 166 | + { | ||
| 167 | + query += 'UPDATE "sinal" SET "idSelo" = ' + parseInt(selo) + ' WHERE '; | ||
| 168 | + } | ||
| 169 | + if (_.isEmpty(idTask) && _.isEmpty(idSinal)) | ||
| 170 | + { | ||
| 171 | + res.status(500); | ||
| 172 | + response.status = false; | ||
| 173 | + response.error = "O campo 'idtask' ou 'idsinal' está ausente"; | ||
| 174 | + return res.send(response); | ||
| 175 | + } | ||
| 176 | + if (!_.isEmpty(idTask)) | ||
| 177 | + { | ||
| 178 | + query += 'idtask = ' + parseInt(idTask); | ||
| 179 | + } | ||
| 180 | + if (!_.isEmpty(idTask) && !_.isEmpty(idSinal)) | ||
| 181 | + { | ||
| 182 | + query += " AND "; | ||
| 183 | + } | ||
| 184 | + if (!_.isEmpty(idSinal)) | ||
| 185 | + { | ||
| 186 | + query += '"idSinal" = ' + parseInt(idSinal); | ||
| 187 | + } | ||
| 188 | + query += ' RETURNING "nome", "idSinal", idtask, "idSelo";'; | ||
| 189 | + db.query(query) | ||
| 190 | + .then(function(result) | ||
| 191 | + { | ||
| 192 | + if (Object.keys(result).length > 0) | ||
| 130 | { | 193 | { |
| 131 | - response = result; | ||
| 132 | - res.status(203); | ||
| 133 | - }) | ||
| 134 | - .catch(function(error) | 194 | + response.status = true; |
| 195 | + } | ||
| 196 | + else | ||
| 135 | { | 197 | { |
| 136 | - response = error; | ||
| 137 | - res.status(500); | ||
| 138 | - }) | ||
| 139 | - .finally(function() | 198 | + response.status = false; |
| 199 | + } | ||
| 200 | + response.data = result; | ||
| 201 | + res.status(200); | ||
| 202 | + }) | ||
| 203 | + .catch(function(error) | ||
| 204 | + { | ||
| 205 | + response.status = false; | ||
| 206 | + response.error = error; | ||
| 207 | + res.status(500); | ||
| 208 | + }) | ||
| 209 | + .finally(function() | ||
| 210 | + { | ||
| 211 | + res.send(response); | ||
| 212 | + pgp.end(); | ||
| 213 | + }); | ||
| 214 | +}); | ||
| 215 | + | ||
| 216 | +/** | ||
| 217 | + * Atualiza o campo 'idtask' com base no idSinal | ||
| 218 | + */ | ||
| 219 | +router.get("/updatetask", function(req, res, next) | ||
| 220 | +{ | ||
| 221 | + var response = {}; | ||
| 222 | + var idTask = req.query["idtask"]; | ||
| 223 | + var idSinal = req.query["idsinal"]; | ||
| 224 | + if (_.isEmpty(idTask)) | ||
| 225 | + { | ||
| 226 | + res.status(500); | ||
| 227 | + response.status = false; | ||
| 228 | + response.error = "O campo 'idtask' é obrigatório"; | ||
| 229 | + res.send(response); | ||
| 230 | + return; | ||
| 231 | + } | ||
| 232 | + else | ||
| 233 | + { | ||
| 234 | + idTask = parseInt(idTask); | ||
| 235 | + } | ||
| 236 | + if (_.isEmpty(idSinal)) | ||
| 237 | + { | ||
| 238 | + res.status(500); | ||
| 239 | + response.status = false; | ||
| 240 | + response.error = "O campo 'idsinal' é obrigatório"; | ||
| 241 | + res.send(response); | ||
| 242 | + return; | ||
| 243 | + } | ||
| 244 | + else | ||
| 245 | + { | ||
| 246 | + idSinal = parseInt(idSinal); | ||
| 247 | + } | ||
| 248 | + db.query('UPDATE "sinal" SET version = version + 1, idtask = ($1) WHERE "idSinal" = ($2) RETURNING "idSinal", idtask;', [idTask, idSinal]) | ||
| 249 | + .then(function(result) | ||
| 250 | + { | ||
| 251 | + if (Object.keys(result).length > 0) | ||
| 140 | { | 252 | { |
| 141 | - res.send(response); | ||
| 142 | - pgp.end(); | ||
| 143 | - }); | 253 | + response.status = true; |
| 254 | + response.data = result; | ||
| 255 | + } | ||
| 256 | + else | ||
| 257 | + { | ||
| 258 | + response.status = false; | ||
| 259 | + response.data = "ERROR: 'idSinal' = " + idSinal + " Não encontrado"; | ||
| 260 | + } | ||
| 261 | + res.status(200); | ||
| 262 | + }) | ||
| 263 | + .catch(function(error) | ||
| 264 | + { | ||
| 265 | + response.status = false; | ||
| 266 | + response.error = error; | ||
| 267 | + res.status(500); | ||
| 268 | + }) | ||
| 269 | + .finally(function() | ||
| 270 | + { | ||
| 271 | + res.send(response); | ||
| 272 | + pgp.end(); | ||
| 273 | + }); | ||
| 274 | +}); | ||
| 275 | + | ||
| 276 | +/** | ||
| 277 | + * Retorna lista de sinais inseridos pelo formulário e | ||
| 278 | + * os que que tiveram o selo alterado | ||
| 279 | + */ | ||
| 280 | +router.get("/newtasks", function(req, res, next) | ||
| 281 | +{ | ||
| 282 | + var response = {}; | ||
| 283 | + var selo = req.query["selo"]; | ||
| 284 | + var query = 'SELECT s."idSinal", s."nome", s."idSelo", ts."nomeSelo", s."usuario", s."estado", s."classe", s."file", s."avatar", s."blender" FROM "sinal" s INNER JOIN "tipoSelo" ts ON (s."idSelo" = ts."idSelo") WHERE s."version" = 0 '; | ||
| 285 | + if (!_.isEmpty(selo)) | ||
| 286 | + { | ||
| 287 | + query += ' AND s."idSelo" = ' + parseInt(selo); | ||
| 288 | + } | ||
| 289 | + query += ';'; | ||
| 290 | + db.query(query) | ||
| 291 | + .then(function(result) | ||
| 292 | + { | ||
| 293 | + response.status = true; | ||
| 294 | + response.count = result.length; | ||
| 295 | + response.data = result; | ||
| 296 | + res.status(200); | ||
| 297 | + }) | ||
| 298 | + .catch(function(error) | ||
| 299 | + { | ||
| 300 | + response.status = false; | ||
| 301 | + response.error = error; | ||
| 302 | + res.status(500); | ||
| 303 | + }) | ||
| 304 | + .finally(function() | ||
| 305 | + { | ||
| 306 | + res.send(response); | ||
| 307 | + pgp.end(); | ||
| 308 | + }); | ||
| 144 | }); | 309 | }); |
| 145 | 310 | ||
| 146 | /* | 311 | /* |
| @@ -201,6 +366,33 @@ router.get("/reset", function(req, res, next) | @@ -201,6 +366,33 @@ router.get("/reset", function(req, res, next) | ||
| 201 | }); | 366 | }); |
| 202 | }); | 367 | }); |
| 203 | 368 | ||
| 369 | +router.get("/resettasks", function(req, res, next) | ||
| 370 | +{ | ||
| 371 | + const pg = require("pg"); | ||
| 372 | + const connectionString = "postgres://pybossa:tester@localhost:5432/pybossa"; | ||
| 373 | + const results = []; | ||
| 374 | + const data = { text: req.body.text, complete: false }; | ||
| 375 | + pg.connect(connectionString, function(err, client, done) | ||
| 376 | + { | ||
| 377 | + if (err) | ||
| 378 | + { | ||
| 379 | + done(); | ||
| 380 | + console.log(err); | ||
| 381 | + return res.status(500).json({ success: false, data: err }); | ||
| 382 | + } | ||
| 383 | + const query = client.query('TRUNCATE "task" CASCADE; ALTER SEQUENCE task_id_seq RESTART WITH 1'); | ||
| 384 | + query.on('row', function(row) | ||
| 385 | + { | ||
| 386 | + results.push(row); | ||
| 387 | + }); | ||
| 388 | + query.on('end', function() | ||
| 389 | + { | ||
| 390 | + done(); | ||
| 391 | + return res.json({ success: true, data: results }); | ||
| 392 | + }); | ||
| 393 | + }); | ||
| 394 | +}); | ||
| 395 | + | ||
| 204 | router.get("/version", function(req, res, next) | 396 | router.get("/version", function(req, res, next) |
| 205 | { | 397 | { |
| 206 | var response = []; | 398 | var response = []; |
| @@ -216,16 +408,16 @@ router.get("/version", function(req, res, next) | @@ -216,16 +408,16 @@ router.get("/version", function(req, res, next) | ||
| 216 | .finally(function() | 408 | .finally(function() |
| 217 | { | 409 | { |
| 218 | pgp.end(); | 410 | pgp.end(); |
| 219 | - res.status(203).send(response); | 411 | + res.status(200).send(response); |
| 220 | }); | 412 | }); |
| 221 | }); | 413 | }); |
| 222 | 414 | ||
| 223 | router.get("/sinais", function(req, res, next) | 415 | router.get("/sinais", function(req, res, next) |
| 224 | { | 416 | { |
| 225 | var results = []; | 417 | var results = []; |
| 226 | - if ((!_.isEmpty(req.param("selo"))) && (!_.isEmpty(req.param("version")))) | 418 | + if ((!_.isEmpty(req.query("selo"))) && (!_.isEmpty(req.query("version")))) |
| 227 | { | 419 | { |
| 228 | - db.query('SELECT s."nome", s."data", s.cidade, s."version", s.estado, s.file, s.avatar, s.blender, ts."nomeSelo" FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo" AND ts."nomeSelo" = $1 AND s."version" = $2', [req.param("selo"), req.param("version")]) | 420 | + db.query('SELECT s."nome", s."data", s.cidade, s."version", s.estado, s.file, s.avatar, s.blender, ts."nomeSelo" FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo" AND ts."nomeSelo" = $1 AND s."version" = $2', [req.query("selo"), req.query("version")]) |
| 229 | .then(function(result) | 421 | .then(function(result) |
| 230 | { | 422 | { |
| 231 | res.status(203).send(result); | 423 | res.status(203).send(result); |
| @@ -241,9 +433,9 @@ router.get("/sinais", function(req, res, next) | @@ -241,9 +433,9 @@ router.get("/sinais", function(req, res, next) | ||
| 241 | } | 433 | } |
| 242 | else | 434 | else |
| 243 | { | 435 | { |
| 244 | - if (!_.isEmpty(req.param("version"))) | 436 | + if (!_.isEmpty(req.query("version"))) |
| 245 | { | 437 | { |
| 246 | - db.query("select nome, data, file, avatar, blender version FROM sinal WHERE version = $1", req.param("version")) | 438 | + db.query("select nome, data, file, avatar, blender version FROM sinal WHERE version = $1", req.query("version")) |
| 247 | .then(function(result) | 439 | .then(function(result) |
| 248 | { | 440 | { |
| 249 | res.status(203).send(result); | 441 | res.status(203).send(result); |
| @@ -257,9 +449,9 @@ router.get("/sinais", function(req, res, next) | @@ -257,9 +449,9 @@ router.get("/sinais", function(req, res, next) | ||
| 257 | pgp.end(); | 449 | pgp.end(); |
| 258 | }); | 450 | }); |
| 259 | } | 451 | } |
| 260 | - if (!_.isEmpty(req.param("selo"))) | 452 | + if (!_.isEmpty(req.query("selo"))) |
| 261 | { | 453 | { |
| 262 | - db.query('SELECT s."nome", s."data", s.cidade, s.estado, s.file, s.avatar, s.blender, ts."nomeSelo", s.version FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo" AND ts."nomeSelo" = $1', req.param("selo")) | 454 | + db.query('SELECT s."nome", s."data", s.cidade, s.estado, s.file, s.avatar, s.blender, ts."nomeSelo", s.version FROM "sinal" s, "tipoSelo" ts WHERE s."idSelo" = ts."idSelo" AND ts."nomeSelo" = $1', req.query("selo")) |
| 263 | 455 | ||
| 264 | .then(function(result) | 456 | .then(function(result) |
| 265 | { | 457 | { |
| @@ -452,6 +644,134 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | @@ -452,6 +644,134 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | ||
| 452 | }); | 644 | }); |
| 453 | */ | 645 | */ |
| 454 | 646 | ||
| 647 | +router.post('/updatesinal', upload.array('video', 2), function(req, res, next) | ||
| 648 | +{ | ||
| 649 | + // console.log("[" + new Date().toISOString() + "]"); | ||
| 650 | + // console.log("From: " + req.ip); | ||
| 651 | + // console.log("Files: " + JSON.stringify(req.files[0], null, 4)); | ||
| 652 | + // console.log("headers: " + JSON.stringify(req.headers, null, 4)); | ||
| 653 | + // console.log("body: " + JSON.stringify(req.body, null, 4)); | ||
| 654 | + if (req.method === "OPTIONS") | ||
| 655 | + { | ||
| 656 | + res.header('Access-Control-Allow-Origin', req.headers.origin); | ||
| 657 | + } | ||
| 658 | + else | ||
| 659 | + { | ||
| 660 | + res.header('Access-Control-Allow-Origin', '*'); | ||
| 661 | + } | ||
| 662 | + if (req.files.length < 2) | ||
| 663 | + { | ||
| 664 | + return res.status(500).send("ERROR: O campo 'video' deve conter dois arquivos (video, blend)"); | ||
| 665 | + } | ||
| 666 | + var response = {}; | ||
| 667 | + var directory = users; | ||
| 668 | + var nome = req.body["nome"]; | ||
| 669 | + var selo = req.body["selo"]; | ||
| 670 | + var idTask = req.body["idtask"]; | ||
| 671 | + var blend = req.files[1]; | ||
| 672 | + var video = req.files[0]; | ||
| 673 | + var maxblendsize = 25; // MB | ||
| 674 | + var maxvideosize = 25; // MB | ||
| 675 | + if (_.isEmpty(nome) || _.isEmpty(idTask)) | ||
| 676 | + { | ||
| 677 | + response.status = false; | ||
| 678 | + response.error = "Os campos 'nome' e 'idtask' são obrigatórios"; | ||
| 679 | + return res.status(500).send(response); | ||
| 680 | + } | ||
| 681 | + else | ||
| 682 | + { | ||
| 683 | + nome = nome.trim().toUpperCase(); | ||
| 684 | + } | ||
| 685 | + if (video.size > (maxvideosize * 1048576)) | ||
| 686 | + { | ||
| 687 | + response.status = false; | ||
| 688 | + response.error = "O tamanho do video deve ter no máximo " + maxvideosize + " MB"; | ||
| 689 | + return res.status(500).send(response); | ||
| 690 | + } | ||
| 691 | + if (blend.size > (maxblendsize * 1048576)) | ||
| 692 | + { | ||
| 693 | + response.status = false; | ||
| 694 | + response.error = "O tamanho do blend deve ter no máximo " + maxblendsize + " MB"; | ||
| 695 | + return res.status(500).send(response); | ||
| 696 | + } | ||
| 697 | + if (_.isEmpty(selo) || 1 < selo || selo > 7) | ||
| 698 | + { | ||
| 699 | + selo = 1; | ||
| 700 | + } | ||
| 701 | + db.query('SELECT "idSinal", usuario, estado, classe FROM "sinal" WHERE nome = ($1) AND idtask = ($2)', [nome, idTask]) | ||
| 702 | + .then(function(result) | ||
| 703 | + { | ||
| 704 | + if (Object.keys(result).length > 0) | ||
| 705 | + { | ||
| 706 | + var idSinal = result[0]["idSinal"]; | ||
| 707 | + var login = result[0]["usuario"]; | ||
| 708 | + var estado = result[0]["estado"]; | ||
| 709 | + var classe = result[0]["classe"]; | ||
| 710 | + var videoname = nome + ".webm"; | ||
| 711 | + var blendname = nome + ".blend"; | ||
| 712 | + if (login !== null) | ||
| 713 | + { | ||
| 714 | + directory = path.join(directory, login); | ||
| 715 | + } | ||
| 716 | + if (estado !== null) | ||
| 717 | + { | ||
| 718 | + directory = path.join(directory, estado); | ||
| 719 | + } | ||
| 720 | + if (classe !== null) | ||
| 721 | + { | ||
| 722 | + directory = path.join(directory, classe); | ||
| 723 | + } | ||
| 724 | + if (!fs.existsSync(directory)) | ||
| 725 | + { | ||
| 726 | + console.log("Criando diretorio: " + directory); | ||
| 727 | + mkdirp(directory, function (err) | ||
| 728 | + { | ||
| 729 | + if (err) | ||
| 730 | + { | ||
| 731 | + console.error(err); | ||
| 732 | + res.status(500).send(err); | ||
| 733 | + return; | ||
| 734 | + } | ||
| 735 | + else | ||
| 736 | + { | ||
| 737 | + console.log("Diretório criado com sucesso!"); | ||
| 738 | + } | ||
| 739 | + }); | ||
| 740 | + } | ||
| 741 | + db.query('UPDATE sinal SET "idSelo" = ($1), version = ($2), avatar = ($3), blender = ($4) WHERE "idSinal" = ($5)', [selo, 0, videoname, blendname, idSinal]) | ||
| 742 | + .then(function(data) | ||
| 743 | + { | ||
| 744 | + videopath = path.join(directory, videoname); | ||
| 745 | + blendpath = path.join(directory, blendname); | ||
| 746 | + fs.rename(video.path, videopath); | ||
| 747 | + fs.rename(blend.path, blendpath); | ||
| 748 | + var message = "Sinal atualizado: '" + nome + "'"; | ||
| 749 | + console.log(message); | ||
| 750 | + res.status(200).send(message); | ||
| 751 | + }) | ||
| 752 | + .catch(function(error) | ||
| 753 | + { | ||
| 754 | + var message = "Erro ao atualizar sinal '" + nome + "'\n" + error; | ||
| 755 | + console.log(message); | ||
| 756 | + res.status(500).send(message); | ||
| 757 | + }); | ||
| 758 | + } | ||
| 759 | + else | ||
| 760 | + { | ||
| 761 | + var message = "Não foi encontrado nenhum 'idtask' = '" + idTask + "' com sinal = " + nome; | ||
| 762 | + res.status(500).send(message); | ||
| 763 | + } | ||
| 764 | + }) | ||
| 765 | + .catch(function(error) | ||
| 766 | + { | ||
| 767 | + console.log(error); | ||
| 768 | + }) | ||
| 769 | + .finally(function() | ||
| 770 | + { | ||
| 771 | + pgp.end(); | ||
| 772 | + }); | ||
| 773 | +}); | ||
| 774 | + | ||
| 455 | router.post('/addsinal', upload.array('video', 2), function(req, res, next) | 775 | router.post('/addsinal', upload.array('video', 2), function(req, res, next) |
| 456 | { | 776 | { |
| 457 | // console.log("[" + new Date().toISOString() + "]"); | 777 | // console.log("[" + new Date().toISOString() + "]"); |
| @@ -469,8 +789,7 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | @@ -469,8 +789,7 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | ||
| 469 | } | 789 | } |
| 470 | if (req.files.length < 1) | 790 | if (req.files.length < 1) |
| 471 | { | 791 | { |
| 472 | - res.status(500).send("ERROR: O campo 'video' não contém nenhum arquivo do sinal"); | ||
| 473 | - return; | 792 | + return res.status(500).send("ERROR: O campo 'video' não contém nenhum arquivo do sinal"); |
| 474 | } | 793 | } |
| 475 | var directory = users; | 794 | var directory = users; |
| 476 | var login = req.body["login"]; | 795 | var login = req.body["login"]; |
| @@ -487,13 +806,11 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | @@ -487,13 +806,11 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | ||
| 487 | var maxfilesize = 25; // MB | 806 | var maxfilesize = 25; // MB |
| 488 | if (filesize > (maxfilesize * 1048576)) | 807 | if (filesize > (maxfilesize * 1048576)) |
| 489 | { | 808 | { |
| 490 | - res.status(500).send("O tamanho do arquivo deve ter no máximo " + maxfilesize + " MB"); | ||
| 491 | - return; | 809 | + return res.status(500).send("O tamanho do arquivo deve ter no máximo " + maxfilesize + " MB"); |
| 492 | } | 810 | } |
| 493 | if (_.isEmpty(nome)) | 811 | if (_.isEmpty(nome)) |
| 494 | { | 812 | { |
| 495 | - res.status(500).send("ERROR: O campo 'nome' não foi encontrado"); | ||
| 496 | - return; | 813 | + return res.status(500).send("ERROR: O campo 'nome' não foi encontrado"); |
| 497 | } | 814 | } |
| 498 | else | 815 | else |
| 499 | { | 816 | { |
| @@ -528,29 +845,36 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | @@ -528,29 +845,36 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | ||
| 528 | { | 845 | { |
| 529 | directory = path.join(directory, classe); | 846 | directory = path.join(directory, classe); |
| 530 | } | 847 | } |
| 531 | - if (!fs.existsSync(directory)) | ||
| 532 | - { | ||
| 533 | - console.log("Criando diretorio: " + directory); | ||
| 534 | - mkdirp(directory, function (err) | 848 | + output = path.join(directory, videoref); |
| 849 | + async.series([ | ||
| 850 | + function (callback) | ||
| 535 | { | 851 | { |
| 536 | - if (err) | 852 | + if (fs.existsSync(directory)) |
| 537 | { | 853 | { |
| 538 | - console.error(err); | ||
| 539 | - res.status(500).send(err); | ||
| 540 | - return; | 854 | + callback(null, 1); |
| 541 | } | 855 | } |
| 542 | else | 856 | else |
| 543 | { | 857 | { |
| 544 | - console.log("Diretório criado com sucesso!"); | 858 | + console.log("Criando diretorio: " + directory); |
| 859 | + mkdirp(directory, function (err) | ||
| 860 | + { | ||
| 861 | + if (err) | ||
| 862 | + { | ||
| 863 | + console.error(err); | ||
| 864 | + return res.status(500).send(err); | ||
| 865 | + } | ||
| 866 | + else | ||
| 867 | + { | ||
| 868 | + console.log("Diretório criado com sucesso!"); | ||
| 869 | + callback(null, 1); | ||
| 870 | + } | ||
| 871 | + }); | ||
| 545 | } | 872 | } |
| 546 | - }); | ||
| 547 | - } | ||
| 548 | - output = path.join(directory, videoref); | ||
| 549 | - async.series([ | 873 | + }, |
| 550 | // Converter para formato webm | 874 | // Converter para formato webm |
| 551 | function(callback) | 875 | function(callback) |
| 552 | { | 876 | { |
| 553 | - console.log("Convertendo para webm..."); | 877 | + console.log("Convertendo sinal '" + nome + "' para webm..."); |
| 554 | child = exec("avconv -y -v error -i \"" + input + "\" -acodec libvorbis -vcodec libvpx -an \"" + output + "\"", | 878 | child = exec("avconv -y -v error -i \"" + input + "\" -acodec libvorbis -vcodec libvpx -an \"" + output + "\"", |
| 555 | function(error, stdout, stderr) | 879 | function(error, stdout, stderr) |
| 556 | { | 880 | { |
| @@ -563,7 +887,7 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | @@ -563,7 +887,7 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | ||
| 563 | } | 887 | } |
| 564 | else | 888 | else |
| 565 | { | 889 | { |
| 566 | - res.status(200); | 890 | + res.status(500); |
| 567 | return 0; | 891 | return 0; |
| 568 | } | 892 | } |
| 569 | }); | 893 | }); |
| @@ -609,11 +933,11 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | @@ -609,11 +933,11 @@ router.post('/addsinal', upload.array('video', 2), function(req, res, next) | ||
| 609 | } | 933 | } |
| 610 | else | 934 | else |
| 611 | { | 935 | { |
| 612 | - console.log("Não existe, inserindo o sinal: '" + nome + "'"); | 936 | + console.log("Não existe, inserindo sinal: '" + nome + "'"); |
| 613 | db.one('INSERT INTO sinal (usuario, nome, classe, "idSelo", data, version, estado, cidade, frase, file) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "idSinal"', [login, nome, classe, selo, date, 0, estado, cidade, frase, videoref]) | 937 | db.one('INSERT INTO sinal (usuario, nome, classe, "idSelo", data, version, estado, cidade, frase, file) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "idSinal"', [login, nome, classe, selo, date, 0, estado, cidade, frase, videoref]) |
| 614 | .then(function(data) | 938 | .then(function(data) |
| 615 | { | 939 | { |
| 616 | - var message = "Sinal[" + data.idSinal + "]: '" + nome + "', inserido com sucesso"; | 940 | + var message = "Sinal[" + data.idSinal + "]: '" + nome + "', inserido com sucesso!"; |
| 617 | console.log(message); | 941 | console.log(message); |
| 618 | res.status(200).send(message); | 942 | res.status(200).send(message); |
| 619 | }) | 943 | }) |
wikilibras-db-api.sql
| @@ -39,12 +39,13 @@ CREATE TABLE sinal ( | @@ -39,12 +39,13 @@ CREATE TABLE sinal ( | ||
| 39 | -- TODO create table users | 39 | -- TODO create table users |
| 40 | "idUsuario" integer, | 40 | "idUsuario" integer, |
| 41 | usuario character varying(30), | 41 | usuario character varying(30), |
| 42 | - version integer DEFAULT 0, | ||
| 43 | "idSinal" integer DEFAULT nextval('sequence'::regclass) NOT NULL, | 42 | "idSinal" integer DEFAULT nextval('sequence'::regclass) NOT NULL, |
| 43 | + idtask integer DEFAULT 0, | ||
| 44 | "idSelo" integer, | 44 | "idSelo" integer, |
| 45 | + version integer DEFAULT 0, | ||
| 45 | nome character varying(30), | 46 | nome character varying(30), |
| 46 | classe character varying(30), | 47 | classe character varying(30), |
| 47 | - frase character varying(100), | 48 | + frase character varying(255), |
| 48 | estado character varying(30), | 49 | estado character varying(30), |
| 49 | cidade character varying(30), | 50 | cidade character varying(30), |
| 50 | file character varying(100), | 51 | file character varying(100), |