Skip to content

Commit

Permalink
Allow undefined in setServerInfo and remove leading slashes in create…
Browse files Browse the repository at this point in the history
…ImageUrl
  • Loading branch information
YouKnowBlom committed Aug 5, 2021
1 parent 4790694 commit 88b3ce3
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/components/jellyfinApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Dictionary } from '~/types/global';

export abstract class JellyfinApi {
// userId that we are connecting as currently
public static userId: string | null = null;
public static userId: string | undefined;

// Security token to prove authentication
public static accessToken: string | null = null;
public static accessToken: string | undefined;

// Address of server
public static serverAddress: string | null = null;
public static serverAddress: string | undefined;

// device name
public static deviceName = 'Google Cast';
Expand All @@ -21,9 +21,9 @@ export abstract class JellyfinApi {
public static versionNumber = RECEIVERVERSION;

public static setServerInfo(
userId: string,
accessToken: string,
serverAddress: string,
userId?: string,
accessToken?: string,
serverAddress?: string,
receiverName = ''
): void {
console.debug(
Expand Down Expand Up @@ -69,7 +69,7 @@ export abstract class JellyfinApi {
Authorization: auth
};

if (this.accessToken != null) {
if (this.accessToken != undefined) {
headers['X-MediaBrowser-Token'] = this.accessToken;
}

Expand All @@ -79,7 +79,7 @@ export abstract class JellyfinApi {
// Create a basic url.
// Cannot start with /.
public static createUrl(path: string): string {
if (this.serverAddress === null) {
if (this.serverAddress === undefined) {
console.error('JellyfinApi.createUrl: no server address present');

return '';
Expand All @@ -96,6 +96,11 @@ export abstract class JellyfinApi {
// create a path in /Users/userId/ <path>
public static createUserUrl(path: string | null = null): string {
if (path) {
// Remove leading slashes
while (path.charAt(0) === '/') {
path = path.substring(1);
}

return this.createUrl(`Users/${this.userId}/${path}`);
} else {
return this.createUrl(`Users/${this.userId}`);
Expand Down Expand Up @@ -125,9 +130,9 @@ export abstract class JellyfinApi {
// Authenticated ajax
public static authAjax(path: string, args: any): Promise<any> {
if (
this.userId === null ||
this.accessToken === null ||
this.serverAddress === null
this.userId === undefined ||
this.accessToken === undefined ||
this.serverAddress === undefined
) {
console.error(
'JellyfinApi.authAjax: No userid/accesstoken/serverAddress present. Skipping request'
Expand All @@ -147,9 +152,9 @@ export abstract class JellyfinApi {
// Authenticated ajax
public static authAjaxUser(path: string, args: any): Promise<any> {
if (
this.userId === null ||
this.accessToken === null ||
this.serverAddress === null
this.userId === undefined ||
this.accessToken === undefined ||
this.serverAddress === undefined
) {
console.error(
'JellyfinApi.authAjaxUser: No userid/accesstoken/serverAddress present. Skipping request'
Expand Down

0 comments on commit 88b3ce3

Please sign in to comment.