Download from booru
This commit is contained in:
parent
79d8c9f74e
commit
afc95836e7
|
@ -1,28 +1,28 @@
|
|||
const request = require("request");
|
||||
const parseConfig = require("./config")
|
||||
const parseConfig = require("./config");
|
||||
|
||||
function search() {
|
||||
let configFile = "./config.json";
|
||||
parseConfig.readConfig(configFile, (err, config)=>{
|
||||
let configFile = "./config.json";
|
||||
parseConfig.readConfig(configFile, (err, config) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
request(
|
||||
`https://${config.booru}.donmai.us/posts/6.json`,
|
||||
{ json: true },
|
||||
(err, res, body) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
return console.log(err);
|
||||
}
|
||||
request(
|
||||
`https://${config.booru}.donmai.us/posts/6.json`,
|
||||
{ json: true },
|
||||
(err, res, body) => {
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
|
||||
console.log(body.id);
|
||||
console.log(body.created_at);
|
||||
console.log(body.rating);
|
||||
console.log(body.large_file_url);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
console.log(body.id);
|
||||
console.log(body.created_at);
|
||||
console.log(body.rating);
|
||||
console.log(body.large_file_url);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { search };
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
const fs = require("fs");
|
||||
|
||||
|
||||
function readConfig(configPath, callBack) {
|
||||
fs.readFile(configPath, (err, configData) =>{
|
||||
if (err){
|
||||
fs.readFile(configPath, (err, configData) => {
|
||||
if (err) {
|
||||
return callBack && callBack(err);
|
||||
}
|
||||
try {
|
||||
const configObject = JSON.parse(configData);
|
||||
return callBack && callBack(null, configObject);
|
||||
} catch (err) {
|
||||
return callBack && callBack(err)
|
||||
return callBack && callBack(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
const fs = require("fs");
|
||||
const client = require("https");
|
||||
|
||||
function downloadFromBooru(url, filepath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
client.get(url, (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
res
|
||||
.pipe(fs.createWriteStream(filepath))
|
||||
.on("error", reject)
|
||||
.once("close", () => resolve(filepath));
|
||||
} else {
|
||||
res.resume();
|
||||
reject(new Error(`Request failed with status code: ${res.statusCode}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { downloadFromBooru };
|
|
@ -1,7 +1,7 @@
|
|||
const search = require("./helpers/API")
|
||||
const search = require("./helpers/API");
|
||||
|
||||
async function main() {
|
||||
search.search();
|
||||
}
|
||||
|
||||
main();
|
||||
main();
|
||||
|
|
Loading…
Reference in New Issue