Compare commits
1 Commits
master
...
feat/types
| Author | SHA1 | Date | |
|---|---|---|---|
| 379e025ab6 |
@@ -1,13 +1,22 @@
|
||||
{
|
||||
"root": true,
|
||||
"parserOptions": {
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"ecmaVersion": 2020,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"extends": ["eslint-config-airbnb-base", "plugin:prettier/recommended"],
|
||||
"plugins": ["mocha"],
|
||||
"extends": [
|
||||
"eslint-config-airbnb-base",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"plugins": ["mocha", "@typescript-eslint"],
|
||||
"rules": {
|
||||
"import/extensions": 0,
|
||||
"lines-between-class-members": [
|
||||
"error",
|
||||
"always",
|
||||
{ "exceptAfterSingleLine": true }
|
||||
],
|
||||
"max-classes-per-file": 1,
|
||||
"no-empty": [
|
||||
2,
|
||||
@@ -17,7 +26,8 @@
|
||||
],
|
||||
"no-promise-executor-return": 1,
|
||||
"no-shadow": "off",
|
||||
"no-underscore-dangle": "off"
|
||||
"no-underscore-dangle": "off",
|
||||
"@typescript-eslint/no-var-requires": "off"
|
||||
},
|
||||
"env": {
|
||||
"mocha": true
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"root": true,
|
||||
"parserOptions": {
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"extends": [
|
||||
"eslint-config-airbnb-base",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"rules": {
|
||||
"no-underscore-dangle": "off",
|
||||
"no-shadow": "off",
|
||||
"@typescript-eslint/no-shadow": ["error"]
|
||||
}
|
||||
}
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@ configurations/development.json
|
||||
configurations/production.json
|
||||
.env
|
||||
shows.db
|
||||
lib/
|
||||
|
||||
node_modules
|
||||
*/package-lock.json
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
FROM node:18
|
||||
LABEL org.opencontainers.image.source https://github.com/kevinmidboe/seasonedShows
|
||||
|
||||
RUN mkdir -p /opt/seasonedShows/src
|
||||
|
||||
@@ -18,3 +17,5 @@ RUN cp configurations/development.json.example configurations/production.json
|
||||
EXPOSE 31459
|
||||
|
||||
CMD ["yarn", "start"]
|
||||
|
||||
LABEL org.opencontainers.image.source https://github.com/kevinmidboe/seasoned
|
||||
|
||||
120
README.md
120
README.md
@@ -1,3 +1,4 @@
|
||||
|
||||
<h1 align="center">
|
||||
🌶 seasonedShows
|
||||
</h1>
|
||||
@@ -35,73 +36,63 @@
|
||||
</p>
|
||||
|
||||
## <a name="demo-documentation"></a> Demo & Documentation
|
||||
|
||||
📺 [DEMO](https://request.movie)
|
||||
📺 [DEMO](https://kevinmidboe.com/request)
|
||||
📝 Documentation of the api.
|
||||
💖 Checkout my [fancy vue.js page](https://github.com/KevinMidboe/seasoned) for interfacing the api.
|
||||
💖 Checkout my [fancy vue.js page](https://github.com/KevinMidboe/seasonedRequest) for interfacing the api.
|
||||
|
||||
## <a name="about"></a> About
|
||||
This is the backend api for [seasoned request] that allows for uesrs to request movies and shows by fetching movies from themoviedb api and checks them with your plex library to identify if a movie is already present or not. This api allows to search my query, get themoviedb movie lists like popular and now playing, all while checking if the item is already in your plex library. Your friends can create users to see what movies or shows they have requested and searched for.
|
||||
|
||||
This is the backend api for [seasoned request] that allows for uesrs to request movies and shows by fetching movies from themoviedb api and checks them with your plex library to identify if a movie is already present or not. This api allows to search my query, get themoviedb movie lists like popular and now playing, all while checking if the item is already in your plex library. Your friends can create users to see what movies or shows they have requested and searched for.
|
||||
|
||||
The api also uses torrent_search to search for matching torrents and returns results from any site or service available from torrent_search. As a admin of the site you can query torrent_search and return a magnet link that can be added to a autoadd folder of your favorite torrent client.
|
||||
The api also uses torrent_search to search for matching torrents and returns results from any site or service available from torrent_search. As a admin of the site you can query torrent_search and return a magnet link that can be added to a autoadd folder of your favorite torrent client.
|
||||
|
||||
## <a name="key-features"></a> Key features
|
||||
|
||||
### Code
|
||||
|
||||
- Uses [tmdb api](https://www.themoviedb.org/documentation/api) with over 350k movies and 70k tv shows
|
||||
- Written asynchronously
|
||||
- Uses caching for external requests
|
||||
- Test coverage
|
||||
- CI and dependency integrated
|
||||
- Use either config file or env_variables
|
||||
|
||||
- Uses [tmdb api](https://www.themoviedb.org/documentation/api) with over 350k movies and 70k tv shows
|
||||
- Written asynchronously
|
||||
- Uses caching for external requests
|
||||
- Test coverage
|
||||
- CI and dependency integrated
|
||||
- Use either config file or env_variables
|
||||
### Functionality
|
||||
|
||||
- Queries plex library to check if items exists
|
||||
- Create admin and normal user accounts
|
||||
- [torrent_search](https://github.com/KevinMidboe/torrent_search) to search for torrents
|
||||
- Fetch curated lists from tmdb
|
||||
- Queries plex library to check if items exists
|
||||
- Create admin and normal user accounts
|
||||
- [torrent_search](https://github.com/KevinMidboe/torrent_search) to search for torrents
|
||||
- Fetch curated lists from tmdb
|
||||
|
||||
## <a name="installation"></a> Installation
|
||||
|
||||
Before we can use seasonedShows we need to download node and a package manager. For instructions on how to install [yarn](https://yarnpkg.com/en/) or [npm](https://www.npmjs.com) package managers refer to [wiki: install package manager](https://github.com/KevinMidboe/seasonedShows/wiki/Install-package-manager). This api is written with express using node.js as the JavaScript runtime engine. To download node.js head over the the official [node.js download page](https://nodejs.org/en/download/).
|
||||
|
||||
### Install seasonedShows
|
||||
|
||||
After you have downloaded a package manager and node.js javascript engine, the following will guide you through how to download, install and run seasonedShows.
|
||||
|
||||
### macOS
|
||||
|
||||
- Open terminal
|
||||
- Install git. This can be done by running `xcode-select --install` in your favorite terminal.
|
||||
- Install a package manager, refer to this [wiki page] for yarn or [wiki page] for npm
|
||||
- Type: `git clone git@github.com:KevinMidboe/seasonedShows.git`
|
||||
- Type: `git clone --recurse-submodules git@github.com:KevinMidboe/seasonedShows.git`
|
||||
- Type: `cd seasonedShows/`
|
||||
- Install required packages
|
||||
- yarn: `yarn install`
|
||||
- npm: `npm install`
|
||||
* yarn: `yarn install`
|
||||
* npm: `npm install`
|
||||
- Start server:
|
||||
- yarn: `yarn start`
|
||||
- npm: `npm run start`
|
||||
* yarn: `yarn start`
|
||||
* npm: `npm run start`
|
||||
- seasonedShows will now be running at http://localhost:31459
|
||||
- To have seasonedShows run headless on startup, check out this wiki page to [install as a daemon].
|
||||
|
||||
### Linux
|
||||
|
||||
- Open terminal
|
||||
- Install git
|
||||
- Ubuntu/Debian: `sudo apt-get install git-core`
|
||||
- Fedora: `sudo yum install git`
|
||||
- Type: `git clone git@github.com:KevinMidboe/seasonedShows.git`
|
||||
* Ubuntu/Debian: `sudo apt-get install git-core`
|
||||
* Fedora: `sudo yum install git`
|
||||
- Type: `git clone --recurse-submodules git@github.com:KevinMidboe/seasonedShows.git`
|
||||
- Type: `cd seasonedShows/`
|
||||
- Install required packages
|
||||
- yarn: `yarn install`
|
||||
- npm: `npm install`
|
||||
* yarn: `yarn install`
|
||||
* npm: `npm install`
|
||||
- Start server:
|
||||
- yarn: `yarn start`
|
||||
- npm: `npm run start`
|
||||
* yarn: `yarn start`
|
||||
* npm: `npm run start`
|
||||
- seasonedShows will now be running at http://localhost:31459
|
||||
- To have seasonedShows run headless on startup, check out this wiki page to [install as a daemon].
|
||||
|
||||
@@ -110,73 +101,42 @@ After you have downloaded a package manager and node.js javascript engine, the f
|
||||
After you have installed the required packages you will have a node_modules directory with all the packages required in packages.json.
|
||||
|
||||
### Requirements
|
||||
- Node 7.6 < [wiki page]
|
||||
- Plex library
|
||||
|
||||
- Node 18 < [wiki page]
|
||||
- Plex library
|
||||
- Optional:
|
||||
- redis
|
||||
- deluge
|
||||
- jackett
|
||||
|
||||
## <a name="setup"></a> Setup and configuration
|
||||
|
||||
Make a copy of configuration file in `configurations/` folder.
|
||||
|
||||
For use during development and with `yarn dev` command:
|
||||
|
||||
```bash
|
||||
cp configurations/development.json.example configurations/development.json
|
||||
```
|
||||
|
||||
For use during production and with `yarn start` command:
|
||||
|
||||
```bash
|
||||
cp configurations/development.json.example configurations/production.json
|
||||
```
|
||||
|
||||
Most important values to change here is adding [TMDB api key](https://developers.themoviedb.org/3/getting-started/introduction) and plex server IP.
|
||||
|
||||
### Optional setup
|
||||
|
||||
To allow authenticated or admin users add items [delugeClient](https://github.com/kevinmidboe/delugeClient) & [torrentSearch](https://github.com/KevinMidboe/torrent_search) can be setup to fetch and add magnet files. Both require python version >= 3.8 and can be downloaded using following pip command:
|
||||
|
||||
```bash
|
||||
pip3 install delugeClient_kevin torrent_search
|
||||
```
|
||||
|
||||
Both of these need to be configured, view their separate README's or find configuration files under `$HOME/.config/`.
|
||||
## <a name="setup"></a> Setup and/ configuration
|
||||
There is a config file template, what the values mean and how to change them.
|
||||
Also show how to hide file from git if not want to show up as uncommitted file.
|
||||
Also set variables in environment.
|
||||
|
||||
## <a name="running"></a> Running/using
|
||||
|
||||
yarn/npm start. (can also say this above)
|
||||
How to create service on linux. This means that
|
||||
How to create service on linux. This means that
|
||||
|
||||
## <a name="daemon"></a> Setup a daemon
|
||||
|
||||
The next step is to setup seasonedShows api to run in the background as a daemon. I have written a [wiki page](https://github.com/KevinMidboe/seasonedShows/wiki/Install-as-a-daemon) on how to create a daemon on several unix distors and macOS.
|
||||
_Please don't hesitate to add your own system if you get it running on something that is not yet lists on the formentioned wiki page._
|
||||
*Please don't hesitate to add your own system if you get it running on something that is not yet lists on the formentioned wiki page.*
|
||||
|
||||
## <a name="contributing"></a> Contributing
|
||||
|
||||
- Fork it!
|
||||
- Create your feature branch: git checkout -b my-new-feature
|
||||
- Commit your changes: git commit -am 'Add some feature'
|
||||
- Push to the branch: git push origin my-new-feature
|
||||
- Submit a pull request
|
||||
|
||||
|
||||
## Api documentation
|
||||
|
||||
The goal of this project is to create a full custom stack that can to everything surround downloading, organizing and notifiyng of new media. From the top down we have a website using [tmdb](https://www.themoviedb.com) api to search for from over 350k movies and 70k tv shows. Using [hjone72](https://github.com/hjone72/PlexAuth) great PHP reverse proxy we can have a secure way of allowing users to login with their plex credentials which limits request capabilites to only users that are authenticated to use your plex library.
|
||||
seasonedShows is a intelligent organizer for your tv show episodes. It is made to automate and simplify to process of renaming and moving newly downloaded tv show episodes following Plex file naming and placement.
|
||||
|
||||
The goal of this project is to create a full custom stack that can to everything surround downloading, organizing and notifiyng of new media. From the top down we have a website using [tmdb](https://www.themoviedb.com) api to search for from over 350k movies and 70k tv shows. Using [hjone72](https://github.com/hjone72/PlexAuth) great PHP reverse proxy we can have a secure way of allowing users to login with their plex credentials which limits request capabilites to only users that are authenticated to use your plex library.
|
||||
seasonedShows is a intelligent organizer for your tv show episodes. It is made to automate and simplify to process of renaming and moving newly downloaded tv show episodes following Plex file naming and placement.
|
||||
|
||||
So this is a multipart system that lets your plex users request movies, and then from the admin page the owner can.
|
||||
|
||||
## Installation
|
||||
|
||||
There are two main ways of
|
||||
There are two main ways of
|
||||
|
||||
## Architecture
|
||||
|
||||
The flow of the system will first check for new folders in your tv shows directory, if a new file is found it's contents are analyzed, stored and tweets suggested changes to it's contents to use_admin.
|
||||
|
||||
Then there is a script for looking for replies on twitter by user_admin, if caanges are needed, it handles the changes specified and updates dtabbase.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"database": {
|
||||
"host": "./shows.db"
|
||||
"host": "../shows.db"
|
||||
},
|
||||
"redis": {
|
||||
"host": "localhost",
|
||||
|
||||
17
package.json
17
package.json
@@ -6,18 +6,19 @@
|
||||
"url": "https://www.opensource.org/licenses/mit-license.php"
|
||||
},
|
||||
"main": "webserver/server.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "SEASONED_CONFIG=configurations/production.json NODE_ENV=production node src/webserver/server.js",
|
||||
"start": "SEASONED_CONFIG=configurations/production.json NODE_ENV=production node lib/webserver/server.js",
|
||||
"dev": "SEASONED_CONFIG=configurations/development.json NODE_ENV=development node src/webserver/server.js",
|
||||
"test": "SEASONED_CONFIG=configurations/test.json mocha --recursive tests/unit tests/system",
|
||||
"build": "yarn tsc",
|
||||
"coverage:upload": "SEASONED_CONFIG=configurations/test.json mocha --recursive tests/unit && nyc report --reporter=text-lcov | coveralls",
|
||||
"coverage": "SEASONED_CONFIG=configurations/test.json mocha --recursive tests/unit && nyc report",
|
||||
"lint": "eslint src tests",
|
||||
"update": "SEASONED_CONFIG=configurations/development.json node scripts/updateRequestsInPlex.js",
|
||||
"update": "SEASONED_CONFIG=configurations/production.json node scripts/updateRequestsInPlex.js",
|
||||
"docs": "yarn apiDocs; yarn classDocs",
|
||||
"apiDocs": "",
|
||||
"classDocs": "scripts/generate-class-docs.sh"
|
||||
"classDocs": "scripts/generate-class-docs.sh",
|
||||
"postbuild": "cp -r src/database/schemas lib/database"
|
||||
},
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.0.1",
|
||||
@@ -27,15 +28,19 @@
|
||||
"form-data": "^2.5.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"km-moviedb": "^0.2.12",
|
||||
"python-shell": "^0.5.0",
|
||||
"raven": "^2.4.2",
|
||||
"redis": "^3.0.2",
|
||||
"sqlite3": "^5.0.1"
|
||||
"sqlite3": "^5.0.1",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.5.5",
|
||||
"@babel/preset-env": "^7.5.5",
|
||||
"@babel/register": "^7.5.5",
|
||||
"@types/node": "^12.6.8",
|
||||
"@types/node": "^18.7.8",
|
||||
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
||||
"@typescript-eslint/parser": "^5.33.1",
|
||||
"chai": "^4.3.6",
|
||||
"chai-http": "^4.3.0",
|
||||
"coveralls": "^3.0.5",
|
||||
|
||||
@@ -1,41 +1,44 @@
|
||||
import Plex from "../src/plex/plex.js";
|
||||
import establishedDatabase from "../src/database/database.js";
|
||||
import Configuration from "../src/config/configuration.js";
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const plex = new Plex(
|
||||
configuration.get("plex", "ip"),
|
||||
configuration.get("plex", "token")
|
||||
);
|
||||
const Plex = require("src/plex/plex");
|
||||
const configuration = require("src/config/configuration").getInstance();
|
||||
const plex = new Plex(configuration.get("plex", "ip"));
|
||||
const establishedDatabase = require("src/database/database");
|
||||
|
||||
const queries = {
|
||||
getRequestsNotYetInPlex: `SELECT * FROM requests WHERE status = 'requested' OR status = 'downloading'`,
|
||||
saveNewStatus: `UPDATE requests SET status = ? WHERE id IS ? and type IS ?`
|
||||
};
|
||||
|
||||
const getRequestsNotYetInPlex = () =>
|
||||
const getByStatus = () =>
|
||||
establishedDatabase.all(queries.getRequestsNotYetInPlex);
|
||||
|
||||
async function getNewRequestMatchesInPlex() {
|
||||
const requests = await getRequestsNotYetInPlex();
|
||||
const exists = await Promise.all(
|
||||
requests.map(request => plex.existsInPlex(request))
|
||||
);
|
||||
const checkIfRequestExistInPlex = async request => {
|
||||
request.existsInPlex = await plex.existsInPlex(request);
|
||||
return request;
|
||||
};
|
||||
|
||||
return requests.filter(() => exists.shift());
|
||||
}
|
||||
|
||||
function commitNewStatus(status, id, type, title) {
|
||||
console.log(`${type} ${title} updated to: ${status}`);
|
||||
const commitNewStatus = (status, id, type, title) => {
|
||||
console.log(type, title, "updated to:", status);
|
||||
return establishedDatabase.run(queries.saveNewStatus, [status, id, type]);
|
||||
}
|
||||
};
|
||||
|
||||
function updateMatchInDb(match, status) {
|
||||
const getNewRequestMatchesInPlex = async () => {
|
||||
const requests = await getByStatus();
|
||||
|
||||
return Promise.all(requests.map(checkIfRequestExistInPlex))
|
||||
.catch(error =>
|
||||
console.log("error from checking plex for existance:", error)
|
||||
)
|
||||
.then(matchedRequests =>
|
||||
matchedRequests.filter(request => request.existsInPlex)
|
||||
);
|
||||
};
|
||||
|
||||
const updateMatchInDb = (match, status) => {
|
||||
return commitNewStatus(status, match.id, match.type, match.title);
|
||||
}
|
||||
};
|
||||
|
||||
getNewRequestMatchesInPlex()
|
||||
.then(newMatches =>
|
||||
Promise.all(newMatches.map(match => updateMatchInDb(match, "downloaded")))
|
||||
)
|
||||
.finally(() => process.exit(0));
|
||||
.then(() => process.exit(0));
|
||||
|
||||
29
src/cache/redis.js
vendored
29
src/cache/redis.js
vendored
@@ -1,11 +1,10 @@
|
||||
import redis from "redis";
|
||||
import Configuration from "../config/configuration.js";
|
||||
import redisMockClient from "./redisMock.js";
|
||||
const configuration = require("../config/configuration").getInstance();
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
let client;
|
||||
const mockCache = {};
|
||||
|
||||
try {
|
||||
const redis = require("redis"); // eslint-disable-line global-require
|
||||
console.log("Trying to connect with redis.."); // eslint-disable-line no-console
|
||||
const host = configuration.get("redis", "host");
|
||||
const port = configuration.get("redis", "port");
|
||||
@@ -20,7 +19,21 @@ try {
|
||||
client.quit();
|
||||
console.error("Unable to connect to redis, setting up redis-mock."); // eslint-disable-line no-console
|
||||
|
||||
client = redisMockClient;
|
||||
client = {
|
||||
get(key, callback) {
|
||||
console.log(`redis-dummy get: ${key}`); // eslint-disable-line no-console
|
||||
const hit = mockCache[key];
|
||||
return Promise.resolve().then(callback(null, hit));
|
||||
},
|
||||
set(key, json, callback) {
|
||||
console.log(`redis-dummy set: ${key}`); // eslint-disable-line no-console
|
||||
mockCache[key] = JSON.stringify(json);
|
||||
return Promise.resolve().then(callback(null, "OK"));
|
||||
},
|
||||
expire(key, TTL) {
|
||||
console.log(`redis-dummy expire: ${key} with TTL ${TTL}`); // eslint-disable-line no-console
|
||||
}
|
||||
};
|
||||
});
|
||||
} catch (e) {}
|
||||
|
||||
@@ -59,7 +72,7 @@ function get(key) {
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
set,
|
||||
get
|
||||
module.exports = {
|
||||
get,
|
||||
set
|
||||
};
|
||||
|
||||
19
src/cache/redisMock.js
vendored
19
src/cache/redisMock.js
vendored
@@ -1,19 +0,0 @@
|
||||
const mockCache = {};
|
||||
|
||||
const redisMockClient = {
|
||||
get(key, callback) {
|
||||
// console.log(`redis-dummy get: ${key}`); // eslint-disable-line no-console
|
||||
const hit = mockCache[key] || null;
|
||||
return Promise.resolve(callback(null, hit));
|
||||
},
|
||||
set(key, json, callback) {
|
||||
// console.log(`redis-dummy set: ${key}`); // eslint-disable-line no-console
|
||||
mockCache[key] = JSON.stringify(json);
|
||||
return Promise.resolve(callback(null, "OK"));
|
||||
},
|
||||
expire(key, TTL) {
|
||||
console.log(`redis-dummy expire: ${key} with TTL ${TTL}`); // eslint-disable-line no-console
|
||||
}
|
||||
};
|
||||
|
||||
export default redisMockClient;
|
||||
@@ -1,17 +1,13 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import Field from "./field.js";
|
||||
const path = require("path");
|
||||
const Field = require("./field");
|
||||
|
||||
let instance = null;
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
class Config {
|
||||
constructor() {
|
||||
this.location = Config.determineLocation();
|
||||
this.fields = Config.readFileContents(this.location);
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
this.fields = require(`${this.location}`);
|
||||
}
|
||||
|
||||
static getInstance() {
|
||||
@@ -25,17 +21,6 @@ class Config {
|
||||
return path.join(__dirname, "..", "..", process.env.SEASONED_CONFIG);
|
||||
}
|
||||
|
||||
static readFileContents(location) {
|
||||
let content = {};
|
||||
try {
|
||||
content = JSON.parse(fs.readFileSync(location, { encoding: "utf-8" }));
|
||||
} catch (err) {
|
||||
console.error(`Error loading configuration file at path: ${location}`);
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
get(section, option) {
|
||||
if (
|
||||
this.fields[section] === undefined ||
|
||||
@@ -60,4 +45,4 @@ class Config {
|
||||
}
|
||||
}
|
||||
|
||||
export default Config;
|
||||
module.exports = Config;
|
||||
|
||||
@@ -12,4 +12,4 @@ class EnvironmentVariables {
|
||||
}
|
||||
}
|
||||
|
||||
export default EnvironmentVariables;
|
||||
module.exports = EnvironmentVariables;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Filters from "./filters.js";
|
||||
import EnvironmentVariables from "./environmentVariables.js";
|
||||
const Filters = require("./filters");
|
||||
const EnvironmentVariables = require("./environmentVariables");
|
||||
|
||||
class Field {
|
||||
constructor(rawValue, environmentVariables) {
|
||||
@@ -50,4 +50,4 @@ class Field {
|
||||
}
|
||||
}
|
||||
|
||||
export default Field;
|
||||
module.exports = Field;
|
||||
|
||||
@@ -31,4 +31,4 @@ class Filters {
|
||||
}
|
||||
}
|
||||
|
||||
export default Filters;
|
||||
module.exports = Filters;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import SqliteDatabase from "./sqliteDatabase.js";
|
||||
import Configuration from "../config/configuration.js";
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const configuration = require("../config/configuration").getInstance();
|
||||
const SqliteDatabase = require("./sqliteDatabase");
|
||||
|
||||
const database = new SqliteDatabase(configuration.get("database", "host"));
|
||||
/**
|
||||
@@ -12,4 +10,4 @@ const database = new SqliteDatabase(configuration.get("database", "host"));
|
||||
*/
|
||||
Promise.resolve().then(() => database.setUp());
|
||||
|
||||
export default database;
|
||||
module.exports = database;
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import sqlite3 from "sqlite3";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const sqlite3 = require("sqlite3").verbose();
|
||||
|
||||
class SqliteDatabase {
|
||||
constructor(host) {
|
||||
@@ -119,4 +115,4 @@ class SqliteDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
export default SqliteDatabase;
|
||||
module.exports = SqliteDatabase;
|
||||
|
||||
@@ -5,4 +5,4 @@ class GitRepository {
|
||||
}
|
||||
}
|
||||
|
||||
export default GitRepository;
|
||||
module.exports = GitRepository;
|
||||
|
||||
@@ -15,4 +15,4 @@ class Media {
|
||||
}
|
||||
}
|
||||
|
||||
export default Media;
|
||||
module.exports = Media;
|
||||
|
||||
@@ -12,4 +12,4 @@ class MediaInfo {
|
||||
}
|
||||
}
|
||||
|
||||
export default MediaInfo;
|
||||
module.exports = MediaInfo;
|
||||
|
||||
@@ -9,4 +9,4 @@ class Player {
|
||||
}
|
||||
}
|
||||
|
||||
export default Player;
|
||||
module.exports = Player;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import Media from "./media.js";
|
||||
const Media = require("./media");
|
||||
|
||||
class Plex extends Media {
|
||||
constructor(
|
||||
@@ -30,4 +30,4 @@ class Plex extends Media {
|
||||
}
|
||||
}
|
||||
|
||||
export default Plex;
|
||||
module.exports = Plex;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* eslint-disable camelcase */
|
||||
import Media from "./media.js";
|
||||
|
||||
const Media = require("./media");
|
||||
|
||||
class TMDB extends Media {
|
||||
// constructor(...args) {
|
||||
@@ -44,4 +45,4 @@ class TMDB extends Media {
|
||||
}
|
||||
}
|
||||
|
||||
export default TMDB;
|
||||
module.exports = TMDB;
|
||||
|
||||
@@ -5,4 +5,4 @@ class User {
|
||||
}
|
||||
}
|
||||
|
||||
export default User;
|
||||
module.exports = User;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import Configuration from "../config/configuration.js";
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const configuration = require("../config/configuration").getInstance();
|
||||
|
||||
class SMSUnexpectedError extends Error {
|
||||
constructor(errorMessage) {
|
||||
@@ -11,7 +9,7 @@ class SMSUnexpectedError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export default function sendSMS(message) {
|
||||
const sendSMS = message => {
|
||||
const apiKey = configuration.get("sms", "apikey");
|
||||
|
||||
if (!apiKey) {
|
||||
@@ -37,4 +35,6 @@ export default function sendSMS(message) {
|
||||
.then(response => resolve(response))
|
||||
.catch(error => reject(new SMSUnexpectedError(error)));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { sendSMS };
|
||||
|
||||
@@ -1,124 +1,52 @@
|
||||
import http from "http";
|
||||
import { URL } from "url";
|
||||
import { spawn } from "child_process";
|
||||
const http = require("http");
|
||||
const { URL } = require("url");
|
||||
const PythonShell = require("python-shell");
|
||||
|
||||
import establishedDatabase from "../database/database.js";
|
||||
import cache from "../cache/redis.js";
|
||||
const establishedDatabase = require("../database/database");
|
||||
|
||||
class SearchPackageNotFoundError extends Error {
|
||||
constructor() {
|
||||
const message = "Search is not setup, view logs.";
|
||||
super(message);
|
||||
|
||||
const warningMessage = `Warning! Package 'torrentSearch' not setup! View project README.`;
|
||||
console.log(warningMessage); /* eslint-disable-line no-console */
|
||||
}
|
||||
}
|
||||
|
||||
class AddMagnetPackageNotFoundError extends Error {
|
||||
constructor() {
|
||||
const message = "Adding magnet is not setup, view logs.";
|
||||
super(message);
|
||||
|
||||
const warningMessage = `Warning! Package 'delugeClient' not setup! View project README.`;
|
||||
console.log(warningMessage); /* eslint-disable-line no-console */
|
||||
}
|
||||
}
|
||||
|
||||
class InvalidMagnetUrlError extends Error {
|
||||
constructor() {
|
||||
const message = "Invalid magnet url.";
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
class UnexpectedScriptError extends Error {
|
||||
constructor(_package, error = null) {
|
||||
const message = `There was an unexpected error while running package: ${_package}`;
|
||||
super(message);
|
||||
this.error = error;
|
||||
|
||||
// console.log("Unexpected script error:", error);
|
||||
}
|
||||
}
|
||||
const cache = require("../cache/redis");
|
||||
|
||||
function getMagnetFromURL(url) {
|
||||
const options = new URL(url);
|
||||
if (options?.protocol?.includes("magnet")) return Promise.resolve(url);
|
||||
return new Promise(resolve => {
|
||||
const options = new URL(url);
|
||||
if (options.protocol.includes("magnet")) resolve(url);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(options, res => {
|
||||
if (res.statusCode !== 301 && res.statusCode !== 302)
|
||||
reject(new InvalidMagnetUrlError());
|
||||
if (!res?.headers?.location?.includes("magnet"))
|
||||
reject(new InvalidMagnetUrlError());
|
||||
|
||||
return resolve(res.headers.location);
|
||||
if (res.statusCode === 301 || res.statusCode === 302) {
|
||||
resolve(res.headers.location);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function removeNewLineListItem(list) {
|
||||
return list.map(el => el.replace("\n", "")).filter(el => el.length !== 0);
|
||||
async function find(searchterm, callback) {
|
||||
const options = {
|
||||
pythonPath: "../torrent_search/env/bin/python3",
|
||||
scriptPath: "../torrent_search",
|
||||
args: [searchterm, "-s", "jackett", "--print"]
|
||||
};
|
||||
|
||||
PythonShell.run("torrentSearch/search.py", options, callback);
|
||||
// PythonShell does not support return
|
||||
}
|
||||
|
||||
function decodeBufferListToString(bufferList) {
|
||||
let data = bufferList.map(bufferElement => bufferElement.toString());
|
||||
if (data.length === 0) return null;
|
||||
async function callPythonAddMagnet(url, callback) {
|
||||
getMagnetFromURL(url)
|
||||
.then(magnet => {
|
||||
const options = {
|
||||
pythonPath: "../delugeClient/env/bin/python3",
|
||||
scriptPath: "../delugeClient",
|
||||
args: ["add", magnet]
|
||||
};
|
||||
|
||||
data = removeNewLineListItem(data);
|
||||
return data.join("");
|
||||
PythonShell.run("deluge_cli.py", options, callback);
|
||||
})
|
||||
.catch(err => {
|
||||
throw new Error(err);
|
||||
});
|
||||
}
|
||||
|
||||
function addMagnetScript(magnet, callback) {
|
||||
const data = [];
|
||||
let error = null;
|
||||
const args = ["add", magnet];
|
||||
|
||||
const addMagnet = spawn("delugeclient", args);
|
||||
|
||||
addMagnet.stdout.on("data", bufferedData => data.push(bufferedData));
|
||||
addMagnet.stderr.on("data", bufferedError => {
|
||||
error = bufferedError.toString();
|
||||
});
|
||||
|
||||
addMagnet.on("exit", () => callback(error, decodeBufferListToString(data)));
|
||||
addMagnet.on("error", error => {
|
||||
callback(error);
|
||||
});
|
||||
}
|
||||
|
||||
function handleAddMagnetScriptError(error) {
|
||||
if (error?.code === "ENOENT") return new AddMagnetPackageNotFoundError();
|
||||
|
||||
return new UnexpectedScriptError("delugeClient", error);
|
||||
}
|
||||
|
||||
function searchScript(searchterm, callback) {
|
||||
const data = [];
|
||||
let error = null;
|
||||
const args = [searchterm, "-s", "jackett", "--print"];
|
||||
|
||||
const torrentSearch = spawn("torrentsearch", args);
|
||||
|
||||
torrentSearch.stdout.on("data", bufferedData => data.push(bufferedData));
|
||||
torrentSearch.stderr.on("data", bufferedError => {
|
||||
error = bufferedError.toString();
|
||||
});
|
||||
|
||||
torrentSearch.on("exit", () =>
|
||||
callback(error, decodeBufferListToString(data))
|
||||
);
|
||||
torrentSearch.on("error", error => callback(error));
|
||||
}
|
||||
|
||||
function handleSearchScriptError(error) {
|
||||
if (error?.code === "ENOENT") return new SearchPackageNotFoundError();
|
||||
|
||||
return new UnexpectedScriptError("torrentSearch", error);
|
||||
}
|
||||
|
||||
export async function SearchPiratebay(_query) {
|
||||
async function SearchPiratebay(_query) {
|
||||
let query = String(_query);
|
||||
|
||||
if (query?.includes("+")) {
|
||||
@@ -126,46 +54,49 @@ export async function SearchPiratebay(_query) {
|
||||
}
|
||||
|
||||
const cacheKey = `pirate/${query}`;
|
||||
try {
|
||||
const hit = await cache.get(cacheKey);
|
||||
|
||||
if (hit) {
|
||||
return Promise.resolve(hit);
|
||||
}
|
||||
} catch (_) {}
|
||||
return new Promise((resolve, reject) =>
|
||||
cache
|
||||
.get(cacheKey)
|
||||
.then(resolve)
|
||||
.catch(() =>
|
||||
find(query, (err, results) => {
|
||||
if (err) {
|
||||
console.log("THERE WAS A FUCKING ERROR!\n", err); // eslint-disable-line no-console
|
||||
reject(Error("There was a error when searching for torrents"));
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
searchScript(query, (error, results) => {
|
||||
if (error || !results) return reject(handleSearchScriptError(error));
|
||||
|
||||
const jsonData = JSON.parse(results, null, "\t");
|
||||
cache.set(cacheKey, jsonData);
|
||||
return resolve(jsonData);
|
||||
});
|
||||
});
|
||||
if (results) {
|
||||
const jsonData = JSON.parse(results[1], null, "\t");
|
||||
cache.set(cacheKey, jsonData);
|
||||
resolve(jsonData);
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export async function AddMagnet(magnetUrl, name, tmdbId) {
|
||||
const magnet = await getMagnetFromURL(magnetUrl);
|
||||
const insertRequestedMagnetQuery =
|
||||
"INSERT INTO requested_torrent(magnet, torrent_name, tmdb_id) VALUES (?,?,?)";
|
||||
function AddMagnet(magnet, name, tmdbId) {
|
||||
return new Promise((resolve, reject) =>
|
||||
callPythonAddMagnet(magnet, (err, results) => {
|
||||
if (err) {
|
||||
/* eslint-disable no-console */
|
||||
console.log(err);
|
||||
reject(Error("Enable to add torrent", err));
|
||||
}
|
||||
/* eslint-disable no-console */
|
||||
console.log("result/error:", err, results);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
addMagnetScript(magnet, (error, result) => {
|
||||
if (error || !result) return reject(handleAddMagnetScriptError(error));
|
||||
|
||||
const magnetHash = result; // TODO save to database
|
||||
const database = establishedDatabase;
|
||||
return database
|
||||
.run(insertRequestedMagnetQuery, [magnet, name, tmdbId])
|
||||
.catch(error => reject(error))
|
||||
.then(() =>
|
||||
resolve({
|
||||
success: true,
|
||||
message: "Successfully added magnet",
|
||||
hash: magnetHash
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
const insertQuery =
|
||||
"INSERT INTO requested_torrent(magnet,torrent_name,tmdb_id) VALUES (?,?,?)";
|
||||
|
||||
const response = database.run(insertQuery, [magnet, name, tmdbId]);
|
||||
console.log(`Response from requsted_torrent insert: ${response}`);
|
||||
|
||||
resolve({ success: true });
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = { SearchPiratebay, AddMagnet };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Episode from "./types/episode.js";
|
||||
const Episode = require("./types/episode");
|
||||
|
||||
function convertPlexToEpisode(plexEpisode) {
|
||||
const episode = new Episode(
|
||||
@@ -21,5 +21,4 @@ function convertPlexToEpisode(plexEpisode) {
|
||||
|
||||
return episode;
|
||||
}
|
||||
|
||||
export default convertPlexToEpisode;
|
||||
module.exports = convertPlexToEpisode;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Movie from "./types/movie.js";
|
||||
const Movie = require("./types/movie");
|
||||
|
||||
function convertPlexToMovie(plexMovie) {
|
||||
const movie = new Movie(plexMovie.title, plexMovie.year);
|
||||
@@ -12,4 +12,4 @@ function convertPlexToMovie(plexMovie) {
|
||||
return movie;
|
||||
}
|
||||
|
||||
export default convertPlexToMovie;
|
||||
module.exports = convertPlexToMovie;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import Plex from "../media_classes/plex.js";
|
||||
const Plex = require("../media_classes/plex");
|
||||
|
||||
function translateAdded(date_string) {
|
||||
return new Date(date_string * 1000);
|
||||
@@ -32,4 +32,4 @@ function convertPlexToSeasoned(plex) {
|
||||
return seasoned;
|
||||
}
|
||||
|
||||
export default convertPlexToSeasoned;
|
||||
module.exports = convertPlexToSeasoned;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Show from "./types/show.js";
|
||||
const Show = require("./types/show");
|
||||
|
||||
function convertPlexToShow(plexShow) {
|
||||
const show = new Show(plexShow.title, plexShow.year);
|
||||
@@ -10,4 +10,4 @@ function convertPlexToShow(plexShow) {
|
||||
return show;
|
||||
}
|
||||
|
||||
export default convertPlexToShow;
|
||||
module.exports = convertPlexToShow;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import convertPlexToSeasoned from "./convertPlexToSeasoned.js";
|
||||
import convertStreamToMediaInfo from "./convertStreamToMediaInfo.js";
|
||||
import convertStreamToPlayer from "./stream/convertStreamToPlayer.js";
|
||||
import convertStreamToUser from "./stream/convertStreamToUser.js";
|
||||
import ConvertStreamToPlayback from "./stream/convertStreamToPlayback.js";
|
||||
const convertPlexToSeasoned = require("./convertPlexToSeasoned");
|
||||
const convertStreamToMediaInfo = require("./convertStreamToMediaInfo");
|
||||
const convertStreamToPlayer = require("./stream/convertStreamToPlayer");
|
||||
const convertStreamToUser = require("./stream/convertStreamToUser");
|
||||
const ConvertStreamToPlayback = require("./stream/convertStreamToPlayback");
|
||||
|
||||
function convertPlexToStream(plexStream) {
|
||||
const stream = convertPlexToSeasoned(plexStream);
|
||||
@@ -16,4 +16,4 @@ function convertPlexToStream(plexStream) {
|
||||
return stream;
|
||||
}
|
||||
|
||||
export default convertPlexToStream;
|
||||
module.exports = convertPlexToStream;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import MediaInfo from "../media_classes/mediaInfo.js";
|
||||
const MediaInfo = require("../media_classes/mediaInfo");
|
||||
|
||||
function convertStreamToMediaInfo(plexStream) {
|
||||
const mediaInfo = new MediaInfo();
|
||||
@@ -19,4 +19,4 @@ function convertStreamToMediaInfo(plexStream) {
|
||||
return mediaInfo;
|
||||
}
|
||||
|
||||
export default convertStreamToMediaInfo;
|
||||
module.exports = convertStreamToMediaInfo;
|
||||
|
||||
@@ -22,4 +22,4 @@ class mailTemplate {
|
||||
}
|
||||
}
|
||||
|
||||
export default mailTemplate;
|
||||
module.exports = mailTemplate;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import convertPlexToMovie from "./convertPlexToMovie.js";
|
||||
import convertPlexToShow from "./convertPlexToShow.js";
|
||||
import convertPlexToEpisode from "./convertPlexToEpisode.js";
|
||||
import redisCache from "../cache/redis.js";
|
||||
const convertPlexToMovie = require("./convertPlexToMovie");
|
||||
const convertPlexToShow = require("./convertPlexToShow");
|
||||
const convertPlexToEpisode = require("./convertPlexToEpisode");
|
||||
const redisCache = require("../cache/redis");
|
||||
|
||||
class PlexRequestTimeoutError extends Error {
|
||||
constructor() {
|
||||
@@ -97,9 +97,8 @@ function mapResults(response) {
|
||||
}
|
||||
|
||||
class Plex {
|
||||
constructor(ip, token, port = 32400, cache = null) {
|
||||
constructor(ip, port = 32400, cache = null) {
|
||||
this.plexIP = ip;
|
||||
this.token = token;
|
||||
this.plexPort = port;
|
||||
|
||||
this.cache = cache || redisCache;
|
||||
@@ -117,7 +116,7 @@ class Plex {
|
||||
headers: { Accept: "application/json" }
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
this.cache
|
||||
.get(cacheKey)
|
||||
.then(machineInfo => resolve(machineInfo?.machineIdentifier))
|
||||
@@ -133,8 +132,8 @@ class Plex {
|
||||
}
|
||||
|
||||
reject(new PlexUnexpectedError());
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async existsInPlex(tmdb) {
|
||||
@@ -186,24 +185,18 @@ class Plex {
|
||||
|
||||
const url = `http://${this.plexIP}:${
|
||||
this.plexPort
|
||||
}/hubs/search?query=${fixedEncodeURIComponent(query)}&X-Plex-Token=${
|
||||
this.token
|
||||
}`;
|
||||
|
||||
}/hubs/search?query=${fixedEncodeURIComponent(query)}`;
|
||||
const options = {
|
||||
timeout: 20000,
|
||||
headers: { Accept: "application/json" }
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
this.cache
|
||||
.get(cacheKey)
|
||||
.catch(() => {
|
||||
// else fetch fresh data
|
||||
return fetch(url, options)
|
||||
.then(successfullResponse)
|
||||
.then(results => this.cache.set(cacheKey, results, 21600)); // 6 hours
|
||||
})
|
||||
.catch(() => fetch(url, options)) // else fetch fresh data
|
||||
.then(successfullResponse)
|
||||
.then(results => this.cache.set(cacheKey, results, 21600)) // 6 hours
|
||||
.then(mapResults)
|
||||
.then(resolve)
|
||||
.catch(error => {
|
||||
@@ -212,8 +205,8 @@ class Plex {
|
||||
}
|
||||
|
||||
reject(new PlexUnexpectedError());
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// this is not guarenteed to work, but if we see a movie or
|
||||
@@ -228,10 +221,10 @@ class Plex {
|
||||
// TODO improve cache key matching by lowercasing it on the backend.
|
||||
// what do we actually need to check for if the key was deleted or not
|
||||
// it might be an error or another response code.
|
||||
console.log("Unable to delete, key might not exists"); // eslint-disable-line no-console
|
||||
console.log("Unable to delete, key might not exists");
|
||||
return response === 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default Plex;
|
||||
module.exports = Plex;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import convertPlexToSeasoned from "./convertPlexToSeasoned.js";
|
||||
import convertPlexToStream from "./convertPlexToStream.js";
|
||||
const convertPlexToSeasoned = require("./convertPlexToSeasoned");
|
||||
const convertPlexToStream = require("./convertPlexToStream");
|
||||
|
||||
// eslint-disable-next-line
|
||||
function addAttributeIfTmdbInPlex(_tmdb, plexResult) {
|
||||
@@ -41,12 +41,9 @@ class PlexRepository {
|
||||
|
||||
inPlex(_tmdbResult) {
|
||||
const tmdbResult = { ..._tmdbResult };
|
||||
|
||||
return this.search(tmdbResult.title)
|
||||
this.search(tmdbResult.title)
|
||||
.then(plexResult => addAttributeIfTmdbInPlex(tmdbResult, plexResult))
|
||||
.catch(() => {
|
||||
// log("some error here::", error);
|
||||
|
||||
/**
|
||||
* If something crashes with search from this function it probably
|
||||
* fine to set the `matchedInPlex` attribute to false and return
|
||||
@@ -106,4 +103,4 @@ class PlexRepository {
|
||||
// }
|
||||
}
|
||||
|
||||
export default PlexRepository;
|
||||
module.exports = PlexRepository;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import PlexRepository from "./plexRepository.js";
|
||||
import TMDB from "../tmdb/tmdb.js";
|
||||
import establishedDatabase from "../database/database.js";
|
||||
import Configuration from "../config/configuration.js";
|
||||
const PlexRepository = require("./plexRepository");
|
||||
const configuration = require("../config/configuration").getInstance();
|
||||
const TMDB = require("../tmdb/tmdb");
|
||||
const establishedDatabase = require("../database/database");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const plexRepository = new PlexRepository(
|
||||
configuration.get("plex", "ip"),
|
||||
configuration.get("plex", "token")
|
||||
@@ -129,4 +128,4 @@ class RequestRepository {
|
||||
}
|
||||
}
|
||||
|
||||
export default RequestRepository;
|
||||
module.exports = RequestRepository;
|
||||
|
||||
@@ -11,4 +11,4 @@ class convertStreamToPlayback {
|
||||
}
|
||||
}
|
||||
|
||||
export default convertStreamToPlayback;
|
||||
module.exports = convertStreamToPlayback;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Player from "../../media_classes/player.js";
|
||||
const Player = require("../../media_classes/player");
|
||||
|
||||
function convertStreamToPlayer(plexStream) {
|
||||
const player = new Player(plexStream.device, plexStream.address);
|
||||
@@ -10,4 +10,4 @@ function convertStreamToPlayer(plexStream) {
|
||||
return player;
|
||||
}
|
||||
|
||||
export default convertStreamToPlayer;
|
||||
module.exports = convertStreamToPlayer;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import User from "../../media_classes/user.js";
|
||||
const User = require("../../media_classes/user");
|
||||
|
||||
function convertStreamToUser(plexStream) {
|
||||
return new User(plexStream.id, plexStream.title);
|
||||
}
|
||||
|
||||
export default convertStreamToUser;
|
||||
module.exports = convertStreamToUser;
|
||||
|
||||
@@ -13,4 +13,4 @@ class Episode {
|
||||
}
|
||||
}
|
||||
|
||||
export default Episode;
|
||||
module.exports = Episode;
|
||||
|
||||
@@ -9,4 +9,4 @@ class Movie {
|
||||
}
|
||||
}
|
||||
|
||||
export default Movie;
|
||||
module.exports = Movie;
|
||||
|
||||
@@ -9,4 +9,4 @@ class Show {
|
||||
}
|
||||
}
|
||||
|
||||
export default Show;
|
||||
module.exports = Show;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from "assert";
|
||||
const assert = require("assert");
|
||||
// const configuration = require("../config/configuration").getInstance();
|
||||
// const TMDB = require("../tmdb/tmdb");
|
||||
import establishedDatabase from "../database/database.js";
|
||||
const establishedDatabase = require("../database/database");
|
||||
|
||||
// const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
|
||||
@@ -33,8 +33,7 @@ class RequestRepository {
|
||||
// downloaded: "(select status from requests where id is request.id and type is request.type limit 1)",
|
||||
// deluge: '(select status from deluge_torrent where id is request.id and type is request.type limit 1)',
|
||||
// fetchAllFilterStatus: 'select * from request where '
|
||||
readWithoutUserData:
|
||||
"select id, title, year, type, status, date from requests where id is ? and type is ?",
|
||||
// readWithoutUserData: "select id, title, year, type, status, date from requests where id is ? and type is ?",
|
||||
read: "select id, title, year, type, status, requested_by, ip, date, user_agent from requests where id is ? and type is ?"
|
||||
};
|
||||
}
|
||||
@@ -84,16 +83,16 @@ class RequestRepository {
|
||||
return this.database
|
||||
.get(this.queries.readWithoutUserData, [id, type])
|
||||
.then(row => {
|
||||
if (!row) return Promise.resolve(null);
|
||||
if (!row) return null;
|
||||
|
||||
return Promise.resolve({
|
||||
return {
|
||||
id: row.id,
|
||||
title: row.title,
|
||||
year: row.year,
|
||||
type: row.type,
|
||||
status: row.status,
|
||||
requested_date: new Date(row.date)
|
||||
});
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -157,4 +156,4 @@ class RequestRepository {
|
||||
}
|
||||
}
|
||||
|
||||
export default RequestRepository;
|
||||
module.exports = RequestRepository;
|
||||
|
||||
@@ -45,4 +45,4 @@ function validFilter(filterParam) {
|
||||
});
|
||||
}
|
||||
|
||||
export default { validSort, validFilter };
|
||||
module.exports = { validSort, validFilter };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import establishedDatabase from "../database/database.js";
|
||||
const establishedDatabase = require("../database/database");
|
||||
|
||||
class SearchHistoryCreateDatabaseError extends Error {
|
||||
constructor(message = "an unexpected error occured", errorResponse = null) {
|
||||
@@ -55,4 +55,4 @@ class SearchHistory {
|
||||
}
|
||||
}
|
||||
|
||||
export default SearchHistory;
|
||||
module.exports = SearchHistory;
|
||||
|
||||
@@ -4,4 +4,4 @@ class Stray {
|
||||
}
|
||||
}
|
||||
|
||||
export default Stray;
|
||||
module.exports = Stray;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from "assert";
|
||||
// import pythonShell from "python-shell";
|
||||
import Stray from "./stray.js";
|
||||
import establishedDatabase from "../database/database.js";
|
||||
const assert = require("assert");
|
||||
const pythonShell = require("python-shell");
|
||||
const Stray = require("./stray");
|
||||
const establishedDatabase = require("../database/database");
|
||||
|
||||
class StrayRepository {
|
||||
constructor(database) {
|
||||
@@ -48,21 +48,21 @@ class StrayRepository {
|
||||
return this.database.get(this.queries.checkVerified, strayId).then(row => {
|
||||
assert.notEqual(row, undefined, `Stray '${strayId}' already verified.`);
|
||||
|
||||
// const options = {
|
||||
// pythonPath: "../app/env/bin/python3",
|
||||
// args: [strayId]
|
||||
// };
|
||||
const options = {
|
||||
pythonPath: "../app/env/bin/python3",
|
||||
args: [strayId]
|
||||
};
|
||||
|
||||
// pythonShell.run("../app/moveSeasoned.py", options, (err, results) => {
|
||||
// if (err) throw err;
|
||||
// // TODO Add error handling!! StrayRepository.ERROR
|
||||
// // results is an array consisting of messages collected during execution
|
||||
// console.log("results: %j", results);
|
||||
// });
|
||||
pythonShell.run("../app/moveSeasoned.py", options, (err, results) => {
|
||||
if (err) throw err;
|
||||
// TODO Add error handling!! StrayRepository.ERROR
|
||||
// results is an array consisting of messages collected during execution
|
||||
console.log("results: %j", results);
|
||||
});
|
||||
|
||||
return this.database.run(this.queries.verify, strayId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default StrayRepository;
|
||||
module.exports = StrayRepository;
|
||||
|
||||
@@ -75,4 +75,4 @@ class Tautulli {
|
||||
}
|
||||
}
|
||||
|
||||
export default Tautulli;
|
||||
module.exports = Tautulli;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from "assert";
|
||||
import establishedDatabase from "../database/database.js";
|
||||
const assert = require("assert");
|
||||
const establishedDatabase = require("../database/database");
|
||||
|
||||
class Cache {
|
||||
constructor(database) {
|
||||
@@ -45,4 +45,4 @@ class Cache {
|
||||
}
|
||||
}
|
||||
|
||||
export default Cache;
|
||||
module.exports = Cache;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import moviedb from "km-moviedb";
|
||||
import redisCache from "../cache/redis.js";
|
||||
const moviedb = require("km-moviedb");
|
||||
const redisCache = require("../cache/redis");
|
||||
|
||||
import { Movie, Show, Person, Credits, ReleaseDates } from "./types.js";
|
||||
const { Movie, Show, Person, Credits, ReleaseDates } = require("./types");
|
||||
|
||||
class TMDBNotFoundError extends Error {
|
||||
constructor(message) {
|
||||
@@ -339,4 +339,4 @@ class TMDB {
|
||||
}
|
||||
}
|
||||
|
||||
export default TMDB;
|
||||
module.exports = TMDB;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Movie from "./types/movie.js";
|
||||
import Show from "./types/show.js";
|
||||
import Person from "./types/person.js";
|
||||
import Credits from "./types/credits.js";
|
||||
import ReleaseDates from "./types/releaseDates.js";
|
||||
const Movie = require("./types/movie");
|
||||
const Show = require("./types/show");
|
||||
const Person = require("./types/person");
|
||||
const Credits = require("./types/credits");
|
||||
const ReleaseDates = require("./types/releaseDates");
|
||||
|
||||
export { Movie, Show, Person, Credits, ReleaseDates };
|
||||
module.exports = { Movie, Show, Person, Credits, ReleaseDates };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable camelcase */
|
||||
import Movie from "./movie.js";
|
||||
import Show from "./show.js";
|
||||
const Movie = require("./movie");
|
||||
const Show = require("./show");
|
||||
|
||||
class CreditedMovie extends Movie {}
|
||||
class CreditedShow extends Show {}
|
||||
@@ -113,4 +113,4 @@ class Credits {
|
||||
}
|
||||
}
|
||||
|
||||
export default Credits;
|
||||
module.exports = Credits;
|
||||
|
||||
@@ -113,4 +113,4 @@ class Movie {
|
||||
}
|
||||
}
|
||||
|
||||
export default Movie;
|
||||
module.exports = Movie;
|
||||
|
||||
@@ -69,4 +69,4 @@ class Person {
|
||||
}
|
||||
}
|
||||
|
||||
export default Person;
|
||||
module.exports = Person;
|
||||
|
||||
@@ -89,4 +89,4 @@ class ReleaseDates {
|
||||
}
|
||||
}
|
||||
|
||||
export default ReleaseDates;
|
||||
module.exports = ReleaseDates;
|
||||
|
||||
@@ -86,4 +86,4 @@ class Show {
|
||||
}
|
||||
}
|
||||
|
||||
export default Show;
|
||||
module.exports = Show;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
import User from "./user.js";
|
||||
const jwt = require("jsonwebtoken");
|
||||
const User = require("./user");
|
||||
|
||||
class Token {
|
||||
constructor(user, admin = false, settings = null) {
|
||||
@@ -38,4 +38,4 @@ class Token {
|
||||
}
|
||||
}
|
||||
|
||||
export default Token;
|
||||
module.exports = Token;
|
||||
|
||||
@@ -5,4 +5,4 @@ class User {
|
||||
}
|
||||
}
|
||||
|
||||
export default User;
|
||||
module.exports = User;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from "assert";
|
||||
import establishedDatabase from "../database/database.js";
|
||||
const assert = require("assert");
|
||||
const establishedDatabase = require("../database/database");
|
||||
|
||||
class LinkPlexUserError extends Error {
|
||||
constructor(errorMessage = null) {
|
||||
@@ -263,4 +263,4 @@ class UserRepository {
|
||||
}
|
||||
}
|
||||
|
||||
export default UserRepository;
|
||||
module.exports = UserRepository;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import bcrypt from "bcrypt";
|
||||
import UserRepository from "./userRepository.js";
|
||||
const bcrypt = require("bcrypt");
|
||||
const UserRepository = require("./userRepository");
|
||||
|
||||
class UserSecurity {
|
||||
constructor(database) {
|
||||
@@ -72,4 +72,4 @@ class UserSecurity {
|
||||
}
|
||||
}
|
||||
|
||||
export default UserSecurity;
|
||||
module.exports = UserSecurity;
|
||||
|
||||
@@ -1,73 +1,20 @@
|
||||
import express from "express";
|
||||
import Raven from "raven";
|
||||
import cookieParser from "cookie-parser";
|
||||
import bodyParser from "body-parser";
|
||||
const express = require("express");
|
||||
const Raven = require("raven");
|
||||
const cookieParser = require("cookie-parser");
|
||||
const bodyParser = require("body-parser");
|
||||
|
||||
import Configuration from "../config/configuration.js";
|
||||
const configuration = require("../config/configuration").getInstance();
|
||||
|
||||
import reqTokenToUser from "./middleware/reqTokenToUser.js";
|
||||
import mustBeAuthenticated from "./middleware/mustBeAuthenticated.js";
|
||||
import mustBeAdmin from "./middleware/mustBeAdmin.js";
|
||||
import mustHaveAccountLinkedToPlex from "./middleware/mustHaveAccountLinkedToPlex.js";
|
||||
const reqTokenToUser = require("./middleware/reqTokenToUser");
|
||||
const mustBeAuthenticated = require("./middleware/mustBeAuthenticated");
|
||||
const mustBeAdmin = require("./middleware/mustBeAdmin");
|
||||
const mustHaveAccountLinkedToPlex = require("./middleware/mustHaveAccountLinkedToPlex");
|
||||
|
||||
import tautulli from "./controllers/user/viewHistory.js";
|
||||
import {
|
||||
getSettingsController,
|
||||
updateSettingsController
|
||||
} from "./controllers/user/settings.js";
|
||||
import AuthenticatePlexAccountController from "./controllers/user/authenticatePlexAccount.js";
|
||||
const listController = require("./controllers/list/listController");
|
||||
const tautulli = require("./controllers/user/viewHistory");
|
||||
const SettingsController = require("./controllers/user/settings");
|
||||
const AuthenticatePlexAccountController = require("./controllers/user/authenticatePlexAccount");
|
||||
|
||||
import UserRegisterController from "./controllers/user/register.js";
|
||||
import UserLoginController from "./controllers/user/login.js";
|
||||
import UserLogoutController from "./controllers/user/logout.js";
|
||||
import UserSearchHistoryController from "./controllers/user/searchHistory.js";
|
||||
import UserRequestsController from "./controllers/user/requests.js";
|
||||
|
||||
import SearchMultiController from "./controllers/search/multiSearch.js";
|
||||
import SearchMovieController from "./controllers/search/movieSearch.js";
|
||||
import SearchShowController from "./controllers/search/showSearch.js";
|
||||
import SearchPersonController from "./controllers/search/personSearch.js";
|
||||
|
||||
import listController from "./controllers/list/listController.js";
|
||||
|
||||
import MovieCreditsController from "./controllers/movie/credits.js";
|
||||
import MovieReleaseDatesController from "./controllers/movie/releaseDates.js";
|
||||
import MovieInfoController from "./controllers/movie/info.js";
|
||||
|
||||
import ShowCreditsController from "./controllers/show/credits.js";
|
||||
import ShowInfoController from "./controllers/show/info.js";
|
||||
|
||||
import PersonCreditsController from "./controllers/person/credits.js";
|
||||
import PersonInfoController from "./controllers/person/info.js";
|
||||
|
||||
// TODO refactor python-shell dependency or remove stray admin functions
|
||||
// import SeasonedAllController from "./controllers/seasoned/readStrays.js";
|
||||
// import SeasonedInfoController from "./controllers/seasoned/strayById.js";
|
||||
// import SeasonedVerifyController from "./controllers/seasoned/verifyStray.js";
|
||||
|
||||
import PlexSearchController from "./controllers/plex/search.js";
|
||||
import PlexFetchRequestedController from "./controllers/plex/fetchRequested.js";
|
||||
// import PlexRequestsInfo from "./controllers/plex/updateRequested.js";
|
||||
import PlexWatchLinkController from "./controllers/plex/watchDirectLink.js";
|
||||
import PlexHookController from "./controllers/plex/hookDump.js";
|
||||
import PlexSubmitRequestController from "./controllers/plex/submitRequest.js";
|
||||
import PlexRequestInfo from "./controllers/plex/readRequest.js";
|
||||
import PlexSearchRequestController from "./controllers/plex/searchRequest.js";
|
||||
import PlexPlayingController from "./controllers/plex/plexPlaying.js";
|
||||
import PlexSearchMediaController from "./controllers/plex/searchMedia.js";
|
||||
import PlexUpdateRequestedController from "./controllers/plex/updateRequested.js";
|
||||
|
||||
import RequestFetchAllController from "./controllers/request/fetchAllRequests.js";
|
||||
import RequestInfoController from "./controllers/request/getRequest.js";
|
||||
import RequestSubmitController from "./controllers/request/requestTmdbId.js";
|
||||
|
||||
import PirateSearchController from "./controllers/pirate/searchTheBay.js";
|
||||
import PirateAddController from "./controllers/pirate/addMagnet.js";
|
||||
|
||||
import GitDumpController from "./controllers/git/dumpHook.js";
|
||||
import EmojiController from "./controllers/misc/emoji.js";
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
// TODO: Have our raven router check if there is a value, if not don't enable raven.
|
||||
Raven.config(configuration.get("raven", "DSN")).install();
|
||||
|
||||
@@ -118,18 +65,30 @@ router.get("/", (req, res) => {
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
router.post("/v1/user", UserRegisterController);
|
||||
router.post("/v1/user/login", UserLoginController);
|
||||
router.post("/v1/user/logout", UserLogoutController);
|
||||
router.post("/v1/user", require("./controllers/user/register"));
|
||||
router.post("/v1/user/login", require("./controllers/user/login"));
|
||||
router.post("/v1/user/logout", require("./controllers/user/logout"));
|
||||
|
||||
router.get("/v1/user/settings", mustBeAuthenticated, getSettingsController);
|
||||
router.put("/v1/user/settings", mustBeAuthenticated, updateSettingsController);
|
||||
router.get(
|
||||
"/v1/user/settings",
|
||||
mustBeAuthenticated,
|
||||
SettingsController.getSettingsController
|
||||
);
|
||||
router.put(
|
||||
"/v1/user/settings",
|
||||
mustBeAuthenticated,
|
||||
SettingsController.updateSettingsController
|
||||
);
|
||||
router.get(
|
||||
"/v1/user/search_history",
|
||||
mustBeAuthenticated,
|
||||
UserSearchHistoryController
|
||||
require("./controllers/user/searchHistory")
|
||||
);
|
||||
router.get(
|
||||
"/v1/user/requests",
|
||||
mustBeAuthenticated,
|
||||
require("./controllers/user/requests")
|
||||
);
|
||||
router.get("/v1/user/requests", mustBeAuthenticated, UserRequestsController);
|
||||
|
||||
router.post(
|
||||
"/v1/user/link_plex",
|
||||
@@ -166,80 +125,111 @@ router.get(
|
||||
/**
|
||||
* Seasoned
|
||||
*/
|
||||
// router.get("/v1/seasoned/all", SeasonedAllController);
|
||||
// router.get("/v1/seasoned/:strayId", SeasonedInfoController);
|
||||
// router.post("/v1/seasoned/verify/:strayId", SeasonedVerifyController);
|
||||
router.get("/v1/seasoned/all", require("./controllers/seasoned/readStrays"));
|
||||
router.get(
|
||||
"/v1/seasoned/:strayId",
|
||||
require("./controllers/seasoned/strayById")
|
||||
);
|
||||
router.post(
|
||||
"/v1/seasoned/verify/:strayId",
|
||||
require("./controllers/seasoned/verifyStray")
|
||||
);
|
||||
|
||||
router.get("/v2/search/", SearchMultiController);
|
||||
router.get("/v2/search/movie", SearchMovieController);
|
||||
router.get("/v2/search/show", SearchShowController);
|
||||
router.get("/v2/search/person", SearchPersonController);
|
||||
router.get("/v2/search/", require("./controllers/search/multiSearch"));
|
||||
router.get("/v2/search/movie", require("./controllers/search/movieSearch"));
|
||||
router.get("/v2/search/show", require("./controllers/search/showSearch"));
|
||||
router.get("/v2/search/person", require("./controllers/search/personSearch"));
|
||||
|
||||
router.get("/v2/movie/now_playing", listController.nowPlayingMovies);
|
||||
router.get("/v2/movie/popular", listController.popularMovies);
|
||||
router.get("/v2/movie/top_rated", listController.topRatedMovies);
|
||||
router.get("/v2/movie/upcoming", listController.upcomingMovies);
|
||||
router.get("/v2/movie/:id/credits", MovieCreditsController);
|
||||
router.get("/v2/movie/:id/release_dates", MovieReleaseDatesController);
|
||||
router.get("/v2/movie/:id", MovieInfoController);
|
||||
router.get("/v2/movie/:id/credits", require("./controllers/movie/credits"));
|
||||
router.get(
|
||||
"/v2/movie/:id/release_dates",
|
||||
require("./controllers/movie/releaseDates")
|
||||
);
|
||||
router.get("/v2/movie/:id", require("./controllers/movie/info"));
|
||||
|
||||
router.get("/v2/show/now_playing", listController.nowPlayingShows);
|
||||
router.get("/v2/show/popular", listController.popularShows);
|
||||
router.get("/v2/show/top_rated", listController.topRatedShows);
|
||||
router.get("/v2/show/:id/credits", ShowCreditsController);
|
||||
router.get("/v2/show/:id", ShowInfoController);
|
||||
router.get("/v2/show/:id/credits", require("./controllers/show/credits"));
|
||||
router.get("/v2/show/:id", require("./controllers/show/info"));
|
||||
|
||||
router.get("/v2/person/:id/credits", PersonCreditsController);
|
||||
router.get("/v2/person/:id", PersonInfoController);
|
||||
router.get("/v2/person/:id/credits", require("./controllers/person/credits"));
|
||||
router.get("/v2/person/:id", require("./controllers/person/info"));
|
||||
|
||||
/**
|
||||
* Plex
|
||||
*/
|
||||
router.get("/v2/plex/search", PlexSearchController);
|
||||
router.get("/v2/plex/search", require("./controllers/plex/search"));
|
||||
|
||||
/**
|
||||
* List
|
||||
*/
|
||||
router.get("/v1/plex/search", PlexSearchMediaController);
|
||||
router.get("/v1/plex/playing", PlexPlayingController);
|
||||
router.get("/v1/plex/request", PlexSearchRequestController);
|
||||
router.get("/v1/plex/request/:mediaId", PlexRequestInfo);
|
||||
router.post("/v1/plex/request/:mediaId", PlexSubmitRequestController);
|
||||
router.post("/v1/plex/hook", PlexHookController);
|
||||
router.get("/v1/plex/search", require("./controllers/plex/searchMedia"));
|
||||
router.get("/v1/plex/playing", require("./controllers/plex/plexPlaying"));
|
||||
router.get("/v1/plex/request", require("./controllers/plex/searchRequest"));
|
||||
router.get(
|
||||
"/v1/plex/request/:mediaId",
|
||||
require("./controllers/plex/readRequest")
|
||||
);
|
||||
router.post(
|
||||
"/v1/plex/request/:mediaId",
|
||||
require("./controllers/plex/submitRequest")
|
||||
);
|
||||
router.post("/v1/plex/hook", require("./controllers/plex/hookDump"));
|
||||
|
||||
router.get("/v1/plex/watch-link", mustBeAuthenticated, PlexWatchLinkController);
|
||||
router.get(
|
||||
"/v1/plex/watch-link",
|
||||
mustBeAuthenticated,
|
||||
require("./controllers/plex/watchDirectLink")
|
||||
);
|
||||
|
||||
/**
|
||||
* Requests
|
||||
*/
|
||||
|
||||
router.get("/v2/request", RequestFetchAllController);
|
||||
router.get("/v2/request/:id", RequestInfoController);
|
||||
router.post("/v2/request", RequestSubmitController);
|
||||
router.get("/v1/plex/requests/all", PlexFetchRequestedController);
|
||||
router.get("/v2/request", require("./controllers/request/fetchAllRequests"));
|
||||
router.get("/v2/request/:id", require("./controllers/request/getRequest"));
|
||||
router.post("/v2/request", require("./controllers/request/requestTmdbId"));
|
||||
router.get(
|
||||
"/v1/plex/requests/all",
|
||||
require("./controllers/plex/fetchRequested")
|
||||
);
|
||||
router.put(
|
||||
"/v1/plex/request/:requestId",
|
||||
mustBeAuthenticated,
|
||||
PlexUpdateRequestedController
|
||||
require("./controllers/plex/updateRequested")
|
||||
);
|
||||
|
||||
/**
|
||||
* Pirate
|
||||
*/
|
||||
router.get("/v1/pirate/search", mustBeAdmin, PirateSearchController);
|
||||
router.post("/v1/pirate/add", mustBeAdmin, PirateAddController);
|
||||
router.get(
|
||||
"/v1/pirate/search",
|
||||
mustBeAdmin,
|
||||
require("./controllers/pirate/searchTheBay")
|
||||
);
|
||||
router.post(
|
||||
"/v1/pirate/add",
|
||||
mustBeAdmin,
|
||||
require("./controllers/pirate/addMagnet")
|
||||
);
|
||||
|
||||
/**
|
||||
* git
|
||||
*/
|
||||
router.post("/v1/git/dump", GitDumpController);
|
||||
router.post("/v1/git/dump", require("./controllers/git/dumpHook"));
|
||||
|
||||
/**
|
||||
* misc
|
||||
*/
|
||||
router.get("/v1/emoji", EmojiController);
|
||||
router.get("/v1/emoji", require("./controllers/misc/emoji"));
|
||||
|
||||
// REGISTER OUR ROUTES -------------------------------
|
||||
// all of our routes will be prefixed with /api
|
||||
app.use("/api", router);
|
||||
|
||||
export default app;
|
||||
module.exports = app;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import GitRepository from "../../../git/gitRepository.js";
|
||||
const GitRepository = require("../../../git/gitRepository");
|
||||
|
||||
const gitRepository = new GitRepository();
|
||||
|
||||
@@ -9,4 +9,4 @@ function dumpHookController(req, res) {
|
||||
.catch(() => res.status(500));
|
||||
}
|
||||
|
||||
export default dumpHookController;
|
||||
module.exports = dumpHookController;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
|
||||
// there should be a translate function from query params to
|
||||
@@ -66,7 +65,7 @@ const popularShows = (req, res) =>
|
||||
const topRatedShows = (req, res) =>
|
||||
fetchTmdbList(req, res, "miscTopRatedTvs", "show");
|
||||
|
||||
export default {
|
||||
module.exports = {
|
||||
nowPlayingMovies,
|
||||
popularMovies,
|
||||
topRatedMovies,
|
||||
|
||||
@@ -16,10 +16,12 @@ const randomEmoji = () => {
|
||||
* @param {Response} res
|
||||
* @returns {Callback}
|
||||
*/
|
||||
export default function emojiController(req, res) {
|
||||
function emojiController(req, res) {
|
||||
res.send({
|
||||
success: true,
|
||||
emoji: randomEmoji(),
|
||||
message: "Happy emoji-ing! 🌝"
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = emojiController;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
|
||||
const movieCreditsController = (req, res) => {
|
||||
@@ -20,4 +19,4 @@ const movieCreditsController = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
export default movieCreditsController;
|
||||
module.exports = movieCreditsController;
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import Plex from "../../../plex/plex.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
const Plex = require("../../../plex/plex");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
const plex = new Plex(
|
||||
configuration.get("plex", "ip"),
|
||||
configuration.get("plex", "token")
|
||||
);
|
||||
const plex = new Plex(configuration.get("plex", "ip"));
|
||||
|
||||
/**
|
||||
* Controller: Retrieve information for a movie
|
||||
@@ -56,4 +52,4 @@ async function movieInfoController(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
export default movieInfoController;
|
||||
module.exports = movieInfoController;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
|
||||
const movieReleaseDatesController = (req, res) => {
|
||||
@@ -20,4 +19,4 @@ const movieReleaseDatesController = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
export default movieReleaseDatesController;
|
||||
module.exports = movieReleaseDatesController;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
|
||||
const personCreditsController = (req, res) => {
|
||||
@@ -20,4 +19,4 @@ const personCreditsController = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
export default personCreditsController;
|
||||
module.exports = personCreditsController;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
|
||||
/**
|
||||
@@ -37,4 +36,4 @@ async function personInfoController(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
export default personInfoController;
|
||||
module.exports = personInfoController;
|
||||
|
||||
@@ -5,20 +5,17 @@
|
||||
* @Last Modified time: 2017-10-21 15:32:43
|
||||
*/
|
||||
|
||||
import { AddMagnet } from "../../../pirate/pirateRepository.js";
|
||||
const PirateRepository = require("../../../pirate/pirateRepository");
|
||||
|
||||
function addMagnet(req, res) {
|
||||
const { magnet, name } = req.body;
|
||||
const tmdbId = req.body?.tmdb_id;
|
||||
|
||||
AddMagnet(magnet, name, tmdbId)
|
||||
PirateRepository.AddMagnet(magnet, name, tmdbId)
|
||||
.then(result => res.send(result))
|
||||
.catch(error => {
|
||||
res.status(error?.statusCode || 500).send({
|
||||
success: false,
|
||||
message: error?.message || "Unexpected error while adding magnet."
|
||||
});
|
||||
res.status(500).send({ success: false, message: error.message });
|
||||
});
|
||||
}
|
||||
|
||||
export default addMagnet;
|
||||
module.exports = addMagnet;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @Last Modified time: 2018-02-26 19:56:32
|
||||
*/
|
||||
|
||||
import { SearchPiratebay } from "../../../pirate/pirateRepository.js";
|
||||
const PirateRepository = require("../../../pirate/pirateRepository");
|
||||
// const pirateRepository = new PirateRepository();
|
||||
|
||||
/**
|
||||
@@ -17,16 +17,13 @@ import { SearchPiratebay } from "../../../pirate/pirateRepository.js";
|
||||
function updateRequested(req, res) {
|
||||
const { query, page, type } = req.query;
|
||||
|
||||
SearchPiratebay(query, page, type)
|
||||
PirateRepository.SearchPiratebay(query, page, type)
|
||||
.then(result => {
|
||||
res.send({ success: true, results: result });
|
||||
})
|
||||
.catch(error => {
|
||||
res.status(error?.statusCode || 500).send({
|
||||
success: false,
|
||||
message: error?.message || "Unexpected error while searching."
|
||||
});
|
||||
res.status(401).send({ success: false, message: error.message });
|
||||
});
|
||||
}
|
||||
|
||||
export default updateRequested;
|
||||
module.exports = updateRequested;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import RequestRepository from "../../../plex/requestRepository.js";
|
||||
const RequestRepository = require("../../../plex/requestRepository");
|
||||
|
||||
const requestRepository = new RequestRepository();
|
||||
|
||||
@@ -26,4 +26,4 @@ function fetchRequestedController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default fetchRequestedController;
|
||||
module.exports = fetchRequestedController;
|
||||
|
||||
@@ -5,4 +5,4 @@ function hookDumpController(req, res) {
|
||||
res.status(200);
|
||||
}
|
||||
|
||||
export default hookDumpController;
|
||||
module.exports = hookDumpController;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import PlexRepository from "../../../plex/plexRepository.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const PlexRepository = require("../../../plex/plexRepository");
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
|
||||
const plexRepository = new PlexRepository(
|
||||
configuration.get("plex", "ip"),
|
||||
@@ -19,4 +17,4 @@ function playingController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default playingController;
|
||||
module.exports = playingController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import RequestRepository from "../../../plex/requestRepository.js";
|
||||
const RequestRepository = require("../../../plex/requestRepository");
|
||||
|
||||
const requestRepository = new RequestRepository();
|
||||
|
||||
@@ -14,11 +14,11 @@ function readRequestController(req, res) {
|
||||
requestRepository
|
||||
.lookup(mediaId, type)
|
||||
.then(movies => {
|
||||
res.send(movies || {});
|
||||
res.send(movies);
|
||||
})
|
||||
.catch(error => {
|
||||
res.status(404).send({ success: false, message: error.message });
|
||||
});
|
||||
}
|
||||
|
||||
export default readRequestController;
|
||||
module.exports = readRequestController;
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import Plex from "../../../plex/plex.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const Plex = require("../../../plex/plex");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
|
||||
const plex = new Plex(
|
||||
configuration.get("plex", "ip"),
|
||||
configuration.get("plex", "token")
|
||||
);
|
||||
const plex = new Plex(configuration.get("plex", "ip"));
|
||||
|
||||
/**
|
||||
* Controller: Search plex for movies, shows and episodes by query
|
||||
@@ -33,4 +28,4 @@ function searchPlexController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default searchPlexController;
|
||||
module.exports = searchPlexController;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import PlexRepository from "../../../plex/plexRepository.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const PlexRepository = require("../../../plex/plexRepository");
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
|
||||
const plexRepository = new PlexRepository(
|
||||
configuration.get("plex", "ip"),
|
||||
@@ -35,4 +33,4 @@ function searchMediaController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default searchMediaController;
|
||||
module.exports = searchMediaController;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import SearchHistory from "../../../searchHistory/searchHistory.js";
|
||||
import Cache from "../../../tmdb/cache.js";
|
||||
import RequestRepository from "../../../plex/requestRepository.js";
|
||||
const SearchHistory = require("../../../searchHistory/searchHistory");
|
||||
const Cache = require("../../../tmdb/cache");
|
||||
const RequestRepository = require("../../../plex/requestRepository");
|
||||
|
||||
const cache = new Cache();
|
||||
const requestRepository = new RequestRepository(cache);
|
||||
@@ -21,4 +21,4 @@ function searchRequestController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default searchRequestController;
|
||||
module.exports = searchRequestController;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import RequestRepository from "../../../request/request.js";
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const RequestRepository = require("../../../request/request");
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
const request = new RequestRepository();
|
||||
|
||||
@@ -58,4 +57,4 @@ function submitRequestController(req, res) {
|
||||
);
|
||||
}
|
||||
|
||||
export default submitRequestController;
|
||||
module.exports = submitRequestController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import RequestRepository from "../../../plex/requestRepository.js";
|
||||
const RequestRepository = require("../../../plex/requestRepository");
|
||||
|
||||
const requestRepository = new RequestRepository();
|
||||
|
||||
@@ -23,4 +23,4 @@ function updateRequested(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default updateRequested;
|
||||
module.exports = updateRequested;
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import Plex from "../../../plex/plex.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const Plex = require("../../../plex/plex");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const plex = new Plex(
|
||||
configuration.get("plex", "ip"),
|
||||
configuration.get("plex", "token")
|
||||
);
|
||||
const plex = new Plex(configuration.get("plex", "ip"));
|
||||
|
||||
/**
|
||||
* Controller: Search plex for movies, shows and episodes by query
|
||||
@@ -29,4 +25,4 @@ function watchDirectLink(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default watchDirectLink;
|
||||
module.exports = watchDirectLink;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import RequestRepository from "../../../request/request.js";
|
||||
const RequestRepository = require("../../../request/request");
|
||||
|
||||
const request = new RequestRepository();
|
||||
|
||||
@@ -24,4 +24,4 @@ function fetchAllRequests(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default fetchAllRequests;
|
||||
module.exports = fetchAllRequests;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import RequestRepository from "../../../request/request.js";
|
||||
const RequestRepository = require("../../../request/request");
|
||||
|
||||
const request = new RequestRepository();
|
||||
|
||||
@@ -12,7 +12,7 @@ function fetchAllRequests(req, res) {
|
||||
const { id } = req.params;
|
||||
const { type } = req.query;
|
||||
|
||||
return request
|
||||
request
|
||||
.getRequestByIdAndType(id, type)
|
||||
.then(result => {
|
||||
if (!result) {
|
||||
@@ -37,4 +37,4 @@ function fetchAllRequests(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default fetchAllRequests;
|
||||
module.exports = fetchAllRequests;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import RequestRepository from "../../../request/request.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
// import sendSMS from "../../../notifications/sms.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
const RequestRepository = require("../../../request/request");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
const request = new RequestRepository();
|
||||
// const { sendSMS } = require("src/notifications/sms");
|
||||
|
||||
const tmdbMovieInfo = id => {
|
||||
return tmdb.movieInfo(id);
|
||||
@@ -66,4 +65,4 @@ function requestTmdbIdController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default requestTmdbIdController;
|
||||
module.exports = requestTmdbIdController;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import SearchHistory from "../../../searchHistory/searchHistory.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
const SearchHistory = require("../../../searchHistory/searchHistory");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
const searchHistory = new SearchHistory();
|
||||
|
||||
@@ -34,4 +33,4 @@ function movieSearchController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default movieSearchController;
|
||||
module.exports = movieSearchController;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import SearchHistory from "../../../searchHistory/searchHistory.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
const SearchHistory = require("../../../searchHistory/searchHistory");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
const searchHistory = new SearchHistory();
|
||||
|
||||
@@ -34,4 +33,4 @@ function multiSearchController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default multiSearchController;
|
||||
module.exports = multiSearchController;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import SearchHistory from "../../../searchHistory/searchHistory.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
const SearchHistory = require("../../../searchHistory/searchHistory");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
const searchHistory = new SearchHistory();
|
||||
|
||||
@@ -34,4 +33,4 @@ function personSearchController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default personSearchController;
|
||||
module.exports = personSearchController;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import SearchHistory from "../../../searchHistory/searchHistory.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const SearchHistory = require("../../../searchHistory/searchHistory");
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
const searchHistory = new SearchHistory();
|
||||
|
||||
@@ -36,4 +35,4 @@ function showSearchController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default showSearchController;
|
||||
module.exports = showSearchController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import StrayRepository from "../../../seasoned/strayRepository.js";
|
||||
const StrayRepository = require("../../../seasoned/strayRepository");
|
||||
|
||||
const strayRepository = new StrayRepository();
|
||||
|
||||
@@ -14,4 +14,4 @@ function readStraysController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default readStraysController;
|
||||
module.exports = readStraysController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import StrayRepository from "../../../seasoned/strayRepository.js";
|
||||
const StrayRepository = require("../../../seasoned/strayRepository");
|
||||
|
||||
const strayRepository = new StrayRepository();
|
||||
|
||||
@@ -15,4 +15,4 @@ function strayByIdController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default strayByIdController;
|
||||
module.exports = strayByIdController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import StrayRepository from "../../../seasoned/strayRepository.js";
|
||||
const StrayRepository = require("../../../seasoned/strayRepository");
|
||||
|
||||
const strayRepository = new StrayRepository();
|
||||
|
||||
@@ -15,4 +15,4 @@ function verifyStrayController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default verifyStrayController;
|
||||
module.exports = verifyStrayController;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
|
||||
const showCreditsController = (req, res) => {
|
||||
@@ -20,4 +19,4 @@ const showCreditsController = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
export default showCreditsController;
|
||||
module.exports = showCreditsController;
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import TMDB from "../../../tmdb/tmdb.js";
|
||||
import Plex from "../../../plex/plex.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const TMDB = require("../../../tmdb/tmdb");
|
||||
const Plex = require("../../../plex/plex");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
|
||||
const plex = new Plex(
|
||||
configuration.get("plex", "ip"),
|
||||
configuration.get("plex", "token")
|
||||
);
|
||||
const plex = new Plex(configuration.get("plex", "ip"));
|
||||
|
||||
/**
|
||||
* Controller: Retrieve information for a show
|
||||
@@ -51,4 +47,4 @@ async function showInfoController(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
export default showInfoController;
|
||||
module.exports = showInfoController;
|
||||
|
||||
@@ -1,39 +1,45 @@
|
||||
import FormData from "form-data";
|
||||
import UserRepository from "../../../user/userRepository.js";
|
||||
const FormData = require("form-data");
|
||||
const UserRepository = require("../../../user/userRepository");
|
||||
|
||||
const userRepository = new UserRepository();
|
||||
|
||||
class PlexAuthenticationError extends Error {
|
||||
constructor(errorResponse) {
|
||||
constructor(errorResponse, statusCode) {
|
||||
const message =
|
||||
"Unexptected error while authenticating to plex signin api. View error response.";
|
||||
super(message);
|
||||
|
||||
this.errorResponse = errorResponse;
|
||||
this.statusCode = 500;
|
||||
this.statusCode = statusCode;
|
||||
this.success = false;
|
||||
this.source = "plex";
|
||||
}
|
||||
}
|
||||
|
||||
class PlexUnauthorizedError extends Error {
|
||||
constructor(errorResponse) {
|
||||
const message = "Unauthorized. Please check plex credentials.";
|
||||
super(message);
|
||||
function handleError(error, res) {
|
||||
const status = error?.status;
|
||||
let { message, source } = error;
|
||||
|
||||
this.errorResponse = errorResponse;
|
||||
this.statusCode = 401;
|
||||
this.success = false;
|
||||
this.source = "plex";
|
||||
if (status && message) {
|
||||
if (status === 401) {
|
||||
message = "Unauthorized. Please check plex credentials.";
|
||||
source = "plex";
|
||||
}
|
||||
|
||||
res.status(status).send({ success: false, message, source });
|
||||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log("caught authenticate plex account controller error", error);
|
||||
res.status(500).send({
|
||||
message:
|
||||
"An unexpected error occured while authenticating your account with plex",
|
||||
source
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleResponse(response) {
|
||||
if (!response.ok) {
|
||||
if (response?.status === 401)
|
||||
throw new PlexUnauthorizedError(response?.statusText);
|
||||
|
||||
throw new PlexAuthenticationError(response?.statusText);
|
||||
throw new PlexAuthenticationError(response.statusText, response.status);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
@@ -74,16 +80,7 @@ function link(req, res) {
|
||||
"Successfully authenticated and linked plex account with seasoned request."
|
||||
})
|
||||
)
|
||||
.catch(error =>
|
||||
res.status(error?.statusCode || 500).send({
|
||||
message:
|
||||
error?.message ||
|
||||
"Unexptected error occured while linking plex account",
|
||||
success: error?.success || false,
|
||||
source: error?.source,
|
||||
errorResponse: error?.errorResponse
|
||||
})
|
||||
);
|
||||
.catch(error => handleError(error, res));
|
||||
}
|
||||
|
||||
function unlink(req, res) {
|
||||
@@ -97,16 +94,10 @@ function unlink(req, res) {
|
||||
message: "Successfully unlinked plex account from seasoned request."
|
||||
})
|
||||
)
|
||||
.catch(error =>
|
||||
res.status(error?.statusCode || 500).send({
|
||||
message:
|
||||
error?.message ||
|
||||
"Unexptected error occured while unlinking plex account",
|
||||
success: error?.success || false,
|
||||
source: error?.source,
|
||||
errorResponse: error?.errorResponse
|
||||
})
|
||||
);
|
||||
.catch(error => handleError(error, res));
|
||||
}
|
||||
|
||||
export default { link, unlink };
|
||||
module.exports = {
|
||||
link,
|
||||
unlink
|
||||
};
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import User from "../../../user/user.js";
|
||||
import Token from "../../../user/token.js";
|
||||
import UserSecurity from "../../../user/userSecurity.js";
|
||||
import UserRepository from "../../../user/userRepository.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const User = require("../../../user/user");
|
||||
const Token = require("../../../user/token");
|
||||
const UserSecurity = require("../../../user/userSecurity");
|
||||
const UserRepository = require("../../../user/userRepository");
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const secret = configuration.get("authentication", "secret");
|
||||
const userSecurity = new UserSecurity();
|
||||
const userRepository = new UserRepository();
|
||||
@@ -55,4 +54,4 @@ async function loginController(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
export default loginController;
|
||||
module.exports = loginController;
|
||||
|
||||
@@ -13,4 +13,4 @@ async function logoutController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default logoutController;
|
||||
module.exports = logoutController;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import User from "../../../user/user.js";
|
||||
import Token from "../../../user/token.js";
|
||||
import UserSecurity from "../../../user/userSecurity.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const User = require("../../../user/user");
|
||||
const Token = require("../../../user/token");
|
||||
const UserSecurity = require("../../../user/userSecurity");
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const secret = configuration.get("authentication", "secret");
|
||||
const userSecurity = new UserSecurity();
|
||||
|
||||
@@ -43,4 +42,4 @@ function registerController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default registerController;
|
||||
module.exports = registerController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import RequestRepository from "../../../plex/requestRepository.js";
|
||||
const RequestRepository = require("../../../plex/requestRepository");
|
||||
|
||||
const requestRepository = new RequestRepository();
|
||||
|
||||
@@ -25,4 +25,4 @@ function requestsController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default requestsController;
|
||||
module.exports = requestsController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import SearchHistory from "../../../searchHistory/searchHistory.js";
|
||||
const SearchHistory = require("../../../searchHistory/searchHistory");
|
||||
|
||||
const searchHistory = new SearchHistory();
|
||||
|
||||
@@ -21,4 +21,4 @@ function historyController(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export default historyController;
|
||||
module.exports = historyController;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import UserRepository from "../../../user/userRepository.js";
|
||||
const UserRepository = require("../../../user/userRepository");
|
||||
|
||||
const userRepository = new UserRepository();
|
||||
/**
|
||||
@@ -7,7 +7,7 @@ const userRepository = new UserRepository();
|
||||
* @param {Response} res
|
||||
* @returns {Callback}
|
||||
*/
|
||||
export function getSettingsController(req, res) {
|
||||
const getSettingsController = (req, res) => {
|
||||
const username = req.loggedInUser ? req.loggedInUser.username : null;
|
||||
|
||||
userRepository
|
||||
@@ -18,9 +18,9 @@ export function getSettingsController(req, res) {
|
||||
.catch(error => {
|
||||
res.status(404).send({ success: false, message: error.message });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export function updateSettingsController(req, res) {
|
||||
const updateSettingsController = (req, res) => {
|
||||
const username = req.loggedInUser ? req.loggedInUser.username : null;
|
||||
|
||||
// const idempotencyKey = req.headers("Idempotency-Key"); // TODO implement better transactions
|
||||
@@ -35,4 +35,9 @@ export function updateSettingsController(req, res) {
|
||||
.catch(error => {
|
||||
res.status(404).send({ success: false, message: error.message });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getSettingsController,
|
||||
updateSettingsController
|
||||
};
|
||||
|
||||
@@ -1,46 +1,21 @@
|
||||
import Tautulli from "../../../tautulli/tautulli.js";
|
||||
import Configuration from "../../../config/configuration.js";
|
||||
const configuration = require("../../../config/configuration").getInstance();
|
||||
const Tautulli = require("../../../tautulli/tautulli");
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
const apiKey = configuration.get("tautulli", "apiKey");
|
||||
const ip = configuration.get("tautulli", "ip");
|
||||
const port = configuration.get("tautulli", "port");
|
||||
const tautulli = new Tautulli(apiKey, ip, port);
|
||||
|
||||
class MissingDaysParameterError extends Error {
|
||||
constructor() {
|
||||
const message = "Missing parameter: days (number)";
|
||||
super(message);
|
||||
function handleError(error, res) {
|
||||
const { status, message } = error;
|
||||
|
||||
this.statusCode = 422;
|
||||
}
|
||||
}
|
||||
|
||||
class MissingYAxisParameterError extends Error {
|
||||
constructor(message = "Missing parameter: y_axis") {
|
||||
super(message);
|
||||
|
||||
this.statusCode = 422;
|
||||
}
|
||||
}
|
||||
|
||||
function requiredPlaysByDayParams(req) {
|
||||
const days = req.query?.days;
|
||||
const yAxis = req.query?.y_axis;
|
||||
let error;
|
||||
|
||||
if (days === undefined) {
|
||||
error = new MissingDaysParameterError();
|
||||
if (status && message) {
|
||||
return res.status(status).send({ success: false, message });
|
||||
}
|
||||
|
||||
const allowedYAxisDataType = ["plays", "duration"];
|
||||
if (!allowedYAxisDataType.includes(yAxis)) {
|
||||
error = new MissingYAxisParameterError(
|
||||
`Y axis parameter must be one of values: [${allowedYAxisDataType}]`
|
||||
);
|
||||
}
|
||||
|
||||
return error ? Promise.reject(error) : Promise.resolve();
|
||||
return res.status(500).send({
|
||||
message: "An unexpected error occured while fetching view history"
|
||||
});
|
||||
}
|
||||
|
||||
function watchTimeStatsController(req, res) {
|
||||
@@ -55,15 +30,7 @@ function watchTimeStatsController(req, res) {
|
||||
message: "watch time successfully fetched from tautulli"
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
res.status(error?.statusCode || 500).send({
|
||||
message:
|
||||
error?.message ||
|
||||
"An unexpected error occured while fetching watch time",
|
||||
errorResponse: error?.errorResponse,
|
||||
success: false
|
||||
});
|
||||
});
|
||||
.catch(error => handleError(error, res));
|
||||
}
|
||||
|
||||
function getPlaysByDayOfWeekController(req, res) {
|
||||
@@ -71,8 +38,8 @@ function getPlaysByDayOfWeekController(req, res) {
|
||||
const days = req.query?.days;
|
||||
const yAxis = req.query?.y_axis;
|
||||
|
||||
return requiredPlaysByDayParams(req)
|
||||
.then(() => tautulli.getPlaysByDayOfWeek(user.plexUserId, days, yAxis))
|
||||
return tautulli
|
||||
.getPlaysByDayOfWeek(user.plexUserId, days, yAxis)
|
||||
.then(data =>
|
||||
res.send({
|
||||
success: true,
|
||||
@@ -80,15 +47,7 @@ function getPlaysByDayOfWeekController(req, res) {
|
||||
message: "play by day of week successfully fetched from tautulli"
|
||||
})
|
||||
)
|
||||
.catch(error => {
|
||||
res.status(error?.statusCode || 500).send({
|
||||
message:
|
||||
error?.message ||
|
||||
"An unexpected error occured while fetching plays by day of week",
|
||||
errorResponse: error?.errorResponse,
|
||||
success: false
|
||||
});
|
||||
});
|
||||
.catch(error => handleError(error, res));
|
||||
}
|
||||
|
||||
function getPlaysByDaysController(req, res) {
|
||||
@@ -96,23 +55,30 @@ function getPlaysByDaysController(req, res) {
|
||||
const days = req.query?.days;
|
||||
const yAxis = req.query?.y_axis;
|
||||
|
||||
return requiredPlaysByDayParams(req, res)
|
||||
.then(() => tautulli.getPlaysByDays(user.plexUserId, days, yAxis))
|
||||
if (days === undefined) {
|
||||
return res.status(422).send({
|
||||
success: false,
|
||||
message: "Missing parameter: days (number)"
|
||||
});
|
||||
}
|
||||
|
||||
const allowedYAxisDataType = ["plays", "duration"];
|
||||
if (!allowedYAxisDataType.includes(yAxis)) {
|
||||
return res.status(422).send({
|
||||
success: false,
|
||||
message: `Y axis parameter must be one of values: [${allowedYAxisDataType}]`
|
||||
});
|
||||
}
|
||||
|
||||
return tautulli
|
||||
.getPlaysByDays(user.plexUserId, days, yAxis)
|
||||
.then(data =>
|
||||
res.send({
|
||||
success: true,
|
||||
data: data.response.data
|
||||
})
|
||||
)
|
||||
.catch(error => {
|
||||
res.status(error?.statusCode || 500).send({
|
||||
message:
|
||||
error?.message ||
|
||||
"An unexpected error occured while fetching plays by days",
|
||||
errorResponse: error?.errorResponse,
|
||||
success: false
|
||||
});
|
||||
});
|
||||
.catch(error => handleError(error, res));
|
||||
}
|
||||
|
||||
function userViewHistoryController(req, res) {
|
||||
@@ -130,22 +96,14 @@ function userViewHistoryController(req, res) {
|
||||
message: "view history successfully fetched from tautulli"
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
res.status(error?.statusCode || 500).send({
|
||||
message:
|
||||
error?.message ||
|
||||
"An unexpected error occured while fetching view history",
|
||||
errorResponse: error?.errorResponse,
|
||||
success: false
|
||||
});
|
||||
});
|
||||
.catch(error => handleError(error, res));
|
||||
|
||||
// const username = user.username;
|
||||
}
|
||||
|
||||
export default {
|
||||
module.exports = {
|
||||
watchTimeStatsController,
|
||||
getPlaysByDayOfWeekController,
|
||||
getPlaysByDaysController,
|
||||
getPlaysByDayOfWeekController,
|
||||
userViewHistoryController
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user