add some v e r b o s i t y
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2022-03-14 15:13:52 +01:00
parent 67a86124b0
commit 26bcdc2df7
Signed by: sam
GPG Key ID: 4D8B07C18F31ACBD
5 changed files with 17 additions and 4 deletions

View File

@ -60,6 +60,7 @@ if (args.verbose) console.log("Running in verbose mode.\n");
if (args.writeConfig) {
writeConfig();
console.log("Wrote default config file to ./config.jsonc");
exit(0);
}

View File

@ -13,6 +13,9 @@ async function readConfig(): Promise<string> {
crashHandler("Error reading config file.", err);
return "CRASH";
});
if (args.verbose) {
console.log(`Read config file: ${args.config}\n${conf}`);
}
return conf;
}
/**

View File

@ -1,9 +1,11 @@
import { writeFileSync } from "fs";
import args from "./cli.js";
/**
* Writes the sample config file to disk
* @returns Nothing
*/
export default function writeConfig() {
if (args.verbose) console.log("Writing sample config to config.jsonc");
writeFileSync(
"./config.jsonc",
// eslint-disable-next-line prettier/prettier

View File

@ -51,7 +51,7 @@ export default async function getLocalImage(conf: config) {
sensitivity = false;
}
if (args.verbosity) {
if (args.verbose) {
console.log(`File being sent: ${file}`);
console.log(`Sensitivity: ${sensitivity}`);
}

View File

@ -1,10 +1,11 @@
import { search } from "booru";
import Post from "booru/dist/structures/Post"; // Ce n'est pas bien
import { createReadStream, createWriteStream, unlink } from "fs";
import got from "got-cjs";
import { createWriteStream, createReadStream, unlink } from "fs";
import { promisify } from "node:util";
import stream from "node:stream";
import { promisify } from "node:util";
import { exit } from "process";
import args from "./helpers/cli.js";
import crashHandler from "./helpers/error.js";
import { config } from "./helpers/types.js";
import postImage from "./post.js";
@ -29,12 +30,14 @@ export default async function getRemoteImage(conf: config) {
return;
}
const post = searchResults[0];
if (args.verbose) console.log(`Found post: ${post.id} at ${post.file_url}`);
// Set the post as sensitive if the rating is not safe
const sensitivity: boolean = post.rating !== "s";
// Make an HTTP request for the image
const filename: string = post.fileUrl?.split("/").pop() as string; // Type checks for type checks
const pipeline = promisify(stream.pipeline);
// Make the HTTP request as a stream so it can be piped to the file system
await pipeline(
got.stream(post.file_url as string),
createWriteStream(filename)
@ -42,11 +45,14 @@ export default async function getRemoteImage(conf: config) {
crashHandler("Error saving downloading image.", err);
return;
});
if (args.verbose) console.log(`Saved image to ${filename}`);
const str = createReadStream(filename).on("error", (err: Error) => {
crashHandler("Error reading downloaded image.", err);
});
if (args.verbose) {
console.log(`File being sent: ${filename}\nSensitivity: ${sensitivity}`);
}
// Make a status with the image
await postImage(str, sensitivity, conf);
@ -57,5 +63,6 @@ export default async function getRemoteImage(conf: config) {
return;
}
});
if (args.verbose) console.log(`Successfully deleted image ${filename}`);
exit(0);
}