diff --git a/translate-api/app.js b/translate-api/app.js index 23adb6f..fa52169 100755 --- a/translate-api/app.js +++ b/translate-api/app.js @@ -15,7 +15,7 @@ var express = require('express'); var bodyParser = require('body-parser'); var db = require('./config/db'); -var settings = require('./config/settings'); +// var settings = require('./config/settings'); var bundle = require('./routes/bundle'); var translate = require('./routes/translate'); @@ -32,7 +32,7 @@ app.use(bodyParser.urlencoded({ extended: true })); /** * Public directory. */ -app.use('/video', express.static(settings.contentsPath)); +// app.use('/video', express.static(settings.contentsPath)); /** * Allow cross origin requests. diff --git a/translate-api/controllers/video.js b/translate-api/controllers/video.js index 2d5a4db..244e979 100644 --- a/translate-api/controllers/video.js +++ b/translate-api/controllers/video.js @@ -8,10 +8,13 @@ /** * Required libs. */ -var shortid = require('shortid') +var fs = require('fs') + , path = require('path') + , shortid = require('shortid') , Video = require('../models/video') , amqp = require('../helpers/amqpManager') - , error = require('../helpers/error'); + , error = require('../helpers/error') + , settings = require('../config/settings'); exports.create = function(req, res, next) { if (!req.body.gloss) @@ -60,6 +63,23 @@ exports.create = function(req, res, next) { }); }; +exports.download = function(req, res, next) { + if (!req.params.file) + return error.badRequest('File not specified.', next); + + var videoFile = path.join(settings.contentsPath, req.params.file); + res.download(videoFile, function(err) { + if (err) + return error.notFound('Can\'t find any content.', next); + + fs.unlink(videoFile, function(err) { + if (err) + return console.error('Can\'t remove ' + videoFile); + console.log(videoFile + ' removed.'); + }); + }); +}; + exports.status = function(req, res, next) { // Receive param id var contentID = req.params.id; diff --git a/translate-api/routes/video.js b/translate-api/routes/video.js index 8cbf74e..214ab51 100644 --- a/translate-api/routes/video.js +++ b/translate-api/routes/video.js @@ -12,6 +12,7 @@ var express = require('express') */ router .post('/', videoController.create) + .get('/:file', videoController.download) .get('/status/:id', videoController.status) module.exports = router; -- libgit2 0.21.2