Compare commits

...

3 Commits

Author SHA1 Message Date
Lamp
202f7360cb add content-type and content-disposition 2021-11-25 15:04:59 -08:00
Lamp
22850e929d port 2021-11-25 14:06:55 -08:00
f0595c0cf7 add noredirect 2021-11-25 14:03:49 -08:00

View File

@ -18,15 +18,18 @@ dbclient.connect().then(async () => {
app.get("/https://www.pixiv.net/en/artworks/:id", async (req, res) => { app.get("/https://www.pixiv.net/en/artworks/:id", async (req, res) => {
//if (req.headers["cache-control"] == "max-age=0") { // this indicates a reload in chrome //if (req.headers["cache-control"] == "max-age=0") { // this indicates a reload in chrome
// but chrome still sends it after redirect // but chrome still sends it after redirect
if (ipa_lastload_map[req.ip] == req.params.id) { if (ipa_lastload_map[req.ip] == req.params.id && req.query.noredirect == null) {
return redirectRandom(req, res); return redirectRandom(req, res);
} else ipa_lastload_map[req.ip] = req.params.id; } else ipa_lastload_map[req.ip] = req.params.id;
console.log(new Date().toLocaleString(), req.ip, req.params.id); console.log(new Date().toLocaleString(), req.ip, req.params.id);
var asdf = await collection.findOne({_id: req.params.id}, {downloaded_images: 1}); var asdf = await collection.findOne({_id: req.params.id}, {downloaded_images: 1});
if (!asdf) return res.sendStatus(404); if (!asdf) return res.sendStatus(404);
var filename = Object.keys(asdf.downloaded_images)[0];
res.type(filename.split('.').pop());
res.header("Content-Disposition", `filename=${filename}`);
var gfsid = Object.values(asdf.downloaded_images)[0]; var gfsid = Object.values(asdf.downloaded_images)[0];
bucket.openDownloadStream(gfsid).pipe(res); bucket.openDownloadStream(gfsid).pipe(res);
}); });
app.listen(8039); app.listen(39);
console.log("server ready"); console.log("server ready");
}); });