Merge pull request 'fix-downloads' (#1) from fix-downloads into master
Reviewed-on: https://git.freecumextremist.com/grumbulon/waifurudor.de/pulls/1
This commit is contained in:
commit
f0e7e00ef1
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"booru": "danbooru",
|
||||
"tags": ["onodera_kosaki"],
|
||||
"tags": ["tohsaka_rin"],
|
||||
"rating": "safe"
|
||||
}
|
||||
|
|
|
@ -48,10 +48,10 @@ function getPost(postID) {
|
|||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
downloadFromBooru.downloadFromBooru(
|
||||
body.file_url,
|
||||
"./src/public/assets/waifu.png"
|
||||
);
|
||||
(async () => {
|
||||
await downloadFromBooru
|
||||
.downloadFromBooru(body.file_url, "./src/public/assets/waifu.png")
|
||||
})();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
const fs = require("fs");
|
||||
const client = require("https");
|
||||
const { promisify } = require("util");
|
||||
const got = require("got");
|
||||
const stream = require("stream");
|
||||
|
||||
function downloadFromBooru(url, filepath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
client.get(url, (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
res
|
||||
.pipe(fs.createWriteStream(filepath))
|
||||
.on("error", reject)
|
||||
.once("close", () => resolve(filepath));
|
||||
} else {
|
||||
res.resume();
|
||||
reject(new Error(`Request failed with status code: ${res.statusCode}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
const pipeline = promisify(stream.pipeline);
|
||||
|
||||
async function downloadFromBooru(url, filepath) {
|
||||
await pipeline(got.stream(url), fs.createWriteStream(filepath));
|
||||
}
|
||||
|
||||
module.exports = { downloadFromBooru };
|
||||
|
|
25
src/index.js
25
src/index.js
|
@ -1,33 +1,22 @@
|
|||
const search = require("./helpers/API");
|
||||
const serveStatic = require("serve-static");
|
||||
const express = require("express");
|
||||
const path = require('path');
|
||||
const router = express.Router();
|
||||
|
||||
const path = require("path");
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
app.set("view engine", "pug");
|
||||
app.set("views", path.join(__dirname, "views"));
|
||||
app.use("/assets", express.static(path.join(__dirname, "/public/assets")));
|
||||
|
||||
const options = {
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache',
|
||||
}
|
||||
};
|
||||
|
||||
//app.use(express.static('./src/public'));
|
||||
app.use("/", router)
|
||||
router.get("/", (req, res) => {
|
||||
res.send(main());
|
||||
app.get("/", (req, res) => {
|
||||
res.set("Cache-Control", "no-store");
|
||||
main();
|
||||
res.sendFile(path.join(__dirname, "/public/index.html"));
|
||||
});
|
||||
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`listening on port ${port}`);
|
||||
});
|
||||
|
||||
async function main() {
|
||||
function main() {
|
||||
search.search();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue