Routes actualizado para upload_sound

parent 110968d7
...@@ -1193,53 +1193,30 @@ module.exports = { ...@@ -1193,53 +1193,30 @@ module.exports = {
* *
* @param {response} res * @param {response} res
* { * {
* id: <stu_picto ID>, * stu_picto
* student: <student ID>,
* attributes: {
* id_cat: categoryId or null,
* coord_x: 1 .. 5 or null,
* coord_y: 1 .. 10 or null,
* free_category_coord_x: 0 .. 4 or null,
* free_category_coord_y: 0 .. 9 or null,
* status: '[invisible]/enabled/disabled',
* highlight: true/[false],
* color: any valid HEX color or [null],
* expression: 'custom expression',
* legend: true/[false],
* uri_sound: 'path of sound associated',
* user_avatar:
* },
* picto: {
* id: <pictoID>,
* source: <sourceID>,
* owner: <ownerID> or null,
* id: <pictoID>,
* uri: <URL to image>,
* category: <categoryID>
* }
* }
* } * }
*/ */
upload_sound: function (req, res) { upload_sound: function (req, res) {
var soundFileName; var soundFileName;
var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory; var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory;
if (!supervisor) console.log("Llega aqui 1");
throw new Error("No supervisor found");
soundFileName = sails.config.pictogram.paths.getCustomPictoSoundFilename(req.params.id_stu_picto); soundFileName = sails.config.pictogram.paths.getCustomPictoSoundFilename(req.params.id_stu_picto);
console.log("Llega aqui 2");
req.file('file').upload({ req.file('file').upload({
maxBytes: 1048576, maxBytes: 1048576,
dirname: soundDirectory, dirname: soundDirectory,
saveAs: soundFileName saveAs: soundFileName
}, function whenDone(err, uploadedFiles) { }, function whenDone(err, uploadedFiles) {
console.log("Llega aqui 3");
var fs = require('fs'); var fs = require('fs');
if (err || (uploadedFiles.length === 0)) if (err || (uploadedFiles.length === 0))
return res.serverError("Error uploading " + err ? err : ""); return res.serverError("Error uploading " + err ? err : "");
console.log("Llega aqui 4");
StuPicto.findOne({ id: req.params.id_stu_picto}) StuPicto.findOne({ id: req.params.id_stu_picto})
.then(sp => { .then(sp => {
console.log("Picto encontrado")
sp.attributes.uri_sound = soundFileName; sp.attributes.uri_sound = soundFileName;
sp.save(function (err) { sp.save(function (err) {
if (err) throw err; if (err) throw err;
......
...@@ -95,7 +95,7 @@ module.exports.routes = { ...@@ -95,7 +95,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_sup/upload/:id_picto': 'StudentController.upload_sound', 'POST /stu/upload/:id_stu_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