Update: Move getting server ID into Plex class

pull/16/head
Juraj Nyíri 4 years ago
parent ce4254df14
commit ae5554529c

@ -18654,9 +18654,17 @@ var axios = axios_1;
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
class Plex { class Plex {
constructor(ip, port = 32400, token, protocol = 'http') { constructor(ip, port = 32400, token, protocol = 'http') {
this.serverInfo = {};
this.getServerID = async () => {
if (lodash.isEmpty(this.serverInfo)) {
await this.getServerInfo();
}
return this.serverInfo.machineIdentifier;
};
this.getServerInfo = async () => { this.getServerInfo = async () => {
const url = `${this.protocol}://${this.ip}:${this.port}/?X-Plex-Token=${this.token}`; const url = `${this.protocol}://${this.ip}:${this.port}/?X-Plex-Token=${this.token}`;
return (await axios.get(url)).data.MediaContainer; this.serverInfo = (await axios.get(url)).data.MediaContainer;
return this.serverInfo;
}; };
this.getSections = async () => { this.getSections = async () => {
const url = `${this.protocol}://${this.ip}:${this.port}/library/sections?X-Plex-Token=${this.token}`; const url = `${this.protocol}://${this.ip}:${this.port}/library/sections?X-Plex-Token=${this.token}`;
@ -19218,9 +19226,9 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.renderPage(); this.renderPage();
try { try {
if (this.plex) { if (this.plex) {
const [plexInfo, plexSections] = await Promise.all([this.plex.getServerInfo(), this.plex.getSectionsData()]); const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]);
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
this.data.serverID = plexInfo.machineIdentifier; this.data.serverID = serverID;
lodash.forEach(plexSections, section => { lodash.forEach(plexSections, section => {
this.data[section.title1] = section.Metadata; this.data[section.title1] = section.Metadata;
}); });

@ -11,6 +11,8 @@ class Plex {
protocol: string; protocol: string;
serverInfo: Record<string, any> = {};
constructor(ip: string, port = 32400, token: string, protocol: 'http' | 'https' = 'http') { constructor(ip: string, port = 32400, token: string, protocol: 'http' | 'https' = 'http') {
this.ip = ip; this.ip = ip;
this.port = port; this.port = port;
@ -18,9 +20,17 @@ class Plex {
this.protocol = protocol; this.protocol = protocol;
} }
getServerID = async (): Promise<any> => {
if (_.isEmpty(this.serverInfo)) {
await this.getServerInfo();
}
return this.serverInfo.machineIdentifier;
};
getServerInfo = async (): Promise<any> => { getServerInfo = async (): Promise<any> => {
const url = `${this.protocol}://${this.ip}:${this.port}/?X-Plex-Token=${this.token}`; const url = `${this.protocol}://${this.ip}:${this.port}/?X-Plex-Token=${this.token}`;
return (await axios.get(url)).data.MediaContainer; this.serverInfo = (await axios.get(url)).data.MediaContainer;
return this.serverInfo;
}; };
getSections = async (): Promise<any> => { getSections = async (): Promise<any> => {

@ -60,9 +60,9 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.renderPage(); this.renderPage();
try { try {
if (this.plex) { if (this.plex) {
const [plexInfo, plexSections] = await Promise.all([this.plex.getServerInfo(), this.plex.getSectionsData()]); const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]);
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
this.data.serverID = plexInfo.machineIdentifier; this.data.serverID = serverID;
_.forEach(plexSections, section => { _.forEach(plexSections, section => {
this.data[section.title1] = section.Metadata; this.data[section.title1] = section.Metadata;
}); });

Loading…
Cancel
Save