Skip to content

Commit

Permalink
chore: fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Nov 21, 2024
1 parent 878af7c commit 42b5bf2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 48 deletions.
19 changes: 8 additions & 11 deletions src/core/Actions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Parser, NavigateAction } from '../parser/index.js';
import type {
IBrowseResponse, IGetNotificationsMenuResponse, INextResponse,
IParsedResponse, IPlayerResponse, IRawResponse,
IResolveURLResponse, ISearchResponse, IUpdatedMetadataResponse
} from '../parser/index.js';

import { NavigateAction, Parser } from '../parser/index.js';
import { InnertubeError } from '../utils/Utils.js';

import type { Session } from './index.js';

import type {
IBrowseResponse, IGetNotificationsMenuResponse,
INextResponse, IPlayerResponse, IResolveURLResponse,
ISearchResponse, IUpdatedMetadataResponse,
IParsedResponse, IRawResponse
} from '../parser/types/index.js';

export interface ApiResponse {
success: boolean;
status_code: number;
Expand Down Expand Up @@ -65,9 +64,7 @@ export default class Actions {
s_url.searchParams.set(key, params[key]);
}

const response = await this.session.http.fetch(s_url);

return response;
return await this.session.http.fetch(s_url);
}

/**
Expand Down
28 changes: 8 additions & 20 deletions src/core/OAuth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export type OAuth2AuthErrorEventHandler = (err: OAuth2Error) => void;
export default class OAuth2 {
#session: Session;

YTTV_URL: URL;
AUTH_SERVER_CODE_URL: URL;
AUTH_SERVER_TOKEN_URL: URL;
AUTH_SERVER_REVOKE_TOKEN_URL: URL;
public YTTV_URL: URL;
public AUTH_SERVER_CODE_URL: URL;
public AUTH_SERVER_TOKEN_URL: URL;
public AUTH_SERVER_REVOKE_TOKEN_URL: URL;

client_id: OAuth2ClientID | undefined;
oauth2_tokens: OAuth2Tokens | undefined;
public client_id: OAuth2ClientID | undefined;
public oauth2_tokens: OAuth2Tokens | undefined;

constructor(session: Session) {
this.#session = session;
Expand Down Expand Up @@ -127,7 +127,7 @@ export default class OAuth2 {
await this.#session.cache?.remove('youtubei_oauth_credentials');
}

async pollForAccessToken(device_and_user_code: DeviceAndUserCode): Promise<void> {
pollForAccessToken(device_and_user_code: DeviceAndUserCode): void {
if (!this.client_id)
throw new OAuth2Error('Client ID is missing.');

Expand Down Expand Up @@ -317,19 +317,7 @@ export default class OAuth2 {
}

validateTokens(tokens: OAuth2Tokens): boolean {
const propertiesAreValid = (
Boolean(tokens.access_token) &&
Boolean(tokens.expiry_date) &&
Boolean(tokens.refresh_token)
);

const typesAreValid = (
typeof tokens.access_token === 'string' &&
typeof tokens.expiry_date === 'string' &&
typeof tokens.refresh_token === 'string'
);

return typesAreValid && propertiesAreValid;
return !(!tokens.access_token || !tokens.refresh_token || !tokens.expiry_date);
}

get #http() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/clients/Music.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type { Actions, Session } from '../index.js';

export default class Music {
#session: Session;
#actions: Actions;
readonly #actions: Actions;

constructor(session: Session) {
this.#session = session;
Expand Down
32 changes: 16 additions & 16 deletions src/utils/Log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default class Log {
private static YTJS_TAG = 'YOUTUBEJS';
static #YTJS_TAG = 'YOUTUBEJS';

public static Level = {
NONE: 0,
Expand All @@ -9,41 +9,41 @@ export default class Log {
DEBUG: 4
};

private static log_map_ = {
static #log_map_ = {
[Log.Level.ERROR]: (...args: any[]) => console.error(...args),
[Log.Level.WARNING]: (...args: any[]) => console.warn(...args),
[Log.Level.INFO]: (...args: any[]) => console.info(...args),
[Log.Level.DEBUG]: (...args: any[]) => console.debug(...args)
};

private static log_level_ = [ Log.Level.WARNING ];
private static one_time_warnings_issued_ = new Set<string>();
static #log_level_ = [ Log.Level.WARNING ];
static #one_time_warnings_issued_ = new Set<string>();

static warnOnce = (id: string, ...args: any[]) => {
if (this.one_time_warnings_issued_.has(id))
if (this.#one_time_warnings_issued_.has(id))
return;
this.doLog(Log.Level.WARNING, id, args);
this.one_time_warnings_issued_.add(id);
this.#doLog(Log.Level.WARNING, id, args);
this.#one_time_warnings_issued_.add(id);
};

static warn = (tag?: string, ...args: any[]) => this.doLog(Log.Level.WARNING, tag, args);
static error = (tag?: string, ...args: any[]) => this.doLog(Log.Level.ERROR, tag, args);
static info = (tag?: string, ...args: any[]) => this.doLog(Log.Level.INFO, tag, args);
static debug = (tag?: string, ...args: any[]) => this.doLog(Log.Level.DEBUG, tag, args);
static warn = (tag?: string, ...args: any[]) => this.#doLog(Log.Level.WARNING, tag, args);
static error = (tag?: string, ...args: any[]) => this.#doLog(Log.Level.ERROR, tag, args);
static info = (tag?: string, ...args: any[]) => this.#doLog(Log.Level.INFO, tag, args);
static debug = (tag?: string, ...args: any[]) => this.#doLog(Log.Level.DEBUG, tag, args);

private static doLog(level: number, tag?: string, args?: any[]) {
if (!this.log_map_[level] || !this.log_level_.includes(level))
static #doLog(level: number, tag?: string, args?: any[]) {
if (!this.#log_map_ [level] || !this.#log_level_.includes(level))
return;

const tags = [ `[${this.YTJS_TAG}]` ];
const tags = [ `[${this.#YTJS_TAG}]` ];

if (tag)
tags.push(`[${tag}]`);

this.log_map_[level](`${tags.join('')}:`, ...(args || []));
this.#log_map_ [level](`${tags.join('')}:`, ...(args || []));
}

static setLevel(...args: number[]) {
this.log_level_ = args;
this.#log_level_ = args;
}
}

0 comments on commit 42b5bf2

Please sign in to comment.