Subida de audio hecha(Falta probar en tablet)

parent d5a684f4
...@@ -1189,9 +1189,9 @@ module.exports = { ...@@ -1189,9 +1189,9 @@ module.exports = {
/** /**
* Upload a custom sound associated to a picto * Upload a custom sound associated to a picto
* @param {request} req * @param {request} req
* id_stu, * id_sup,
* id_picto, * id_picto,
* attributes: { @see StuPicto.getValidAttributes() } *
* @param {response} res * @param {response} res
* { * {
* id: <stu_picto ID>, * id: <stu_picto ID>,
...@@ -1222,15 +1222,14 @@ module.exports = { ...@@ -1222,15 +1222,14 @@ module.exports = {
* } * }
*/ */
upload_sound: function (req, res) { 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 soundFileName;
var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory; var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory;
if (!supervisor) if (!supervisor)
throw new Error("No supervisor found"); throw new Error("No supervisor found");
soundFileName = sails.config.pictogram.paths.getSupervisorCustomPictoFileName(supervisor.id) soundFileName = sails.config.pictogram.paths.getSupervisorCustomPictoSoundFilename(supervisor.id);
+ "_sound";
sails.log.debug("Uploading sound with FileName: " + soundFileName);
req.file('file').upload({ req.file('file').upload({
maxBytes: 1048576, maxBytes: 1048576,
...@@ -1246,7 +1245,6 @@ module.exports = { ...@@ -1246,7 +1245,6 @@ module.exports = {
.then(picto => { .then(picto => {
return res.ok(picto); return res.ok(picto);
}) })
.populate('uri_sound',soundFileName)
.catch(err => { .catch(err => {
fs.unlink(uploadedFiles[0].fd); fs.unlink(uploadedFiles[0].fd);
return res.serverError("Error uploading " + err); return res.serverError("Error uploading " + err);
...@@ -1257,7 +1255,7 @@ module.exports = { ...@@ -1257,7 +1255,7 @@ module.exports = {
return res.serverError("Error uploading sound: " + err); return res.serverError("Error uploading sound: " + err);
}); });
}, },
// *************************************************************** // ***************************************************************
// WEBSOCKETS // WEBSOCKETS
// *************************************************************** // ***************************************************************
......
...@@ -75,6 +75,18 @@ module.exports.pictogram = { ...@@ -75,6 +75,18 @@ module.exports.pictogram = {
.replace(/\W/g, '') + ".jpg"; .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 * Gets the supervisor avatar filename
* @param {supervisorId} supervisorId * @param {supervisorId} supervisorId
...@@ -109,9 +121,21 @@ module.exports.pictogram = { ...@@ -109,9 +121,21 @@ module.exports.pictogram = {
'SUPERVISOR_CUSTOM_PICTO', 'SUPERVISOR_CUSTOM_PICTO',
supervisorId 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"... // TODO: errores should have a code (number) and a name (string) like "TokenExpired", "UserNotFound"...
error_codes: { error_codes: {
'DUPLICATED_PICTO': 1, 'DUPLICATED_PICTO': 1,
......
...@@ -87,7 +87,7 @@ module.exports.routes = { ...@@ -87,7 +87,7 @@ module.exports.routes = {
'POST /stu/login': 'StudentController.login', 'POST /stu/login': 'StudentController.login',
'POST /stu': 'StudentController.create', 'POST /stu': 'StudentController.create',
'POST /stu/upload': 'StudentController.upload', '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/:id_stu/picto/:id_picto': 'StudentController.add_picto',
'POST /stu/subscribe': 'StudentController.subscribe', 'POST /stu/subscribe': 'StudentController.subscribe',
'POST /stu/unsubscribe': 'StudentController.unsubscribe', '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