Post is now a lazy class
parent
63d27febfa
commit
4a16642540
|
@ -65,19 +65,16 @@ export default class Post {
|
|||
|
||||
//#endregion Getters
|
||||
|
||||
constructor(id: number) { this._id = id; }
|
||||
|
||||
//#region Public methods
|
||||
|
||||
public async fetchData(id: number): Promise<void>;
|
||||
|
||||
public async fetchData(article: cheerio.Cheerio): Promise<void>;
|
||||
|
||||
/**
|
||||
* Gets the post data starting from its unique ID for the entire platform.
|
||||
*/
|
||||
public async fetchData(arg: number | cheerio.Cheerio): Promise<void> {
|
||||
if (typeof arg === "number") {
|
||||
public async fetch() {
|
||||
// Fetch HTML page containing the post
|
||||
const url = new URL(arg.toString(), urls.F95_POSTS).toString();
|
||||
const url = new URL(this.id.toString(), urls.F95_POSTS).toString();
|
||||
const htmlResponse = await fetchHTML(url);
|
||||
|
||||
if (htmlResponse.isSuccess()) {
|
||||
|
@ -89,14 +86,12 @@ export default class Post {
|
|||
const sid: string = $(el).find(POST.ID).attr("id").replace("post-", "");
|
||||
const id = parseInt(sid);
|
||||
|
||||
if (id === arg) return el;
|
||||
if (id === this.id) return el;
|
||||
});
|
||||
|
||||
// Finally parse the post
|
||||
this.parsePost($(post));
|
||||
} else throw htmlResponse.value;
|
||||
|
||||
} else this.parsePost(arg);
|
||||
}
|
||||
|
||||
//#endregion Public methods
|
||||
|
|
Loading…
Reference in New Issue