fix(plex): use server 'address' returned by Plex API (#1379)

pull/1379/merge
TheCatLady 4 years ago committed by GitHub
parent f2d7003969
commit 33542c9b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -200,9 +200,6 @@ components:
message: message:
type: string type: string
example: 'OK' example: 'OK'
host:
type: string
example: '127-0-0-1.2ab6ce1a093d465e910def96cf4e4799.plex.direct'
required: required:
- protocol - protocol
- address - address

@ -113,7 +113,6 @@ settingsRoutes.post('/plex', async (req, res, next) => {
settingsRoutes.get('/plex/devices/servers', async (req, res, next) => { settingsRoutes.get('/plex/devices/servers', async (req, res, next) => {
const userRepository = getRepository(User); const userRepository = getRepository(User);
const regexp = /(http(s?):\/\/)(.*)(:[0-9]*)/;
try { try {
const admin = await userRepository.findOneOrFail({ const admin = await userRepository.findOneOrFail({
select: ['id', 'plexToken'], select: ['id', 'plexToken'],
@ -126,18 +125,15 @@ settingsRoutes.get('/plex/devices/servers', async (req, res, next) => {
return device.provides.includes('server') && device.owned; return device.provides.includes('server') && device.owned;
}); });
const settings = getSettings(); const settings = getSettings();
if (devices) { if (devices) {
await Promise.all( await Promise.all(
devices.map(async (device) => { devices.map(async (device) => {
await Promise.all( await Promise.all(
device.connection.map(async (connection) => { device.connection.map(async (connection) => {
connection.host = connection.uri.replace(regexp, '$3');
let msg:
| { status: number; message: string }
| undefined = undefined;
const plexDeviceSettings = { const plexDeviceSettings = {
...settings.plex, ...settings.plex,
ip: connection.host, ip: connection.address,
port: connection.port, port: connection.port,
useSsl: connection.protocol === 'https' ? true : false, useSsl: connection.protocol === 'https' ? true : false,
}; };
@ -146,20 +142,15 @@ settingsRoutes.get('/plex/devices/servers', async (req, res, next) => {
plexSettings: plexDeviceSettings, plexSettings: plexDeviceSettings,
timeout: 5000, timeout: 5000,
}); });
try { try {
await plexClient.getStatus(); await plexClient.getStatus();
msg = { connection.status = 200;
status: 200, connection.message = 'OK';
message: 'OK',
};
} catch (e) { } catch (e) {
msg = { connection.status = 500;
status: 500, connection.message = e.message;
message: e.message,
};
} }
connection.status = msg?.status;
connection.message = msg?.message;
}) })
); );
}) })

Loading…
Cancel
Save