image_node/routes/remove.js

18 lines
356 B
JavaScript
Raw Normal View History

2020-04-27 21:09:43 +02:00
let router = require("express").Router();
let isAuth = require("../user").isAuth;
let fs = require("fs");
router.get("/:name", isAuth, (req, res, next) => {
if ("name" in req.params && fs.existsSync("./images/"+req.params.name)) {
fs.unlinkSync("./images/"+req.params.name);
res.redirect("/");
} else {
next();
}
});
module.exports = router;