Rewrite complete, added error checks and some stuff
This commit is contained in:
parent
2e78190d43
commit
d4e5257f74
|
@ -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();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { search } from "./helpers/API.js";
|
||||
import { getFromBooru } from "./helpers/API.js";
|
||||
import express from "express";
|
||||
|
||||
const app = express();
|
||||
|
|
Loading…
Reference in New Issue