Skip to content

Commit

Permalink
fix: reviewed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hillaliy committed Oct 22, 2024
1 parent df4e24f commit 16d18bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/integrations/src/plex/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface MediaContainer {
title?: string;
index?: number;
type: string;
live?: string;
};
}[];
}
Expand Down
19 changes: 10 additions & 9 deletions packages/integrations/src/plex/plex-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class PlexIntegration extends Integration {
});
const body = await response.text();
// convert xml response to objects, as there is no JSON api
const data = await PlexIntegration.parseXmlAsync<PlexResponse>(body);
const data = await PlexIntegration.parseXml<PlexResponse>(body);
const mediaContainer = data.MediaContainer;
// no sessions are open or available
if (!mediaContainer.Video) {
Expand Down Expand Up @@ -46,7 +46,7 @@ export class PlexIntegration extends Integration {
profilePictureUrl: userElement?.$.thumb ?? null,
},
currentlyPlaying: {
type: PlexIntegration.getCurrentlyPlayingType(videoElement.$.type) ?? "video",
type: videoElement.$.live === "1" ? "tv" : PlexIntegration.getCurrentlyPlayingType(videoElement.$.type),
name: videoElement.$.grandparentTitle ?? videoElement.$.title ?? "Unknown",
seasonName: videoElement.$.parentTitle,
episodeName: videoElement.$.title ?? null,
Expand All @@ -72,21 +72,22 @@ export class PlexIntegration extends Integration {
});
},
handleResponseAsync: async (response) => {
const result = await response.text();
const parsedResponse = (await parseStringPromise(result)) as unknown;
if (typeof parsedResponse === "object" && parsedResponse !== null) {
try {
const result = await response.text();
await PlexIntegration.parseXml<PlexResponse>(result);
return;
} catch {
throw new IntegrationTestConnectionError("invalidCredentials");
}
throw new IntegrationTestConnectionError("invalidCredentials");
},
});
}

static async parseXmlAsync<T>(xml: string): Promise<T> {
static parseXml<T>(xml: string): Promise<T> {
return parseStringPromise(xml) as Promise<T>;
}

static getCurrentlyPlayingType(type: string): "movie" | "audio" | "video" | "tv" | undefined {
static getCurrentlyPlayingType(type: string): NonNullable<StreamSession["currentlyPlaying"]>["type"] {
switch (type) {
case "movie":
return "movie";
Expand All @@ -95,7 +96,7 @@ export class PlexIntegration extends Integration {
case "track":
return "audio";
default:
return undefined;
return "video";
}
}
}

0 comments on commit 16d18bb

Please sign in to comment.