Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d140acb0
authored
Apr 04, 2017
by
Germán Callejas Alcántara
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Añadido metodo upload_sound a StudentController con las policies, routes y path establecidos
parent
252741c0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
1 deletions
sails/src/api/controllers/StudentController.js
sails/src/config/pictogram.js
sails/src/config/policies.js
sails/src/config/routes.js
sails/src/api/controllers/StudentController.js
View file @
d140acb0
...
...
@@ -130,7 +130,7 @@ module.exports = {
"tape_background": "#00ffff",
"delivery": 0
}
}
}
*/
getInfo
:
function
(
req
,
res
)
{
Student
.
findOne
({
id
:
req
.
params
.
id_stu
})
...
...
@@ -1186,6 +1186,77 @@ module.exports = {
});
},
/**
* Upload a custom sound associated to a picto
* @param {request} req
* id_stu,
* id_picto,
* attributes: { @see StuPicto.getValidAttributes() }
* @param {response} res
* {
* id: <stu_picto ID>,
* 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
)
{
Supervisor
.
findOne
({
id
:
req
.
body
.
owner
}).
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
);
req
.
file
(
'file'
).
upload
({
maxBytes
:
1048576
,
dirname
:
soundDirectory
,
saveAs
:
soundFileName
},
function
whenDone
(
err
,
uploadedFiles
)
{
var
fs
=
require
(
'fs'
);
if
(
err
||
(
uploadedFiles
.
length
===
0
))
return
res
.
serverError
(
"Error uploading "
+
err
?
err
:
""
);
StuPicto
.
findOne
({
id
:
req
.
body
.
id
})
.
then
(
soundFileName
=>
{
return
res
.
ok
(
soundFileName
);
})
.
catch
(
err
=>
{
fs
.
unlink
(
uploadedFiles
[
0
].
fd
);
return
res
.
serverError
(
"Error uploading "
+
err
);
});
});
})
.
catch
(
function
(
err
)
{
return
res
.
serverError
(
"Error uploading sound: "
+
err
);
});
}
};
// ***************************************************************
// WEBSOCKETS
// ***************************************************************
...
...
sails/src/config/pictogram.js
View file @
d140acb0
...
...
@@ -55,6 +55,7 @@ module.exports.pictogram = {
supervisorAvatarDirectory
:
path
.
join
(
UPLOAD_PATH
,
'supervisorAvatar'
),
studentAvatarDirectory
:
path
.
join
(
UPLOAD_PATH
,
'studentAvatar'
),
supervisorCustomPictoDirectory
:
path
.
join
(
UPLOAD_PATH
,
'supervisorCustomPicto'
),
pictoSoundDirectory
:
path
.
join
(
UPLOAD_PATH
,
'pictoSound'
),
/**
* Get a random name used for uploaded file names
...
...
sails/src/config/policies.js
View file @
d140acb0
...
...
@@ -105,6 +105,7 @@ module.exports.policies = {
login
:
true
,
create
:
[
'tokenAuth'
,
'isSupAdmin'
],
upload
:
[
'tokenAuth'
],
upload_sound
:
[
'tokenAuth'
,
'isSupervisorOfStudent'
],
add_picto
:
[
'tokenAuth'
,
'isSupervisorOfStudent'
],
subscribe
:
[
'tokenAuth'
],
unsubscribe
:
true
,
...
...
sails/src/config/routes.js
View file @
d140acb0
...
...
@@ -87,6 +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_stu/picto/:id_picto'
:
'StudentController.add_picto'
,
'POST /stu/subscribe'
:
'StudentController.subscribe'
,
'POST /stu/unsubscribe'
:
'StudentController.unsubscribe'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment