From f4af0c43f1c312be177264f4191000f605caf670 Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Tue, 2 Mar 2021 20:28:05 +0100 Subject: [PATCH] Add overload to getHandiworkInformation --- src/scripts/scrape-data/handiwork-parse.ts | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/scripts/scrape-data/handiwork-parse.ts b/src/scripts/scrape-data/handiwork-parse.ts index c2838bc..5e4cd85 100644 --- a/src/scripts/scrape-data/handiwork-parse.ts +++ b/src/scripts/scrape-data/handiwork-parse.ts @@ -17,13 +17,22 @@ import { ILink, IPostElement } from "./post-parse.js"; * * @todo It does not currently support assets. */ -export default async function getHandiworkInformation(url: string): Promise { - shared.logger.info(`Obtaining handiwork from ${url}`); +export async function getHandiworkInformation(url: string): Promise - // Fetch thread data - const id = extractIDFromURL(url); - const thread: Thread = new Thread(id); - await thread.fetch(); +export async function getHandiworkInformation(url: string): Promise + +export default async function getHandiworkInformation(arg: string | Thread): Promise { + // Local variables + let thread: Thread = null; + + if (typeof arg === "string") { + // Fetch thread data + const id = extractIDFromURL(arg); + thread = new Thread(id); + await thread.fetch(); + } else thread = arg; + + shared.logger.info(`Obtaining handiwork from ${thread.url}`); // Convert the info from thread to handiwork const hw: HandiWork = {} as HandiWork; @@ -40,9 +49,9 @@ export default async function getHandiworkInformation(url: str // Fetch info from first post const post = await thread.getPost(1); fillWithPostData(hw, post.body); - + return hw; -}; +} //#region Private methods