Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Meyito committed Oct 20, 2018
2 parents b02d5d2 + 1146199 commit 16c186b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion controllers/materials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -241,6 +242,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,
Expand All @@ -249,5 +254,6 @@ module.exports = {
list,
index,
pending,
update
update,
getPdf
}
1 change: 1 addition & 0 deletions routes/materials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', materialsCtrl.getPdf )
materials.post('/', auth.isAuth, materialUpload, materialsCtrl.create )
materials.put('/:id', auth.isAuth, materialUpload, materialsCtrl.update )
materials.delete('/:id', auth.isAuth, materialsCtrl.remove )
Expand Down
5 changes: 3 additions & 2 deletions services/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
})
}
Expand All @@ -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)
Expand Down

0 comments on commit 16c186b

Please sign in to comment.