Subida de audio hecha(Falta probar en tablet)

parent d5a684f4
......@@ -1189,9 +1189,9 @@ module.exports = {
/**
* Upload a custom sound associated to a picto
* @param {request} req
* id_stu,
* id_sup,
* id_picto,
* attributes: { @see StuPicto.getValidAttributes() }
*
* @param {response} res
* {
* id: <stu_picto ID>,
......@@ -1222,15 +1222,14 @@ module.exports = {
* }
*/
upload_sound: function (req, res) {
Supervisor.findOne({ id: req.body.owner }).then(function (supervisor) {
console.log("sup id: " + req.params.id_supervisor );
Supervisor.findOne({ id: req.params.id_supervisor }).then(function (supervisor) {
var soundFileName;
var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory;
if (!supervisor)
throw new Error("No supervisor found");
soundFileName = sails.config.pictogram.paths.getSupervisorCustomPictoFileName(supervisor.id)
+ "_sound";
sails.log.debug("Uploading sound with FileName: " + soundFileName);
soundFileName = sails.config.pictogram.paths.getSupervisorCustomPictoSoundFilename(supervisor.id);
req.file('file').upload({
maxBytes: 1048576,
......@@ -1246,7 +1245,6 @@ module.exports = {
.then(picto => {
return res.ok(picto);
})
.populate('uri_sound',soundFileName)
.catch(err => {
fs.unlink(uploadedFiles[0].fd);
return res.serverError("Error uploading " + err);
......
......@@ -75,6 +75,18 @@ module.exports.pictogram = {
.replace(/\W/g, '') + ".jpg";
},
_getRandomSoundFileName: function (randomString, randomNumber) {
var bcrypt = require('bcrypt-nodejs');
var randomDate = (new Date())
.getTime();
var randomFloat = Math.random();
return bcrypt.hashSync(
[randomString, randomDate, randomNumber, randomFloat].join(''),
bcrypt.genSaltSync()
)
.replace(/\W/g, '') + "_sound.mp3";
},
/**
* Gets the supervisor avatar filename
* @param {supervisorId} supervisorId
......@@ -109,9 +121,21 @@ module.exports.pictogram = {
'SUPERVISOR_CUSTOM_PICTO',
supervisorId
);
}
},
/**
* Gets the supervisor custom picto filename
* @param {supervisorId} supervisorId supervisorId
* @return {string} fileName
*/
getSupervisorCustomPictoSoundFilename: function (supervisorId) {
return sails.config.pictogram.paths._getRandomSoundFileName(
'SUPERVISOR_CUSTOM_PICTO',
supervisorId
);
}
},
// TODO: errores should have a code (number) and a name (string) like "TokenExpired", "UserNotFound"...
error_codes: {
'DUPLICATED_PICTO': 1,
......
......@@ -87,7 +87,7 @@ module.exports.routes = {
'POST /stu/login': 'StudentController.login',
'POST /stu': 'StudentController.create',
'POST /stu/upload': 'StudentController.upload',
'POST /stu/:id_stu/upload/:id_picto': 'StudentController.upload_sound',
'POST /stu/:id_sup/upload/:id_picto': 'StudentController.upload_sound',
'POST /stu/:id_stu/picto/:id_picto': 'StudentController.add_picto',
'POST /stu/subscribe': 'StudentController.subscribe',
'POST /stu/unsubscribe': 'StudentController.unsubscribe',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment