chore: add comments and format code

This commit is contained in:
LuanRT
2021-10-25 18:02:28 -03:00
parent 389b0f362f
commit b2117f11b9
6 changed files with 33 additions and 41 deletions

View File

@@ -1,9 +1,9 @@
'use strict';
const Uuid = require('uuid');
const Axios = require('axios');
const Utils = require('./Utils');
const Constants = require('./Constants');
const Uuid = require('uuid');
async function engage(session, engagement_type, args = {}) {
if (!session.logged_in) throw new Error('You are not logged in');
@@ -56,7 +56,7 @@ async function browse(session, action_type) {
break;
default:
}
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/browse${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session })).catch((error) => error);
if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message };
return {
@@ -104,11 +104,11 @@ async function notifications(session, action_type, args = {}) {
async function livechat(session, action_type, args = {}) {
let data;
switch (action_type) {
case 'live_chat/send_message':
case 'live_chat/send_message':
data = {
context: session.context,
params: Utils.generateMessageParams(args.channel_id, args.video_id),
clientMessageId: `INntLiB${Uuid.v4()}`,
clientMessageId: `ytjs-${Uuid.v4()}`,
richMessage: {
textSegments: [{ text: args.text }]
}
@@ -127,7 +127,7 @@ async function livechat(session, action_type, args = {}) {
break;
default:
}
const response = await Axios.post(`${Constants.urls.YT_BASE_URL}/youtubei/v1/${action_type}${session.logged_in && session.cookie.length < 1 ? '' : `?key=${session.key}`}`, JSON.stringify(data), Constants.innertube_request_opts({ session, params: args.params })).catch((error) => error);
if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message };
return {
@@ -139,10 +139,7 @@ async function livechat(session, action_type, args = {}) {
async function getContinuation(session, info = {}) {
let data = { context: session.context };
if (info.continuation_token) {
data.continuation = info.continuation_token;
}
info.continuation_token && (data.continuation = info.continuation_token);
if (info.video_id) {
data.videoId = info.video_id;