Added route for user defined tags
This commit is contained in:
parent
1220d939cb
commit
f5a621b6e1
2 changed files with 33 additions and 1 deletions
|
@ -5,6 +5,7 @@ import { search } from "booru";
|
|||
let configFile = "./config.json";
|
||||
|
||||
export function getFromBooru() {
|
||||
|
||||
readConfig(configFile, (err, config) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
|
@ -39,3 +40,28 @@ export function getFromBooru() {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function userDefinedTags(tags) {
|
||||
readConfig(configFile, (err, config) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
const randBooru = Math.floor(Math.random() * config.booru.length);
|
||||
search(config.booru[randBooru], tags, {
|
||||
limit: 1,
|
||||
random: true,
|
||||
}).then((response) => {
|
||||
if (response.length === 0) {
|
||||
console.log("Error searching for posts.", Error("No posts found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const post = response[0];
|
||||
|
||||
(async () => {
|
||||
await downloadFromBooru(post.fileUrl, "./src/public/assets/waifu.png");
|
||||
})();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { getFromBooru } from "./helpers/API.js";
|
||||
import { getFromBooru, userDefinedTags } from "./helpers/API.js";
|
||||
import express from "express";
|
||||
|
||||
const app = express();
|
||||
|
@ -10,6 +10,12 @@ app.get("/", (req, res) => {
|
|||
res.sendFile("src/public/assets/waifu.png", { root: "." });
|
||||
});
|
||||
|
||||
app.get("/waifu", (req, res) => {
|
||||
const tags = req.query.tags.split(',');
|
||||
userDefinedTags(tags);
|
||||
res.sendFile("src/public/assets/waifu.png", { root: "." })
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`listening on port ${port}`);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue