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
1754391f
authored
Apr 22, 2017
by
Sebastián Collado Montañez
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'develop' of
http://gitlab.ujaen.es/yotta/pictogram
into develop
parents
ca18d2fe
0ca9f1b5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
13 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 @
1754391f
...
@@ -1247,28 +1247,34 @@ module.exports = {
...
@@ -1247,28 +1247,34 @@ module.exports = {
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
;
soundFileName
=
sails
.
config
.
pictogram
.
paths
.
getCustomPictoSoundFilename
(
req
.
params
.
id_stu_picto
);
soundFileName
=
sails
.
config
.
pictogram
.
paths
.
getCustomPictoSoundFilename
(
req
.
params
.
id_stu
,
req
.
params
.
id_picto
);
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
)
{
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
:
""
);
StuPicto
.
findOne
({
id
:
req
.
params
.
id_stu_picto
})
StuPicto
.
findOne
({
student
:
req
.
params
.
id_stu
,
picto
:
req
.
params
.
id_picto
})
.
then
((
sp
)
=>
{
.
then
((
sp
)
=>
{
if
(
!
sp
)
if
(
!
sp
)
throw
Error
(
"Not found"
);
throw
Error
(
"Not found"
);
sp
.
attributes
.
uri_sound
=
soundFileName
;
sp
.
attributes
.
uri_sound
=
sails
.
config
.
pictogram
.
urls
.
getSoundUrl
(
soundFileName
);
sp
.
save
(
function
(
err
)
{
sp
.
save
(
function
(
err
)
{
if
(
err
)
throw
err
;
if
(
err
)
throw
err
;
return
res
.
ok
(
sp
);
return
res
.
ok
(
sp
);
});
});
})
})
.
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
);
});
});
...
...
sails/src/config/pictogram.js
View file @
1754391f
/* global sails */
/* global sails */
var
path
=
require
(
'path'
);
var
path
=
require
(
'path'
);
var
ASSETS_PATH
=
path
.
join
(
__dirname
,
'..'
,
'assets'
);
var
ASSETS_PATH
=
path
.
join
(
__dirname
,
'..'
,
'assets'
);
var
UPLOAD_PATH
=
path
.
join
(
__dirname
,
'..'
,
'..'
,
'upload'
);
var
UPLOAD_PATH
=
path
.
join
(
__dirname
,
'..'
,
'..'
,
'upload'
);
...
@@ -53,6 +54,14 @@ module.exports.pictogram = {
...
@@ -53,6 +54,14 @@ module.exports.pictogram = {
*/
*/
getSupervisorCustomPictoUrl
:
function
(
filename
)
{
getSupervisorCustomPictoUrl
:
function
(
filename
)
{
return
`/upload/supervisorCustomPicto/
${
filename
}
`
;
return
`/upload/supervisorCustomPicto/
${
filename
}
`
;
},
/**
* Gets the public url of a sound for a given picto
* @param {String} filename filename of sound
* @return {String} Public url of the picto sound
*/
getSoundUrl
:
function
(
filename
)
{
return
`/upload/pictoSound/
${
filename
}
`
;
}
}
},
},
...
@@ -63,8 +72,7 @@ module.exports.pictogram = {
...
@@ -63,8 +72,7 @@ module.exports.pictogram = {
supervisorAvatarDirectory
:
path
.
join
(
UPLOAD_PATH
,
'supervisorAvatar'
),
supervisorAvatarDirectory
:
path
.
join
(
UPLOAD_PATH
,
'supervisorAvatar'
),
studentAvatarDirectory
:
path
.
join
(
UPLOAD_PATH
,
'studentAvatar'
),
studentAvatarDirectory
:
path
.
join
(
UPLOAD_PATH
,
'studentAvatar'
),
supervisorCustomPictoDirectory
:
path
.
join
(
UPLOAD_PATH
,
'supervisorCustomPicto'
),
supervisorCustomPictoDirectory
:
path
.
join
(
UPLOAD_PATH
,
'supervisorCustomPicto'
),
pictoSoundDirectory
:
path
.
join
(
UPLOAD_PATH
,
'pictoSound'
),
pictoSoundDirectory
:
path
.
join
(
UPLOAD_PATH
,
'pictoSound'
),
/**
/**
* Get a random name used for uploaded file names
* Get a random name used for uploaded file names
* @param {string} randomString String used for generating the name
* @param {string} randomString String used for generating the name
...
@@ -137,10 +145,10 @@ module.exports.pictogram = {
...
@@ -137,10 +145,10 @@ module.exports.pictogram = {
* @param {supervisorId} supervisorId supervisorId
* @param {supervisorId} supervisorId supervisorId
* @return {string} fileName
* @return {string} fileName
*/
*/
getCustomPictoSoundFilename
:
function
(
s
upervisor
Id
)
{
getCustomPictoSoundFilename
:
function
(
s
tudentId
,
picto
Id
)
{
return
sails
.
config
.
pictogram
.
paths
.
_getRandomSoundFileName
(
return
sails
.
config
.
pictogram
.
paths
.
_getRandomSoundFileName
(
'
SUPERVISOR_CUSTOM_PICTO
'
,
'
PICTO_SOUND
'
,
s
upervisor
Id
s
tudentId
+
'_'
+
picto
Id
);
);
}
}
},
},
...
...
sails/src/config/routes.js
View file @
1754391f
...
@@ -107,7 +107,7 @@ module.exports.routes = {
...
@@ -107,7 +107,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/
upload/:id_stu
_picto'
:
'StudentController.upload_sound'
,
'POST /stu/
:id_stu/upload_sound/: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