From 26bcdc2df7a4adbb71666f9a15fdcce0888a59b8 Mon Sep 17 00:00:00 2001 From: Sam Therapy Date: Mon, 14 Mar 2022 15:13:52 +0100 Subject: [PATCH] add some v e r b o s i t y Signed-off-by: Sam Therapy --- src/helpers/cli.ts | 1 + src/helpers/config.ts | 3 +++ src/helpers/writeconfig.ts | 2 ++ src/local.ts | 2 +- src/remote.ts | 13 ++++++++++--- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/helpers/cli.ts b/src/helpers/cli.ts index e270b1a..d09b765 100644 --- a/src/helpers/cli.ts +++ b/src/helpers/cli.ts @@ -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); } diff --git a/src/helpers/config.ts b/src/helpers/config.ts index 4804bb4..1411998 100644 --- a/src/helpers/config.ts +++ b/src/helpers/config.ts @@ -13,6 +13,9 @@ async function readConfig(): Promise { crashHandler("Error reading config file.", err); return "CRASH"; }); + if (args.verbose) { + console.log(`Read config file: ${args.config}\n${conf}`); + } return conf; } /** diff --git a/src/helpers/writeconfig.ts b/src/helpers/writeconfig.ts index 58f1ce7..37d7220 100644 --- a/src/helpers/writeconfig.ts +++ b/src/helpers/writeconfig.ts @@ -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 diff --git a/src/local.ts b/src/local.ts index 2eeedb5..a02681d 100644 --- a/src/local.ts +++ b/src/local.ts @@ -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}`); } diff --git a/src/remote.ts b/src/remote.ts index 0a743fb..07ca602 100644 --- a/src/remote.ts +++ b/src/remote.ts @@ -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); }