chore: clean up build steps

This commit is contained in:
LuanRT
2022-07-20 16:28:51 -03:00
parent fb68e6bcfe
commit 6a5ebeb8ee
287 changed files with 40 additions and 40 deletions

View File

@@ -0,0 +1,21 @@
import { YTNode } from '../../helpers';
class AuthorCommentBadge extends YTNode {
static type = 'AuthorCommentBadge';
#data;
constructor(data) {
super();
this.icon_type = data.icon.iconType;
this.tooltip = data.iconTooltip;
// *** For consistency
this.tooltip === 'Verified' &&
(this.style = 'BADGE_STYLE_TYPE_VERIFIED') &&
(data.style = 'BADGE_STYLE_TYPE_VERIFIED');
this.#data = data;
}
get orig_badge() {
return this.#data;
}
}
export default AuthorCommentBadge;

View File

@@ -0,0 +1,109 @@
import Parser from '../../index';
import Text from '../misc/Text';
import Thumbnail from '../misc/Thumbnail';
import Author from '../misc/Author';
import Proto from '../../../proto/index';
import { InnertubeError } from '../../../utils/Utils';
import { YTNode } from '../../helpers';
class Comment extends YTNode {
static type = 'Comment';
#actions;
constructor(data) {
super();
this.content = new Text(data.contentText);
this.published = new Text(data.publishedTimeText);
this.author_is_channel_owner = data.authorIsChannelOwner;
this.current_user_reply_thumbnail = Thumbnail.fromResponse(data.currentUserReplyThumbnail);
this.author_badge = Parser.parse(data.authorCommentBadge);
this.author = new Author({
...data.authorText,
navigationEndpoint: data.authorEndpoint
}, this.author_badge ? [ {
metadataBadgeRenderer: this.author_badge?.orig_badge
} ] : null, data.authorThumbnail);
this.action_menu = Parser.parse(data.actionMenu);
this.action_buttons = Parser.parse(data.actionButtons);
this.comment_id = data.commentId;
this.vote_status = data.voteStatus;
this.vote_count = {
text: data.voteCount ? data.voteCount.accessibility.accessibilityData?.label.replace(/\D/g, '') : '0',
short_text: data.voteCount ? new Text(data.voteCount).toString() : '0'
};
this.reply_count = data.replyCount || 0;
this.is_liked = this.action_buttons.item().like_button.is_toggled;
this.is_disliked = this.action_buttons.item().dislike_button.is_toggled;
this.is_pinned = !!data.pinnedCommentBadge;
}
/**
* API response.
* @typedef {{ success: boolean, status_code: number, data: object }} Response
*/
/**
* Likes the comment.
* @returns {Promise.<Response>}
*/
async like() {
const button = this.action_buttons.like_button;
if (button.is_toggled)
throw new InnertubeError('This comment is already liked', { comment_id: this.comment_id });
const response = await button.endpoint.callTest(this.#actions, { parse: false });
return response;
}
/**
* Dislikes the comment.
* @returns {Promise.<Response>}
*/
async dislike() {
const button = this.action_buttons.dislike_button;
if (button.is_toggled)
throw new InnertubeError('This comment is already disliked', { comment_id: this.comment_id });
const response = await button.endpoint.callTest(this.#actions, { parse: false });
return response;
}
/**
* Creates a reply to the comment.
* @param {string} text
* @returns {Promise.<Response>}
*/
async reply(text) {
if (!this.action_buttons.reply_button)
throw new InnertubeError('Cannot reply to another reply. Try mentioning the user instead.', { comment_id: this.comment_id });
const button = this.action_buttons.reply_button;
const dialog_button = button.endpoint.dialog.reply_button;
const payload = {
params: {
commentText: text
}
};
const response = await dialog_button.endpoint.callTest(this.#actions, payload);
return response;
}
/**
* Translates the comment to the given language.
* @param {string} target_language
*/
async translate(target_language) {
// Emojis must be removed otherwise InnerTube throws a 400 status code at us.
const text = this.content.toString().replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu, '');
const payload = {
text,
target_language,
comment_id: this.comment_id
};
const action = Proto.encodeCommentActionParams(22, payload);
const response = await this.#actions.execute('comment/perform_comment_action', { action, client: 'ANDROID' });
// TODO: maybe add these to Parser#parseResponse?
const mutations = response.data.frameworkUpdates.entityBatchUpdate.mutations;
const content = mutations[0].payload.commentEntityPayload.translatedContent.content;
return { ...response, content };
}
/**
* @param {import('../../../../core/Actions').default} actions
*/
setActions(actions) {
this.#actions = actions;
}
}
export default Comment;

View File

@@ -0,0 +1,14 @@
import Parser from '../../index';
import { YTNode } from '../../helpers';
class CommentActionButtons extends YTNode {
static type = 'CommentActionButtons';
constructor(data) {
super();
this.like_button = Parser.parse(data.likeButton);
this.dislike_button = Parser.parse(data.dislikeButton);
this.reply_button = Parser.parse(data.replyButton);
}
}
export default CommentActionButtons;

View File

@@ -0,0 +1,14 @@
import Parser from '../../index';
import { YTNode } from '../../helpers';
class CommentReplies extends YTNode {
static type = 'CommentReplies';
constructor(data) {
super();
this.contents = Parser.parse(data.contents);
this.view_replies = Parser.parse(data.viewReplies);
this.hide_replies = Parser.parse(data.hideReplies);
}
}
export default CommentReplies;

View File

@@ -0,0 +1,18 @@
import Parser from '../../index';
import Thumbnail from '../misc/Thumbnail';
import Text from '../misc/Text';
import { YTNode } from '../../helpers';
class CommentReplyDialog extends YTNode {
static type = 'CommentReplyDialog';
constructor(data) {
super();
this.reply_button = Parser.parse(data.replyButton);
this.cancel_button = Parser.parse(data.cancelButton);
this.author_thumbnail = Thumbnail.fromResponse(data.authorThumbnail);
this.placeholder = new Text(data.placeholderText);
this.error_message = new Text(data.errorMessage);
}
}
export default CommentReplyDialog;

View File

@@ -0,0 +1,18 @@
import Parser from '../../index';
import Thumbnail from '../misc/Thumbnail';
import Text from '../misc/Text';
import { YTNode } from '../../helpers';
class CommentSimplebox extends YTNode {
static type = 'CommentSimplebox';
constructor(data) {
super();
this.submit_button = Parser.parse(data.submitButton);
this.cancel_button = Parser.parse(data.cancelButton);
this.author_thumbnails = Thumbnail.fromResponse(data.authorThumbnail);
this.placeholder = new Text(data.placeholderText);
this.avatar_size = data.avatarSize;
}
}
export default CommentSimplebox;

View File

@@ -0,0 +1,63 @@
import Parser from '../../index';
import { InnertubeError } from '../../../utils/Utils';
import { YTNode } from '../../helpers';
import Comment from './Comment';
import ContinuationItem from '../ContinuationItem';
import Actions from '../../../core/Actions';
import NavigationEndpoint from '../NavigationEndpoint';
class CommentThread extends YTNode {
static type = 'CommentThread';
#replies;
#actions?: Actions;
#continuation?: ContinuationItem;
is_moderated_elq_comment: boolean;
comment;
replies: Comment[] | undefined;
constructor(data: any) {
super();
this.comment = Parser.parseItem(data.comment, Comment);
this.#replies = Parser.parseItem(data.replies);
this.is_moderated_elq_comment = data.isModeratedElqComment;
}
/**
* Retrieves replies to this comment thread.
*/
async getReplies() {
if (!this.#actions)
throw new InnertubeError('Actions not set for this CommentThread.');
if (!this.#replies)
throw new InnertubeError('This comment has no replies.', { comment_id: this.comment?.comment_id });
const continuation = this.#replies.key('contents').parsed().array().get({ type: 'ContinuationItem' })?.as(ContinuationItem);
const response = await continuation?.endpoint.callTest(this.#actions);
this.replies = response?.on_response_received_endpoints_memo?.getType(Comment).map((comment) => {
comment.setActions(this.#actions);
return comment;
});
this.#continuation = response?.on_response_received_endpoints_memo.getType(ContinuationItem)?.[0];
return this;
}
/**
* Retrieves next batch of replies.
*/
async getContinuation() {
if (!this.replies)
throw new InnertubeError('Continuation not available.');
if (!this.#continuation)
throw new InnertubeError('Continuation not found.');
if (!this.#actions)
throw new InnertubeError('Actions not set for this CommentThread.');
const response = await this.#continuation.button?.item().key('endpoint').nodeOfType(NavigationEndpoint).callTest(this.#actions);
this.replies = response?.on_response_received_endpoints_memo.getType(Comment).map((comment) => {
comment.setActions(this.#actions);
return comment;
});
this.#continuation = response?.on_response_received_endpoints_memo.getType(ContinuationItem)?.[0];
return this;
}
setActions(actions: Actions) {
this.#actions = actions;
}
}
export default CommentThread;

View File

@@ -0,0 +1,17 @@
import Text from '../misc/Text';
import Thumbnail from '../misc/Thumbnail';
import { YTNode } from '../../helpers';
class CommentsEntryPointHeader extends YTNode {
static type = 'CommentsEntryPointHeader';
constructor(data) {
super();
this.header = new Text(data.headerText);
this.comment_count = new Text(data.commentCount);
this.teaser_avatar = Thumbnail.fromResponse(data.teaserAvatar || data.simpleboxAvatar);
this.teaser_content = new Text(data.teaserContent);
this.simplebox_placeholder = new Text(data.simpleboxPlaceholder);
}
}
export default CommentsEntryPointHeader;

View File

@@ -0,0 +1,25 @@
import Parser from '../../index';
import Text from '../misc/Text';
import Thumbnail from '../misc/Thumbnail';
import { YTNode } from '../../helpers';
class CommentsHeader extends YTNode {
static type = 'CommentsHeader';
constructor(data) {
super();
this.title = new Text(data.titleText);
this.count = new Text(data.countText);
this.comments_count = new Text(data.commentsCount);
this.create_renderer = Parser.parseItem(data.createRenderer);
this.sort_menu = Parser.parse(data.sortMenu);
this.custom_emojis = data.customEmojis?.map((emoji) => ({
emoji_id: emoji.emojiId,
shortcuts: emoji.shortcuts,
search_terms: emoji.searchTerms,
image: Thumbnail.fromResponse(emoji.image),
is_custom_emoji: emoji.isCustomEmoji
})) || null;
}
}
export default CommentsHeader;