fix linting errors

This commit is contained in:
Karl Hudgell 2023-05-23 12:43:45 +01:00
parent ad10b48204
commit 70ee750e6b

View File

@ -6,7 +6,9 @@ import { httpProxy } from "utils/proxy/http";
import getServiceWidget from "utils/config/service-helpers"; import getServiceWidget from "utils/config/service-helpers";
import createLogger from "utils/logger"; import createLogger from "utils/logger";
import widgets from "widgets/widgets"; import widgets from "widgets/widgets";
const saltedMd5 = require('salted-md5'); const saltedMd5 = require('salted-md5');
const proxyName = "nextpvrProxyHandler"; const proxyName = "nextpvrProxyHandler";
const logger = createLogger(proxyName); const logger = createLogger(proxyName);
@ -51,25 +53,25 @@ async function loginToNextPVR(endpoint, widget) {
return [status, null]; return [status, null];
} }
// Create md5 hash of pin / salt to to md5 login // Create md5 hash of pin / salt to to md5 login
let hashedSalt = saltedMd5(':' + saltedMd5(widget.pin) + ':', dataAsJson.rsp.salt._text); const hashedSalt = saltedMd5(`:${saltedMd5(widget.pin)}:`, dataAsJson.rsp.salt._text);
endpoint = 'session.login&md5=' url = `${new URL(formatApiCall(api, { 'endpoint': 'session.login&md5=', 'url': widget.url }))}${hashedSalt}&sid=${dataAsJson.rsp.sid._text}`;
url = new URL(formatApiCall(api, { endpoint, ...widget })) + hashedSalt + '&sid=' + dataAsJson.rsp.sid._text;
[status, contentType, data] = await httpProxy(url); [status, contentType, data] = await httpProxy(url);
if (status !== 200) { if (status !== 200) {
logger.error("HTTP %d communicating with NextPVR. Data: %s", status, data.toString()); logger.error("HTTP %d communicating with NextPVR. Data: %s", status, contentType, data.toString());
return [status, data]; return [status, data];
} }
try { try {
const dataDecoded = xml2json(data.toString(), { compact: true }); const dataDecoded = xml2json(data.toString(), { compact: true });
let dataAsJson = JSON.parse(dataDecoded); dataAsJson = JSON.parse(dataDecoded);
// Store the session id globally // Store the session id globally
globalSid = dataAsJson.rsp.sid._text globalSid = dataAsJson.rsp.sid._text
} catch (e) { } catch (e) {
logger.error("Error decoding NextPVR API data. Data: %s", data.toString()); logger.error("Error decoding NextPVR API data. Data: %s", data.toString());
return [status, null]; return [status, null];
} }
console.log('gettingSID') logger.info('gettingSID')
return [status, true];
} }
@ -78,9 +80,7 @@ async function fetchFromNextPVRAPI(endpoint, widget, sid) {
if (!api) { if (!api) {
return [403, null]; return [403, null];
} }
const url = `${new URL(formatApiCall(api, { endpoint, ...widget }))}&sid=${sid}`
const url = new URL(formatApiCall(api, { endpoint, ...widget })) + '&sid=' + sid;
const [status, contentType, data] = await httpProxy(url); const [status, contentType, data] = await httpProxy(url);
if (status !== 200) { if (status !== 200) {
@ -101,7 +101,7 @@ export default async function nextPVRProxyHandler(req, res) {
const widget = await getWidget(req); const widget = await getWidget(req);
if (!globalSid) { if (!globalSid) {
await loginToNextPVR('session.initiate&ver=1.0&device=homepage', widget); await loginToNextPVR('session.initiate&ver=1.0&device=homepage', widget);
} }
if (!widget) { if (!widget) {
return res.status(400).json({ error: "Invalid proxy service type" }); return res.status(400).json({ error: "Invalid proxy service type" });
@ -114,9 +114,9 @@ export default async function nextPVRProxyHandler(req, res) {
if (status !== 200) { if (status !== 200) {
return res.status(status).json({ error: { message: "HTTP error communicating with NextPVR API", data: Buffer.from(apiData).toString() } }); return res.status(status).json({ error: { message: "HTTP error communicating with NextPVR API", data: Buffer.from(apiData).toString() } });
} }
let recordingCount let recordingCount
if (Array.isArray(apiData.rsp.recordings.recording) == false) { if (Array.isArray(apiData.rsp.recordings.recording) === false) {
if (apiData.rsp.recordings.recording) { if (apiData.rsp.recordings.recording) {
recordingCount = 1; recordingCount = 1;
} else { } else {
@ -132,7 +132,7 @@ export default async function nextPVRProxyHandler(req, res) {
return res.status(status).json({ error: { message: "HTTP error communicating with NextPVR API", data: Buffer.from(apiData).toString() } }); return res.status(status).json({ error: { message: "HTTP error communicating with NextPVR API", data: Buffer.from(apiData).toString() } });
} }
let readyCount let readyCount
if (Array.isArray(apiData.rsp.recordings.recording) == false) { if (Array.isArray(apiData.rsp.recordings.recording) === false) {
if (apiData.rsp.recordings.recording) { if (apiData.rsp.recordings.recording) {
readyCount = 1; readyCount = 1;
} else { } else {