From 4fb53bb741a6fa788bdb00d59b05a6926bdbcd99 Mon Sep 17 00:00:00 2001 From: flifloo Date: Tue, 28 Apr 2020 16:01:39 +0200 Subject: [PATCH] Add list to route, allow a list of all images upload --- app.js | 2 ++ public/css/main.css | 16 ++++++++++++++++ routes/list.js | 13 +++++++++++++ views/list.pug | 7 +++++++ 4 files changed, 38 insertions(+) create mode 100644 routes/list.js create mode 100644 views/list.pug diff --git a/app.js b/app.js index e7d0f45..c74de87 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,7 @@ let indexRoute = require("./routes/index"); let uploadRoute = require("./routes/upload"); let loginRoute = require("./routes/login"); let imagesRoute = require("./routes/images"); +let listRoute = require("./routes/list"); let removeRoute = require("./routes/remove"); let notFoundRoute = require("./routes/notFound"); let errorRoute = require("./routes/error"); @@ -43,6 +44,7 @@ app.use(morgan("dev")) .use("/upload", uploadRoute) .use("/login", loginRoute) .use("/images", imagesRoute) + .use("/list", listRoute) .use("/remove", removeRoute) .use(notFoundRoute) .use(errorRoute) diff --git a/public/css/main.css b/public/css/main.css index 4ae4208..b9624b8 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -49,3 +49,19 @@ form>div { padding: 0.5em; } +.images { + display: flex; + flex-wrap: wrap; + justify-content: space-between; + width: 100%; +} + +.image { + margin: 2em; + max-width: 100%; + width: auto; + max-height: 20em; + height: auto; +} + + diff --git a/routes/list.js b/routes/list.js new file mode 100644 index 0000000..3cd147a --- /dev/null +++ b/routes/list.js @@ -0,0 +1,13 @@ +let router = require("express").Router(); +let isAuth = require("../user").isAuth; +let fs = require("fs"); + + +router.get("/", isAuth, (req, res, next) => { + let images = fs.readdirSync("./images/"); + res.render("list", {images: images}); +}); + + +module.exports = router; + diff --git a/views/list.pug b/views/list.pug new file mode 100644 index 0000000..9259c59 --- /dev/null +++ b/views/list.pug @@ -0,0 +1,7 @@ +extend layout +block content + h1 Images List + div.images + each image in images + img.image(src=`/images/${image}`) +