Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Damien Armillon
API Toucan
Commits
df9a6468
Commit
df9a6468
authored
Sep 08, 2020
by
Damien Armillon
Browse files
(feature): change pdf endpoint
parent
481e3e77
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
backend/.gitignore
View file @
df9a6468
/node_modules
.env.json
/private
pdf/*
!pdf/.gitkeep
img/*
!img/.gitkeep
backend/img/.gitkeep
0 → 100644
View file @
df9a6468
backend/package.json
View file @
df9a6468
...
...
@@ -6,13 +6,15 @@
"author"
:
"Damien <damien.armillon@gmail.com>"
,
"license"
:
"MIT"
,
"scripts"
:
{
"lint"
:
"yarn eslint ."
"start"
:
"yarn nodemon app.js"
,
"lint"
:
"yarn eslint ."
},
"dependencies"
:
{
"axios"
:
"^0.18.0"
,
"body-parser"
:
"^1.18.3"
,
"celebrate"
:
"^9.1.0"
,
"connect-mongo"
:
"^2.0.3"
,
"cookie-parser"
:
"^1.4.4"
,
"cors"
:
"^2.8.5"
,
"express"
:
"^4.16.4"
,
"express-session"
:
"^1.16.1"
,
...
...
@@ -22,6 +24,7 @@
"querystring"
:
"^0.2.0"
},
"devDependencies"
:
{
"eslint"
:
"^6.6.0"
"eslint"
:
"^6.6.0"
,
"nodemon"
:
"^2.0.4"
}
}
backend/pdf/.gitkeep
0 → 100644
View file @
df9a6468
backend/routes/routesToucan.js
View file @
df9a6468
...
...
@@ -3,7 +3,7 @@ var fs = require("fs");
var
path
=
require
(
"
path
"
);
var
{
celebrate
}
=
require
(
"
celebrate
"
);
var
{
newToucan
,
validId
,
validGet
}
=
require
(
"
../utils/schema
"
);
var
{
newToucan
,
validId
,
validGet
,
validTitle
}
=
require
(
"
../utils/schema
"
);
var
env
=
require
(
"
../.env
"
);
var
isLogged
=
require
(
"
../utils/authentification
"
);
var
upload
=
require
(
"
../utils/fileSaver
"
);
...
...
@@ -109,7 +109,7 @@ router.route("/delete/:id")
// Renvoie la cover du toucan avec l'id donné
router
.
route
(
"
/img/:id
"
)
.
get
(
celebrate
({
params
:
validId
}),
function
(
req
,
res
)
{
var
imgPath
=
path
.
join
(
env
.
savedExtensions
[
0
].
path
,
"
/
"
,
req
.
params
.
id
);
var
imgPath
=
path
.
resolve
(
env
.
savedExtensions
[
0
].
path
,
req
.
params
.
id
);
var
fileKnown
=
false
;
env
.
savedExtensions
[
0
].
extensions
.
forEach
(
ext
=>
{
if
(
fs
.
existsSync
(
imgPath
+
ext
)){
...
...
@@ -124,6 +124,19 @@ router.route("/img/:id")
}
});
router
.
use
(
"
/pdf
"
,
express
.
static
(
env
.
savedExtensions
[
1
].
path
));
router
.
route
(
"
/pdf/:title
"
)
.
get
(
celebrate
({
params
:
validTitle
}),
function
(
req
,
res
)
{
Toucan
.
findOne
({
title
:
req
.
params
.
title
},
(
err
,
data
)
=>
{
if
(
err
)
{
res
.
end
(
500
);
return
;
}
else
if
(
!
data
)
{
res
.
status
(
404
).
send
(
"
Toucan non trouvée
"
);
return
;
}
const
id
=
data
.
_id
;
res
.
sendFile
(
path
.
resolve
(
env
.
savedExtensions
[
1
].
path
,
id
+
"
.pdf
"
));
}
);});
module
.
exports
=
router
;
\ No newline at end of file
backend/utils/schema.js
View file @
df9a6468
...
...
@@ -7,6 +7,12 @@ var newToucan = Joi.object({
date
:
Joi
.
date
().
required
()
});
var
validTitle
=
Joi
.
object
({
title
:
Joi
.
string
()
.
regex
(
/^
[
a-zA-Z0-9áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ._
\s
'-
]{1,60}
$/
)
//Autorise la plupart des acents
.
required
(),
});
var
validId
=
Joi
.
object
({
id
:
Joi
.
string
().
hex
().
length
(
24
).
required
()});
var
validGet
=
Joi
.
object
({
limit
:
Joi
.
number
().
integer
(),
...
...
@@ -14,4 +20,4 @@ var validGet = Joi.object({
after
:
Joi
.
date
().
timestamp
()
});
module
.
exports
=
{
newToucan
,
validId
,
validGet
};
\ No newline at end of file
module
.
exports
=
{
newToucan
,
validTitle
,
validId
,
validGet
};
\ No newline at end of file
backend/yarn.lock
View file @
df9a6468
This diff is collapsed.
Click to expand it.
doc/API.md
View file @
df9a6468
...
...
@@ -22,9 +22,9 @@ L'api possède les routes :
Si l'oppération est un succès, on renvoie un message de succès et l'id du toucan enregistré.
2.
`toucan/pdf/:
id
`
:
2.
`toucan/pdf/:
title
`
:
*
`GET`
Renvoie le pdf du toucan avec
id
comme
_id
dans la base de donnée.
*
`GET`
Renvoie le pdf du toucan avec
title
comme
titre (title)
dans la base de donnée.
3.
`toucan/img/:id`
:
...
...
front/src/view/AllToucanPage/AllToucanPage.js
View file @
df9a6468
...
...
@@ -49,7 +49,7 @@ function AllToucan(props){
{
toucans
.
map
(
toucan
=>
{
return
<
ToucanCard
image
=
{
`
${
props
.
backURL
}
/toucan/img/
${
toucan
[
"
_id
"
]}
`
}
link
=
{
`
${
props
.
backURL
}
/toucan/pdf/
${
toucan
[
"
_id
"
]}
.pdf
`
}
link
=
{
`
${
props
.
backURL
}
/toucan/pdf/
${
toucan
.
title
}
`
}
header
=
{
toucan
.
title
}
toucanId
=
{
toucan
.
_id
}
isAdmin
=
{
props
.
isAdmin
}
...
...
Write
Preview
Supports
Markdown
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