Merge pull request 'search-route' (#5) from search-route into master
Reviewed-on: https://git.freecumextremist.com/grumbulon/waifurudor.de/pulls/5
This commit is contained in:
commit
b4b22d1f8a
3 changed files with 43 additions and 3 deletions
|
@ -2,6 +2,12 @@
|
|||
|
||||
It's like foxrudor.de for anime girls, but worse
|
||||
|
||||
## How to use
|
||||
|
||||
Open the web site up and see the predefined anime girls, or define your own tags like:
|
||||
|
||||
https://waifurudor.de/?tags=tohsaka_rin,-feet,-underwear,rating:safe
|
||||
|
||||
## Server Install
|
||||
|
||||
Clone the repo to where ever you will be hosting this and run the following command to install the dependencies.
|
||||
|
|
|
@ -2,7 +2,7 @@ import { readConfig } from "./config.js";
|
|||
import downloadFromBooru from "./download.js";
|
||||
import { search } from "booru";
|
||||
|
||||
let configFile = "./config.json";
|
||||
const configFile = "./config.json";
|
||||
|
||||
export function getFromBooru() {
|
||||
readConfig(configFile, (err, config) => {
|
||||
|
@ -39,3 +39,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");
|
||||
})();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
13
src/index.js
13
src/index.js
|
@ -1,4 +1,4 @@
|
|||
import { getFromBooru } from "./helpers/API.js";
|
||||
import { getFromBooru, userDefinedTags } from "./helpers/API.js";
|
||||
import express from "express";
|
||||
|
||||
const app = express();
|
||||
|
@ -6,7 +6,16 @@ const port = 3000;
|
|||
|
||||
app.get("/", (req, res) => {
|
||||
res.set("Cache-Control", "no-store");
|
||||
getFromBooru();
|
||||
if (!req.query.tags) {
|
||||
getFromBooru();
|
||||
} else {
|
||||
const tags = req.query.tags.split(",");
|
||||
userDefinedTags(tags);
|
||||
}
|
||||
res.sendFile("src/public/assets/waifu.png", { root: "." });
|
||||
});
|
||||
|
||||
app.get("/waifu", (req, res) => {
|
||||
res.sendFile("src/public/assets/waifu.png", { root: "." });
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue