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