1
0
Fork 0

Rewrite complete, added error checks and some stuff

This commit is contained in:
grumbulon 2022-04-04 21:04:28 -04:00
parent 2e78190d43
commit d4e5257f74
2 changed files with 22 additions and 13 deletions

View File

@ -1,7 +1,6 @@
import { readConfig } from "./config.js";
import downloadFromBooru from "./download.js";
import Booru from 'booru';
import { search } from "booru";
let configFile = "./config.json";
@ -11,16 +10,26 @@ export function getFromBooru() {
console.log(err);
return;
}
if (config.rating === "safe") {
config.tags.push("rating:safe");
}
const randBooru = Math.floor(Math.random() * config.booru.length);
Booru.search(config.booru[randBooru], config.tags, { limit: 1, random: true }).then(
(posts) => {
(async () => {
await downloadFromBooru(
posts[0].fileUrl,
"./src/public/assets/waifu.png"
);
})();
search(config.booru[randBooru], config.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");
})();
});
});
}
}
getFromBooru();

View File

@ -1,4 +1,4 @@
import { search } from "./helpers/API.js";
import { getFromBooru } from "./helpers/API.js";
import express from "express";
const app = express();