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
4334f75d
authored
Apr 05, 2017
by
Germán Callejas Alcántara
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Subida de audio hecha(Falta probar en tablet)
parent
d5a684f4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
10 deletions
sails/src/api/controllers/StudentController.js
sails/src/config/pictogram.js
sails/src/config/routes.js
sails/src/api/controllers/StudentController.js
View file @
4334f75d
...
@@ -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_s
tu
,
* id_s
up
,
* 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
// ***************************************************************
// ***************************************************************
...
...
sails/src/config/pictogram.js
View file @
4334f75d
...
@@ -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
,
...
...
sails/src/config/routes.js
View file @
4334f75d
...
@@ -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_s
tu
/upload/:id_picto'
:
'StudentController.upload_sound'
,
'POST /stu/:id_s
up
/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'
,
...
...
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