Fix: Linter warnings (#137)

* Automaticly fixable eslint issues, mostly 3 -> 2 space indentation

* fix: updated plex_userid to camelcase

* Linted and some consistency refactor on middleware

* eslint uses ecmaversion 2020 & allow empty catch rule

* Started linting source files

* Fixed eslint errors & improved a lot of error handling

* Set 2 eslint rules as warning temporarly
This commit was merged in pull request #137.
This commit is contained in:
2022-08-20 17:21:25 +02:00
committed by GitHub
parent cfbd4965db
commit 1815a429b0
83 changed files with 1625 additions and 1294 deletions

View File

@@ -1,5 +1,19 @@
const fetch = require("node-fetch");
class TautulliUnexpectedError extends Error {
constructor(errorMessage) {
const message = "Unexpected error fetching from tautulli.";
super(message);
this.statusCode = 500;
this.errorMessage = errorMessage;
}
}
function logTautulliError(error) {
throw new TautulliUnexpectedError(error);
}
class Tautulli {
constructor(apiKey, ip, port) {
this.apiKey = apiKey;
@@ -7,67 +21,59 @@ class Tautulli {
this.port = port;
}
buildUrlWithCmdAndUserid(cmd, user_id) {
buildUrlWithCmdAndUserid(cmd, userId) {
const url = new URL("api/v2", `http://${this.ip}:${this.port}`);
url.searchParams.append("apikey", this.apiKey);
url.searchParams.append("cmd", cmd);
url.searchParams.append("user_id", user_id);
url.searchParams.append("user_id", userId);
return url;
}
logTautulliError(error) {
console.error("error fetching from tautulli");
throw error;
}
getPlaysByDayOfWeek(plex_userid, days, y_axis) {
getPlaysByDayOfWeek(plexUserId, days, yAxis) {
const url = this.buildUrlWithCmdAndUserid(
"get_plays_by_dayofweek",
plex_userid
plexUserId
);
url.searchParams.append("time_range", days);
url.searchParams.append("y_axis", y_axis);
url.searchParams.append("y_axis", yAxis);
return fetch(url.href)
.then(resp => resp.json())
.catch(error => this.logTautulliError(error));
.catch(error => logTautulliError(error));
}
getPlaysByDays(plex_userid, days, y_axis) {
const url = this.buildUrlWithCmdAndUserid("get_plays_by_date", plex_userid);
getPlaysByDays(plexUserId, days, yAxis) {
const url = this.buildUrlWithCmdAndUserid("get_plays_by_date", plexUserId);
url.searchParams.append("time_range", days);
url.searchParams.append("y_axis", y_axis);
url.searchParams.append("y_axis", yAxis);
return fetch(url.href)
.then(resp => resp.json())
.catch(error => this.logTautulliError(error));
.catch(error => logTautulliError(error));
}
watchTimeStats(plex_userid) {
watchTimeStats(plexUserId) {
const url = this.buildUrlWithCmdAndUserid(
"get_user_watch_time_stats",
plex_userid
plexUserId
);
url.searchParams.append("grouping", 0);
return fetch(url.href)
.then(resp => resp.json())
.catch(error => this.logTautulliError(error));
.catch(error => logTautulliError(error));
}
viewHistory(plex_userid) {
const url = this.buildUrlWithCmdAndUserid("get_history", plex_userid);
viewHistory(plexUserId) {
const url = this.buildUrlWithCmdAndUserid("get_history", plexUserId);
url.searchParams.append("start", 0);
url.searchParams.append("length", 50);
console.log("fetching url", url.href);
return fetch(url.href)
.then(resp => resp.json())
.catch(error => this.logTautulliError(error));
.catch(error => logTautulliError(error));
}
}