Commit 1ccd01c49b0253f30312d2d7bf16c432fecae3c7

Authored by Wesnydy Ribeiro
1 parent 79931261

bundles request service implementation

translate-api/app.js
... ... @@ -11,12 +11,14 @@
11 11 /**
12 12 * Module dependencies.
13 13 */
14   -var express = require('express')
15   -var bodyParser = require('body-parser')
  14 +var express = require('express');
  15 +var bodyParser = require('body-parser');
16 16  
17   -var db = require('./config/db')
  17 +var db = require('./config/db');
  18 +var settings = require('./config/settings');
18 19  
19   -var translate = require('./routes/translate')
  20 +var bundle = require('./routes/bundle');
  21 +var translate = require('./routes/translate');
20 22 var video = require('./routes/video');
21 23  
22 24 var app = express();
... ... @@ -30,7 +32,7 @@ app.use(bodyParser.urlencoded({ extended: true }));
30 32 /**
31 33 * Public directory.
32 34 */
33   -app.use('/video', express.static(process.env.VLIBRAS_VIDEO_LIBRAS));
  35 +app.use('/video', express.static(process.env.settings.contentsPath));
34 36  
35 37 /**
36 38 * Allow cross origin requests.
... ... @@ -45,6 +47,7 @@ app.use(function(req, res, next) {
45 47 /**
46 48 * Register routes.
47 49 */
  50 +app.use('/', bundle);
48 51 app.use('/translate', translate);
49 52 app.use('/video', video);
50 53  
... ...
translate-api/config/settings.js 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +/**
  2 + * Author: Wesnydy Lima Ribeiro
  3 + * Email: wesnydy@lavid.ufpb.br
  4 + */
  5 +
  6 +'use strict';
  7 +
  8 +/**
  9 + * Required libs.
  10 + */
  11 +var path = require('path');
  12 +
  13 +var config = {};
  14 +
  15 +config.contentsPath = process.env.VLIBRAS_VIDEO_LIBRAS;
  16 +config.bundlesPath = process.env.BUNDLES_PATH;
  17 +
  18 +config.platformsList = [ 'ANDROID', 'IOS', 'WEBGL', 'STANDALONE' ];
  19 +
  20 +config.statesList = [ 'AC', 'AL', 'AP', 'AM', 'BA', 'CE', 'DF', 'ES', 'GO',
  21 + 'MA', 'MT', 'MS', 'MG', 'PA', 'PB', 'PR', 'PE', 'PI',
  22 + 'RJ', 'RN', 'RS', 'RO', 'RR', 'SC', 'SP', 'SE', 'TO' ];
  23 +
  24 +module.exports = config;
... ...
translate-api/controllers/bundle.js 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +/**
  2 + * Author: Wesnydy Lima Ribeiro
  3 + * Email: wesnydy@lavid.ufpb.br
  4 + */
  5 +
  6 +'use strict';
  7 +
  8 +/**
  9 + * Required libs.
  10 + */
  11 +var path = require('path')
  12 + , settings = require('../config/settings')
  13 + , error = require('../helpers/error');
  14 +
  15 +exports.show=function(req, res, next) {
  16 + /**
  17 + * Check the required params.
  18 + */
  19 + if (!req.params.sign || !req.params.platform)
  20 + return error.badRequest('Sign and/or platform not specified.', next);
  21 + /**
  22 + * Check for supported platforms.
  23 + */
  24 + var upperPlatform = req.params.platform.toUpperCase();
  25 + if (settings.platformsList.indexOf(upperPlatform) < 0)
  26 + return error.notFound('Platform not recognized.', next);
  27 + /**
  28 + * Check for supported states.
  29 + * If the state is suppressed, we use the national dictionary.
  30 + */
  31 + var upperState = req.params.state ? req.params.state.toUpperCase() : "";
  32 + if ((upperState !== "") && (settings.statesList.indexOf(upperState) < 0))
  33 + return error.notFound('State not recognized.', next);
  34 + /**
  35 + * Sends the bundle if it exists in the repository.
  36 + */
  37 + var upperSign = req.params.sign.toUpperCase();
  38 + var bundle = path.join(settings.bundlesPath, upperPlatform, upperState, upperSign);
  39 + res.sendFile(bundle);
  40 +};
... ...
translate-api/package.json
1 1 {
2 2 "name": "translate-container",
3   - "version": "0.0.0",
  3 + "version": "3.1.0",
4 4 "private": true,
5 5 "license": "GPLv3",
6 6 "authors": [
... ... @@ -15,8 +15,9 @@
15 15 "amqplib": "~0.5.1",
16 16 "bluebird": "^3.4.7",
17 17 "body-parser": "~1.16.0",
18   - "express": "~4.0.0",
  18 + "express": "^4.15.2",
19 19 "mongoose": "^4.8.4",
  20 + "path": "^0.12.7",
20 21 "shortid": "~2.2.6"
21 22 }
22 23 }
... ...
translate-api/routes/bundle.js 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +/**
  2 + * Author: Wesnydy Lima Ribeiro
  3 + * Email: wesnydy@lavid.ufpb.br
  4 + */
  5 +
  6 +var express = require('express')
  7 + , router = express.Router()
  8 + , bundlesController = require('../controllers/bundle');
  9 +
  10 +/**
  11 + * Routes to get bundles of a specific platform.
  12 + */
  13 +router
  14 + // .get('/signs', bundlesController.index)
  15 + .get('/:platform/:state?/:sign', bundlesController.show)
  16 +
  17 +module.exports = router;
... ...