Fix: Tests lint and src folder #138
@@ -1,4 +1,3 @@
|
|||||||
const request = require("request");
|
|
||||||
const configuration = require("../config/configuration").getInstance();
|
const configuration = require("../config/configuration").getInstance();
|
||||||
|
|
||||||
class SMSUnexpectedError extends Error {
|
class SMSUnexpectedError extends Error {
|
||||||
@@ -20,23 +19,21 @@ const sendSMS = message => {
|
|||||||
|
|
||||||
const sender = configuration.get("sms", "sender");
|
const sender = configuration.get("sms", "sender");
|
||||||
const recipient = configuration.get("sms", "recipient");
|
const recipient = configuration.get("sms", "recipient");
|
||||||
|
const smsRequestHeaders = { "Content-Type": "application/json" };
|
||||||
|
const smsRequestBody = {
|
||||||
|
sender,
|
||||||
|
message,
|
||||||
|
recipients: [{ msisdn: `47${recipient}` }]
|
||||||
|
};
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
request.post(
|
fetch(`https://gatewayapi.com/rest/mtsms?token=${apiKey}`, {
|
||||||
{
|
body: JSON.stringify(smsRequestBody),
|
||||||
url: `https://gatewayapi.com/rest/mtsms?token=${apiKey}`,
|
headers: smsRequestHeaders
|
||||||
json: true,
|
})
|
||||||
body: {
|
.then(resp => resp.json())
|
||||||
sender,
|
.then(response => resolve(response))
|
||||||
message,
|
.catch(error => reject(new SMSUnexpectedError(error)));
|
||||||
recipients: [{ msisdn: `47${recipient}` }]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(err, r, body) => {
|
|
||||||
if (err) reject(new SMSUnexpectedError(err || body));
|
|
||||||
resolve(body);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
const fetch = require("node-fetch");
|
|
||||||
const convertPlexToMovie = require("./convertPlexToMovie");
|
const convertPlexToMovie = require("./convertPlexToMovie");
|
||||||
const convertPlexToShow = require("./convertPlexToShow");
|
const convertPlexToShow = require("./convertPlexToShow");
|
||||||
const convertPlexToEpisode = require("./convertPlexToEpisode");
|
const convertPlexToEpisode = require("./convertPlexToEpisode");
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
const rp = require("request-promise");
|
|
||||||
const convertPlexToSeasoned = require("./convertPlexToSeasoned");
|
const convertPlexToSeasoned = require("./convertPlexToSeasoned");
|
||||||
const convertPlexToStream = require("./convertPlexToStream");
|
const convertPlexToStream = require("./convertPlexToStream");
|
||||||
|
|
||||||
@@ -35,8 +34,9 @@ function mapResults(response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PlexRepository {
|
class PlexRepository {
|
||||||
constructor(plexIP) {
|
constructor(plexIP, plexToken) {
|
||||||
this.plexIP = plexIP;
|
this.plexIP = plexIP;
|
||||||
|
this.plexToken = plexToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
inPlex(_tmdbResult) {
|
inPlex(_tmdbResult) {
|
||||||
@@ -56,19 +56,17 @@ class PlexRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
search(query) {
|
search(query) {
|
||||||
const queryUri = encodeURIComponent(query);
|
const url = encodeURI(
|
||||||
const uri = encodeURI(
|
`http://${this.plexIP}:32400/search?query=${encodeURIComponent(
|
||||||
`http://${this.plexIP}:32400/search?query=${queryUri}`
|
query
|
||||||
|
)}&X-Plex-Token=${this.plexToken}`
|
||||||
);
|
);
|
||||||
const options = {
|
const options = {
|
||||||
uri,
|
headers: { Accept: "application/json" }
|
||||||
headers: {
|
|
||||||
Accept: "application/json"
|
|
||||||
},
|
|
||||||
json: true
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return rp(options)
|
return fetch(url, options)
|
||||||
|
.then(resp => resp.json())
|
||||||
.then(result => mapResults(result))
|
.then(result => mapResults(result))
|
||||||
.then(([mappedResults, resultCount]) => ({
|
.then(([mappedResults, resultCount]) => ({
|
||||||
results: mappedResults,
|
results: mappedResults,
|
||||||
@@ -77,15 +75,13 @@ class PlexRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nowPlaying() {
|
nowPlaying() {
|
||||||
|
const url = `http://${this.plexIP}:32400/status/sessions?X-Plex-Token=${this.plexToken}`;
|
||||||
const options = {
|
const options = {
|
||||||
uri: `http://${this.plexIP}:32400/status/sessions`,
|
headers: { Accept: "application/json" }
|
||||||
headers: {
|
|
||||||
Accept: "application/json"
|
|
||||||
},
|
|
||||||
json: true
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return rp(options)
|
return fetch(url, options)
|
||||||
|
.then(resp => resp.json())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.MediaContainer.size > 0) {
|
if (result.MediaContainer.size > 0) {
|
||||||
const playing =
|
const playing =
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ const configuration = require("../config/configuration").getInstance();
|
|||||||
const TMDB = require("../tmdb/tmdb");
|
const TMDB = require("../tmdb/tmdb");
|
||||||
const establishedDatabase = require("../database/database");
|
const establishedDatabase = require("../database/database");
|
||||||
|
|
||||||
const plexRepository = new PlexRepository(configuration.get("plex", "ip"));
|
const plexRepository = new PlexRepository(
|
||||||
|
configuration.get("plex", "ip"),
|
||||||
|
configuration.get("plex", "token")
|
||||||
|
);
|
||||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||||
|
|
||||||
class RequestRepository {
|
class RequestRepository {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
const fetch = require("node-fetch");
|
|
||||||
|
|
||||||
class TautulliUnexpectedError extends Error {
|
class TautulliUnexpectedError extends Error {
|
||||||
constructor(errorMessage) {
|
constructor(errorMessage) {
|
||||||
const message = "Unexpected error fetching from tautulli.";
|
const message = "Unexpected error fetching from tautulli.";
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
const PlexRepository = require("../../../plex/plexRepository");
|
const PlexRepository = require("../../../plex/plexRepository");
|
||||||
const configuration = require("../../../config/configuration").getInstance();
|
const configuration = require("../../../config/configuration").getInstance();
|
||||||
|
|
||||||
const plexRepository = new PlexRepository(configuration.get("plex", "ip"));
|
const plexRepository = new PlexRepository(
|
||||||
|
configuration.get("plex", "ip"),
|
||||||
|
configuration.get("plex", "token")
|
||||||
|
);
|
||||||
|
|
||||||
function playingController(req, res) {
|
function playingController(req, res) {
|
||||||
plexRepository
|
plexRepository
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
const PlexRepository = require("../../../plex/plexRepository");
|
const PlexRepository = require("../../../plex/plexRepository");
|
||||||
const configuration = require("../../../config/configuration").getInstance();
|
const configuration = require("../../../config/configuration").getInstance();
|
||||||
|
|
||||||
const plexRepository = new PlexRepository(configuration.get("plex", "ip"));
|
const plexRepository = new PlexRepository(
|
||||||
|
configuration.get("plex", "ip"),
|
||||||
|
configuration.get("plex", "token")
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller: Search for media and check existence
|
* Controller: Search for media and check existence
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ const app = require("./app");
|
|||||||
module.exports = app.listen(config.get("webserver", "port"), () => {
|
module.exports = app.listen(config.get("webserver", "port"), () => {
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
console.log("seasonedAPI");
|
console.log("seasonedAPI");
|
||||||
/* eslint-disable no-console */
|
|
||||||
console.log(`Database is located at ${config.get("database", "host")}`);
|
console.log(`Database is located at ${config.get("database", "host")}`);
|
||||||
/* eslint-disable no-console */
|
|
||||||
console.log(`Webserver is listening on ${config.get("webserver", "port")}`);
|
console.log(`Webserver is listening on ${config.get("webserver", "port")}`);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user