refactor(ytmusic)!: rewrite Album to TypeScript

This commit is contained in:
LuanRT
2022-07-29 06:58:28 -03:00
parent 99233bcf7a
commit 72c3af84b0
2 changed files with 36 additions and 32 deletions

View File

@@ -1,32 +0,0 @@
import Parser from '../index';
class Album {
#page;
#actions;
/**
* @param {object} response - API response.
* @param {import('../../core/Actions').default} actions
*/
constructor(response, actions) {
this.#page = Parser.parseResponse(response.data);
this.#actions = actions;
/** @type {import('../classes/MusicDetailHeader')[]} */
this.header = this.#page.header;
/** @type {string} */
this.url = this.#page.microformat.url_canonical;
/** @type {import('../classes/MusicResponsiveListItem')[]} */
this.contents = this.#page.contents_memo.get('MusicShelf')?.[0].contents;
this.sections = this.#page.contents_memo.get('MusicCarouselShelf') || [];
}
get page() {
return this.#page;
}
}
export default Album;

View File

@@ -0,0 +1,36 @@
import Parser, { ParsedResponse } from '../index';
import Actions, { AxioslikeResponse } from '../../core/Actions';
import MusicDetailHeader from '../classes/MusicDetailHeader';
import MicroformatData from '../classes/MicroformatData';
import MusicCarouselShelf from '../classes/MusicCarouselShelf';
import MusicResponsiveListItem from '../classes/MusicResponsiveListItem';
import MusicShelf from '../classes/MusicShelf';
class Album {
#page;
#actions;
header;
contents;
sections;
url: string | null;
constructor(response: AxioslikeResponse, actions: Actions) {
this.#page = Parser.parseResponse(response.data);
this.#actions = actions;
this.header = this.#page.header.item().as(MusicDetailHeader);
this.url = this.#page.microformat?.as(MicroformatData).url_canonical || null;
this.contents = this.#page.contents_memo.get('MusicShelf')?.[0].as(MusicShelf).contents.array().as(MusicResponsiveListItem);
this.sections = this.#page.contents_memo.get('MusicCarouselShelf') as MusicCarouselShelf[] || ([] as MusicCarouselShelf[]);
}
get page(): ParsedResponse {
return this.#page;
}
}
export default Album;