Add overload to getHandiworkInformation

pull/73/head
MillenniumEarl 2021-03-02 20:28:05 +01:00
parent ffe9271bcf
commit f4af0c43f1
1 changed files with 17 additions and 8 deletions

View File

@ -17,13 +17,22 @@ import { ILink, IPostElement } from "./post-parse.js";
* *
* @todo It does not currently support assets. * @todo It does not currently support assets.
*/ */
export default async function getHandiworkInformation<T extends IBasic>(url: string): Promise<T> { export async function getHandiworkInformation<T extends IBasic>(url: string): Promise<T>
shared.logger.info(`Obtaining handiwork from ${url}`);
// Fetch thread data export async function getHandiworkInformation<T extends IBasic>(url: string): Promise<T>
const id = extractIDFromURL(url);
const thread: Thread = new Thread(id); export default async function getHandiworkInformation<T extends IBasic>(arg: string | Thread): Promise<T> {
await thread.fetch(); // 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 // Convert the info from thread to handiwork
const hw: HandiWork = {} as HandiWork; const hw: HandiWork = {} as HandiWork;
@ -40,9 +49,9 @@ export default async function getHandiworkInformation<T extends IBasic>(url: str
// Fetch info from first post // Fetch info from first post
const post = await thread.getPost(1); const post = await thread.getPost(1);
fillWithPostData(hw, post.body); fillWithPostData(hw, post.body);
return <T><unknown>hw; return <T><unknown>hw;
}; }
//#region Private methods //#region Private methods