Compare commits
4 Commits
4dd589fdce
...
mongodb
| Author | SHA1 | Date | |
|---|---|---|---|
| 202f7360cb | |||
| 22850e929d | |||
| f0595c0cf7 | |||
| 1b9e51f1cb |
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
.env
|
.env
|
||||||
|
output.log
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ require("dotenv").config();
|
|||||||
var {MongoClient, GridFSBucket} = require("mongodb");
|
var {MongoClient, GridFSBucket} = require("mongodb");
|
||||||
var express = require("express");
|
var express = require("express");
|
||||||
var app = express();
|
var app = express();
|
||||||
|
app.set("trust proxy", "127.0.0.1");
|
||||||
var dbclient = new MongoClient(process.env.DB_URI);
|
var dbclient = new MongoClient(process.env.DB_URI);
|
||||||
dbclient.connect().then(async () => {
|
dbclient.connect().then(async () => {
|
||||||
var db = dbclient.db("mikudb");
|
var db = dbclient.db("mikudb");
|
||||||
@@ -17,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");
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user