refactored server to break out into node modules

This commit is contained in:
slynn1324
2021-01-29 14:23:37 -06:00
parent 02019ff941
commit 49ebef0202
47 changed files with 1055 additions and 945 deletions

23
server/image-server.js Normal file
View File

@@ -0,0 +1,23 @@
let conf = require("./conf.js");
module.exports = (req, res, next) => {
if ( req.method == "GET" && req.originalUrl.startsWith("/images/") ){
let filepath = conf.getImagePath() + '/' + req.user.id + '/' + req.originalUrl;
res.setHeader('Cache-control', `private, max-age=2592000000`); // 30 days
res.sendFile(filepath);
return;
} else if ( req.method == "GET" && req.originalUrl.startsWith("/dl/") ){
let path = req.originalUrl.replace("/dl/", "/images/");
let filepath = conf.getImagePath() + "/" + req.user.id + "/" + path;
res.setHeader("Content-Disposition", 'attachment; filename="image.jpg');
res.sendFile(filepath);
return;
} else {
next();
}
}