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.
*/
export default async function getHandiworkInformation<T extends IBasic>(url: string): Promise<T> {
shared.logger.info(`Obtaining handiwork from ${url}`);
export async function getHandiworkInformation<T extends IBasic>(url: string): Promise<T>
// Fetch thread data
const id = extractIDFromURL(url);
const thread: Thread = new Thread(id);
await thread.fetch();
export async function getHandiworkInformation<T extends IBasic>(url: string): Promise<T>
export default async function getHandiworkInformation<T extends IBasic>(arg: string | Thread): Promise<T> {
// 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;
@ -42,7 +51,7 @@ export default async function getHandiworkInformation<T extends IBasic>(url: str
fillWithPostData(hw, post.body);
return <T><unknown>hw;
};
}
//#region Private methods