mirror of
https://github.com/slynn1324/tinypin
synced 2025-12-15 15:55:36 +00:00
refactored server to break out into node modules
This commit is contained in:
23
server/image-server.js
Normal file
23
server/image-server.js
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user