fix(plex): add support for plex.direct URLs (#1437)

* fix(plex): add support for plex.direct URLs

* fix(ui): mark HTTPS Plex connections as secure
pull/1450/head^2
TheCatLady 4 years ago committed by GitHub
parent 8fc71bea08
commit db077700e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,11 +4,13 @@ import fs from 'fs';
import { merge, omit } from 'lodash'; import { merge, omit } from 'lodash';
import path from 'path'; import path from 'path';
import { getRepository } from 'typeorm'; import { getRepository } from 'typeorm';
import { URL } from 'url';
import PlexAPI from '../../api/plexapi'; import PlexAPI from '../../api/plexapi';
import PlexTvAPI from '../../api/plextv'; import PlexTvAPI from '../../api/plextv';
import Media from '../../entity/Media'; import Media from '../../entity/Media';
import { MediaRequest } from '../../entity/MediaRequest'; import { MediaRequest } from '../../entity/MediaRequest';
import { User } from '../../entity/User'; import { User } from '../../entity/User';
import { PlexConnection } from '../../interfaces/api/plexInterfaces';
import { import {
LogMessage, LogMessage,
LogsResultsResponse, LogsResultsResponse,
@ -129,13 +131,32 @@ settingsRoutes.get('/plex/devices/servers', async (req, res, next) => {
if (devices) { if (devices) {
await Promise.all( await Promise.all(
devices.map(async (device) => { devices.map(async (device) => {
const plexDirectConnections: PlexConnection[] = [];
device.connection.forEach((connection) => {
const url = new URL(connection.uri);
if (url.hostname !== connection.address) {
const plexDirectConnection = { ...connection };
plexDirectConnection.address = url.hostname;
plexDirectConnections.push(plexDirectConnection);
// Connect to IP addresses over HTTP
connection.protocol = 'http';
}
});
plexDirectConnections.forEach((plexDirectConnection) => {
device.connection.push(plexDirectConnection);
});
await Promise.all( await Promise.all(
device.connection.map(async (connection) => { device.connection.map(async (connection) => {
const plexDeviceSettings = { const plexDeviceSettings = {
...settings.plex, ...settings.plex,
ip: connection.address, ip: connection.address,
port: connection.port, port: connection.port,
useSsl: !connection.local && connection.protocol === 'https', useSsl: connection.protocol === 'https',
}; };
const plexClient = new PlexAPI({ const plexClient = new PlexAPI({
plexToken: admin.plexToken, plexToken: admin.plexToken,
@ -149,7 +170,7 @@ settingsRoutes.get('/plex/devices/servers', async (req, res, next) => {
connection.message = 'OK'; connection.message = 'OK';
} catch (e) { } catch (e) {
connection.status = 500; connection.status = 500;
connection.message = e.message; connection.message = e.message.split(':')[0];
} }
}) })
); );

@ -1,6 +1,7 @@
import { RefreshIcon, SearchIcon, XIcon } from '@heroicons/react/solid'; import { RefreshIcon, SearchIcon, XIcon } from '@heroicons/react/solid';
import axios from 'axios'; import axios from 'axios';
import { Field, Formik } from 'formik'; import { Field, Formik } from 'formik';
import { orderBy } from 'lodash';
import React, { useMemo, useState } from 'react'; import React, { useMemo, useState } from 'react';
import { defineMessages, useIntl } from 'react-intl'; import { defineMessages, useIntl } from 'react-intl';
import { useToasts } from 'react-toast-notifications'; import { useToasts } from 'react-toast-notifications';
@ -28,7 +29,7 @@ const messages = defineMessages({
serverpresetPlaceholder: 'Plex Server', serverpresetPlaceholder: 'Plex Server',
serverLocal: 'local', serverLocal: 'local',
serverRemote: 'remote', serverRemote: 'remote',
serverConnected: 'connected', serverSecure: 'secure',
serverpresetManualMessage: 'Manual configuration', serverpresetManualMessage: 'Manual configuration',
serverpresetRefreshing: 'Retrieving servers…', serverpresetRefreshing: 'Retrieving servers…',
serverpresetLoad: 'Press the button to load available servers', serverpresetLoad: 'Press the button to load available servers',
@ -131,7 +132,7 @@ const SettingsPlex: React.FC<SettingsPlexProps> = ({ onComplete }) => {
dev.connection.forEach((conn) => dev.connection.forEach((conn) =>
finalPresets.push({ finalPresets.push({
name: dev.name, name: dev.name,
ssl: !conn.local && conn.protocol === 'https', ssl: conn.protocol === 'https',
uri: conn.uri, uri: conn.uri,
address: conn.address, address: conn.address,
port: conn.port, port: conn.port,
@ -141,14 +142,8 @@ const SettingsPlex: React.FC<SettingsPlexProps> = ({ onComplete }) => {
}) })
); );
}); });
finalPresets.sort((a, b) => {
if (a.status && !b.status) { return orderBy(finalPresets, ['status', 'ssl'], ['desc', 'desc']);
return -1;
} else {
return 1;
}
});
return finalPresets;
}, [availableServers]); }, [availableServers]);
const syncLibraries = async () => { const syncLibraries = async () => {
@ -420,7 +415,13 @@ const SettingsPlex: React.FC<SettingsPlexProps> = ({ onComplete }) => {
server.local server.local
? intl.formatMessage(messages.serverLocal) ? intl.formatMessage(messages.serverLocal)
: intl.formatMessage(messages.serverRemote) : intl.formatMessage(messages.serverRemote)
}] }]${
server.ssl
? ` [${intl.formatMessage(
messages.serverSecure
)}]`
: ''
}
${server.status ? '' : '(' + server.message + ')'} ${server.status ? '' : '(' + server.message + ')'}
`} `}
</option> </option>

@ -560,9 +560,9 @@
"components.Settings.regionTip": "Filter content by regional availability", "components.Settings.regionTip": "Filter content by regional availability",
"components.Settings.scan": "Sync Libraries", "components.Settings.scan": "Sync Libraries",
"components.Settings.scanning": "Syncing…", "components.Settings.scanning": "Syncing…",
"components.Settings.serverConnected": "connected",
"components.Settings.serverLocal": "local", "components.Settings.serverLocal": "local",
"components.Settings.serverRemote": "remote", "components.Settings.serverRemote": "remote",
"components.Settings.serverSecure": "secure",
"components.Settings.servername": "Server Name", "components.Settings.servername": "Server Name",
"components.Settings.servernamePlaceholder": "Plex Server Name", "components.Settings.servernamePlaceholder": "Plex Server Name",
"components.Settings.servernameTip": "Automatically retrieved from Plex after saving", "components.Settings.servernameTip": "Automatically retrieved from Plex after saving",

Loading…
Cancel
Save