From 8acc2a04bf95dc3b05f54b54e6eabf9f36c8a7a0 Mon Sep 17 00:00:00 2001 From: grumbulon Date: Sat, 2 Apr 2022 21:39:29 -0400 Subject: [PATCH] Added stuff so you can search safe or not, and excluded images from being uploaded to git --- .gitignore | 5 ++++- src/helpers/API.js | 24 +++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 13fbdfd..1d3b3ca 100644 --- a/.gitignore +++ b/.gitignore @@ -117,4 +117,7 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* -.vscode/* \ No newline at end of file +.vscode/* + +#merde +img/* \ No newline at end of file diff --git a/src/helpers/API.js b/src/helpers/API.js index 3ef8b7b..99024bc 100644 --- a/src/helpers/API.js +++ b/src/helpers/API.js @@ -11,21 +11,31 @@ function search() { console.log(err); return; } - //Get list of posts for the tag(s) - request( - `https://${config.booru}.donmai.us/posts.json?tags=${config.tags}&z=1`, - { json: true }, - (err, res, body) => { + + if (config.rating === "safe") { + let queryUrl = `https://${config.booru}.donmai.us/posts.json?tags=${config.tags}+rating:${config.rating}&z=1`; + request(queryUrl, { json: true }, (err, res, body) => { if (err) { return console.log(err); } const randPost = Math.floor(Math.random() * body.length); const postID = body[randPost].id; getPost(postID); - } - ); + }); + } else { + let queryUrl = `https://${config.booru}.donmai.us/posts.json?tags=${config.tags}&z=1`; + request(queryUrl, { json: true }, (err, res, body) => { + if (err) { + return console.log(err); + } + const randPost = Math.floor(Math.random() * body.length); + const postID = body[randPost].id; + getPost(postID); + }); + } }); } + function getPost(postID) { parseConfig.readConfig(configFile, (err, config) => { if (err) {