From b94b46c14a23959f62777295050dcbf8c628bfbd Mon Sep 17 00:00:00 2001 From: GersonLazaro Date: Thu, 18 Oct 2018 19:21:32 -0500 Subject: [PATCH 1/4] =?UTF-8?q?Correcci=C3=B3n=20en=20subida=20de=20materi?= =?UTF-8?q?ales?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/uploader.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/uploader.js b/services/uploader.js index 06abc8a..1db2dbb 100644 --- a/services/uploader.js +++ b/services/uploader.js @@ -28,7 +28,8 @@ var multer_storage = multer.diskStorage({ fieldname = raw.toString('hex') + moment() + ext if( file.fieldname == 'code' ) fieldname = raw.toString('hex') + moment() + path.extname(file.originalname) - + if( file.fieldname == 'pdf') + fieldname = raw.toString('hex') + moment() + '.pdf' cb(null, fieldname ) }) } @@ -55,7 +56,7 @@ var materialsDataFilter = function (req, file, cb) { var submissionsDataFilter = function (req, file, cb) { let ext = path.extname( file.originalname ); - if ( ext !== '.cpp' && ext !== '.java' && ext !== '.py' ) { + if ( ext !== '.cpp' && ext !== '.cc' && ext !== '.cxx' && ext !== '.c' && ext !== '.cp' && ext !== '.java' && ext !== '.py' ) { return cb( new Error('Sólo estan permitidos archivos .cpp, .java y .py') ) } cb(null, true) From 0d78386b83059bf7cce4db219c17bfb0c29c1bfc Mon Sep 17 00:00:00 2001 From: GersonLazaro Date: Thu, 18 Oct 2018 19:46:37 -0500 Subject: [PATCH 2/4] Obtener un pdf desde el backend --- controllers/materials.js | 7 ++++++- routes/materials.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/controllers/materials.js b/controllers/materials.js index fbaec4e..4b8d34d 100644 --- a/controllers/materials.js +++ b/controllers/materials.js @@ -241,6 +241,10 @@ function approve (req, res){ } +function getPdf(req,res){ + return res.sendFile( path.join( path.dirname(__dirname), 'files', 'materials', req.params.id ) ) +} + module.exports = { create, remove, @@ -249,5 +253,6 @@ module.exports = { list, index, pending, - update + update, + getPdf } diff --git a/routes/materials.js b/routes/materials.js index 63146c0..7dd31a5 100644 --- a/routes/materials.js +++ b/routes/materials.js @@ -23,6 +23,7 @@ var materialUpload = upload.fields([ materials.get('/', materialsCtrl.index ) materials.get('/pending', auth.isAuth, materialsCtrl.pending ) materials.get('/:id', materialsCtrl.get ) +materials.get('/pdf/:id', userCtrl.getPdf ) materials.post('/', auth.isAuth, materialUpload, materialsCtrl.create ) materials.put('/:id', auth.isAuth, materialUpload, materialsCtrl.update ) materials.delete('/:id', auth.isAuth, materialsCtrl.remove ) From df961eb14b9ce78a87cd254b4432eca1adc2a8f4 Mon Sep 17 00:00:00 2001 From: GersonLazaro Date: Thu, 18 Oct 2018 19:53:02 -0500 Subject: [PATCH 3/4] hotfix --- routes/materials.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/materials.js b/routes/materials.js index 7dd31a5..e666fa1 100644 --- a/routes/materials.js +++ b/routes/materials.js @@ -23,7 +23,7 @@ var materialUpload = upload.fields([ materials.get('/', materialsCtrl.index ) materials.get('/pending', auth.isAuth, materialsCtrl.pending ) materials.get('/:id', materialsCtrl.get ) -materials.get('/pdf/:id', userCtrl.getPdf ) +materials.get('/pdf/:id', materialsCtrl.getPdf ) materials.post('/', auth.isAuth, materialUpload, materialsCtrl.create ) materials.put('/:id', auth.isAuth, materialUpload, materialsCtrl.update ) materials.delete('/:id', auth.isAuth, materialsCtrl.remove ) From 9ca6031c2cdd8e6926466fb72c6de2a1774ad001 Mon Sep 17 00:00:00 2001 From: GersonLazaro Date: Thu, 18 Oct 2018 20:38:28 -0500 Subject: [PATCH 4/4] =?UTF-8?q?A=C3=B1adido=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/materials.js | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/materials.js b/controllers/materials.js index 4b8d34d..b282361 100644 --- a/controllers/materials.js +++ b/controllers/materials.js @@ -3,6 +3,7 @@ const Material = require('../models').materials const Category = require('../models').categories const User = require('../models').users +const path = require('path') const _ = require('lodash') const files = require('../services/files')