@@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS search_history (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS requests(
|
CREATE TABLE IF NOT EXISTS requests(
|
||||||
id TEXT,
|
id TEXT,
|
||||||
name TEXT,
|
title TEXT,
|
||||||
year NUMBER,
|
year NUMBER,
|
||||||
poster_path TEXT DEFAULT NULL,
|
poster_path TEXT DEFAULT NULL,
|
||||||
background_path TEXT DEFAULT NULL,
|
background_path TEXT DEFAULT NULL,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class Movie {
|
|||||||
this.release_date = undefined;
|
this.release_date = undefined;
|
||||||
this.summary = undefined;
|
this.summary = undefined;
|
||||||
this.rating = undefined;
|
this.rating = undefined;
|
||||||
this.poster = undefined;
|
this.poster_path = undefined;
|
||||||
this.background = undefined;
|
this.background = undefined;
|
||||||
this.genre = undefined;
|
this.genre = undefined;
|
||||||
this.date_added = undefined;
|
this.date_added = undefined;
|
||||||
|
|||||||
@@ -17,6 +17,15 @@ function convertPlexToSeasoned(plexObject) {
|
|||||||
|
|
||||||
movie.mediaInfo = plexObject.Media;
|
movie.mediaInfo = plexObject.Media;
|
||||||
|
|
||||||
|
// Don't need a for-loop when we have it in json format
|
||||||
|
file_sizes = []
|
||||||
|
for (let movie_info of plexObject.Media) {
|
||||||
|
for (let file_data of movie_info.Part) {
|
||||||
|
file_sizes.push(file_data.size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
movie.size = file_sizes;
|
||||||
|
|
||||||
return movie;
|
return movie;
|
||||||
}
|
}
|
||||||
else if (mediaType === 'show') {
|
else if (mediaType === 'show') {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class PlexRepository {
|
|||||||
|
|
||||||
searchMedia(query) {
|
searchMedia(query) {
|
||||||
var options = {
|
var options = {
|
||||||
uri: 'http://10.0.0.42:32400/search?query=' + query,
|
uri: 'http://10.0.0.44:32400/search?query=' + query,
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
},
|
},
|
||||||
@@ -31,7 +31,7 @@ class PlexRepository {
|
|||||||
|
|
||||||
nowPlaying() {
|
nowPlaying() {
|
||||||
var options = {
|
var options = {
|
||||||
uri: 'http://10.0.0.42:32400/status/sessions',
|
uri: 'http://10.0.0.44:32400/status/sessions',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class RequestRepository {
|
|||||||
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
||||||
'fetchRequstedItems': "SELECT * FROM requests",
|
'fetchRequstedItems': "SELECT * FROM requests",
|
||||||
'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?",
|
'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?",
|
||||||
|
'checkIfIdRequested': "SELECT * FROM requests WHERE id IS ? AND type IS ?",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ class RequestRepository {
|
|||||||
// runnning through the entire plex loop. Many loops, but safe.
|
// runnning through the entire plex loop. Many loops, but safe.
|
||||||
let checkIfMatchesPlexObjects = function(title, year, plexarray) {
|
let checkIfMatchesPlexObjects = function(title, year, plexarray) {
|
||||||
// Iterate all elements in plexarray
|
// Iterate all elements in plexarray
|
||||||
|
console.log(plexArray)
|
||||||
for (let plexItem of plexarray) {
|
for (let plexItem of plexarray) {
|
||||||
// If matches with our title and year return true
|
// If matches with our title and year return true
|
||||||
if (plexItem.title === title && plexItem.year === year)
|
if (plexItem.title === title && plexItem.year === year)
|
||||||
@@ -84,25 +86,68 @@ class RequestRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lookup(identifier, type = 'movie') {
|
lookup(identifier, type = 'movie') {
|
||||||
if (type === 'movie') { type = 'movieInfo'}
|
// console.log('Lookup: ', identifier + ' : ' + type)
|
||||||
else if (type === 'tv') { type = 'tvInfo'}
|
// if (type === 'movie') { type = 'movieInfo'}
|
||||||
|
// else if (type === 'tv') { type = 'tvInfo'}
|
||||||
|
// return Promise.resolve()
|
||||||
|
// .then(() => tmdb.lookup(identifier, type))
|
||||||
|
// .then((tmdbMovie) => {
|
||||||
|
// return Promise.resolve(plexRepository.searchMedia(tmdbMovie.title))
|
||||||
|
// .then((plexMovies) => {
|
||||||
|
// for (var i = 0; i < plexMovies.length; i++) {
|
||||||
|
// if (tmdbMovie.title === plexMovies[i].title && tmdbMovie.year === plexMovies[i].year) {
|
||||||
|
// tmdbMovie.matchedInPlex = true;
|
||||||
|
// return tmdbMovie;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .catch((error) => {
|
||||||
|
// return error;
|
||||||
|
// });
|
||||||
|
// return tmdbMovie;
|
||||||
|
// });
|
||||||
|
let tmdbType = undefined;
|
||||||
|
if (type === 'movie') { tmdbType = 'movieInfo'}
|
||||||
|
else if (type === 'tv') { tmdbType = 'tvInfo'}
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => tmdb.lookup(identifier, type))
|
.then(() => tmdb.lookup(identifier, tmdbType))
|
||||||
|
.then((tmdbMovie) => this.checkID(tmdbMovie))
|
||||||
.then((tmdbMovie) => {
|
.then((tmdbMovie) => {
|
||||||
return Promise.resolve(plexRepository.searchMedia(tmdbMovie.title))
|
return Promise.resolve(plexRepository.searchMedia(tmdbMovie.title))
|
||||||
.then((plexMovies) => {
|
.then((plexMovies) => {
|
||||||
|
console.log('plexMovies lookup: ', plexMovies)
|
||||||
for (var i = 0; i < plexMovies.length; i++) {
|
for (var i = 0; i < plexMovies.length; i++) {
|
||||||
if (tmdbMovie.title === plexMovies[i].title && tmdbMovie.year === plexMovies[i].year) {
|
if (tmdbMovie.title === plexMovies[i].title && tmdbMovie.year === plexMovies[i].year) {
|
||||||
|
console.log('matched')
|
||||||
tmdbMovie.matchedInPlex = true;
|
tmdbMovie.matchedInPlex = true;
|
||||||
return tmdbMovie;
|
return tmdbMovie;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return tmdbMovie;
|
||||||
|
})
|
||||||
|
// Add it here
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('there was a error:', error)
|
||||||
|
return tmdbMovie;
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
return error;
|
console.log(error)
|
||||||
});
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
checkID(tmdbMovie) {
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => this.database.get(this.queries.checkIfIdRequested, [tmdbMovie.id, tmdbMovie.type]))
|
||||||
|
.then((result, error) => {
|
||||||
|
let already_requested = false;
|
||||||
|
if (result)
|
||||||
|
already_requested = true
|
||||||
|
|
||||||
|
tmdbMovie.requested = already_requested;
|
||||||
return tmdbMovie;
|
return tmdbMovie;
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,7 +162,7 @@ class RequestRepository {
|
|||||||
user = 'NULL';
|
user = 'NULL';
|
||||||
console.log(user)
|
console.log(user)
|
||||||
// Add request to database
|
// Add request to database
|
||||||
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, movie.background, user, ip, user_agent, movie.type])
|
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster_path, movie.background_path, user, ip, user_agent, movie.type])
|
||||||
|
|
||||||
|
|
||||||
// create reusable transporter object using the default SMTP transport
|
// create reusable transporter object using the default SMTP transport
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ function convertTmdbToSeasoned(tmdbObject, strictType=undefined) {
|
|||||||
movie.id = tmdbObject.id;
|
movie.id = tmdbObject.id;
|
||||||
movie.summary = tmdbObject.overview;
|
movie.summary = tmdbObject.overview;
|
||||||
movie.rating = tmdbObject.vote_average;
|
movie.rating = tmdbObject.vote_average;
|
||||||
movie.poster = tmdbObject.poster_path;
|
movie.poster_path = tmdbObject.poster_path;
|
||||||
movie.background = tmdbObject.backdrop_path;
|
movie.background_path = tmdbObject.backdrop_path;
|
||||||
movie.genre = tmdbObject.genre_ids;
|
movie.genre = tmdbObject.genre_ids;
|
||||||
|
|
||||||
movie.popularity = tmdbObject.popularity;
|
movie.popularity = tmdbObject.popularity;
|
||||||
@@ -42,8 +42,8 @@ function convertTmdbToSeasoned(tmdbObject, strictType=undefined) {
|
|||||||
show.id = tmdbObject.id;
|
show.id = tmdbObject.id;
|
||||||
show.summary = tmdbObject.overview;
|
show.summary = tmdbObject.overview;
|
||||||
show.rating = tmdbObject.vote_average;
|
show.rating = tmdbObject.vote_average;
|
||||||
show.poster = tmdbObject.poster_path;
|
show.poster_path = tmdbObject.poster_path;
|
||||||
show.background = tmdbObject.backdrop_path;
|
show.background_path = tmdbObject.backdrop_path;
|
||||||
show.genre = tmdbObject.genre_ids;
|
show.genre = tmdbObject.genre_ids;
|
||||||
|
|
||||||
show.popularity = tmdbObject.popularity;
|
show.popularity = tmdbObject.popularity;
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ class TMDB {
|
|||||||
* @returns {Promise} succeeds if movie was found
|
* @returns {Promise} succeeds if movie was found
|
||||||
*/
|
*/
|
||||||
lookup(identifier, queryType = 'movie') {
|
lookup(identifier, queryType = 'movie') {
|
||||||
var type;
|
var type, tmdbType;
|
||||||
if (queryType === 'movie') { type = 'movieInfo'}
|
if (queryType === 'movie' || queryType === 'movieInfo') { type = 'movie', tmdbType = 'movieInfo' }
|
||||||
else if (queryType === 'show') { type = 'tvInfo'}
|
else if (queryType === 'show' || queryType === 'tvInfo') { type = 'show', tmdbType = 'tvInfo' }
|
||||||
else {
|
else {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -89,14 +89,12 @@ class TMDB {
|
|||||||
const cacheKey = `${this.cacheTags.lookup}:${type}:${identifier}`;
|
const cacheKey = `${this.cacheTags.lookup}:${type}:${identifier}`;
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => this.cache.get(cacheKey))
|
.then(() => this.cache.get(cacheKey))
|
||||||
.catch(() => this.tmdb(type, query))
|
.catch(() => this.tmdb(tmdbType, query))
|
||||||
.catch(() => { throw new Error('Could not find a movie with that id.'); })
|
.catch(() => { throw new Error('Could not find a movie with that id.'); })
|
||||||
.then((response) => this.cache.set(cacheKey, response))
|
.then((response) => this.cache.set(cacheKey, response))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
try {
|
try {
|
||||||
var car = convertTmdbToSeasoned(response, queryType);
|
return convertTmdbToSeasoned(response, type);
|
||||||
console.log(car);
|
|
||||||
return car;
|
|
||||||
} catch (parseError) {
|
} catch (parseError) {
|
||||||
throw new Error('Could not parse movie.');
|
throw new Error('Could not parse movie.');
|
||||||
}
|
}
|
||||||
@@ -142,7 +140,6 @@ class TMDB {
|
|||||||
const mappedResults = response.results.map((result) => {
|
const mappedResults = response.results.map((result) => {
|
||||||
return convertTmdbToSeasoned(result, type)
|
return convertTmdbToSeasoned(result, type)
|
||||||
})
|
})
|
||||||
|
|
||||||
return [mappedResults, response.page, response.total_pages]
|
return [mappedResults, response.page, response.total_pages]
|
||||||
})
|
})
|
||||||
.catch((error) => { throw new Error(error)})
|
.catch((error) => { throw new Error(error)})
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ const configuration = require('src/config/configuration').getInstance();
|
|||||||
|
|
||||||
// TODO: Have our raven router check if there is a value, if not don't enable raven.
|
// TODO: Have our raven router check if there is a value, if not don't enable raven.
|
||||||
Raven.config(configuration.get('raven', 'DSN')).install();
|
Raven.config(configuration.get('raven', 'DSN')).install();
|
||||||
|
|
||||||
|
|
||||||
const app = express(); // define our app using express
|
const app = express(); // define our app using express
|
||||||
app.use(Raven.requestHandler());
|
app.use(Raven.requestHandler());
|
||||||
// this will let us get the data from a POST
|
// this will let us get the data from a POST
|
||||||
@@ -18,7 +20,6 @@ app.use(bodyParser.json());
|
|||||||
/* Decode the Authorization header if provided */
|
/* Decode the Authorization header if provided */
|
||||||
// router.use(tokenToUser);
|
// router.use(tokenToUser);
|
||||||
|
|
||||||
const port = 31459; // set our port
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
|
const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ app.use(bodyParser.urlencoded({ extended: true }));
|
|||||||
|
|
||||||
|
|
||||||
// This is probably a correct middleware/router setup
|
// This is probably a correct middleware/router setup
|
||||||
/* Decode the Authorization header if provided */
|
/* Translate the user token to a user name */
|
||||||
router.use(tokenToUser);
|
router.use(tokenToUser);
|
||||||
|
|
||||||
// TODO: Should have a separate middleware/router for handling headers.
|
// TODO: Should have a separate middleware/router for handling headers.
|
||||||
@@ -61,7 +62,7 @@ app.use(function onError(err, req, res, next) {
|
|||||||
*/
|
*/
|
||||||
router.post('/v1/user', require('./controllers/user/register.js'));
|
router.post('/v1/user', require('./controllers/user/register.js'));
|
||||||
router.post('/v1/user/login', require('./controllers/user/login.js'));
|
router.post('/v1/user/login', require('./controllers/user/login.js'));
|
||||||
router.get('/v1/user/history', mustBeAuthenticated, require('./controllers/user/history.js'));
|
router.get('/v1/user/history', require('./controllers/user/history.js'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seasoned
|
* Seasoned
|
||||||
@@ -83,7 +84,7 @@ router.get('/v1/plex/hook', require('./controllers/plex/hookDump.js'));
|
|||||||
/**
|
/**
|
||||||
* Requests
|
* Requests
|
||||||
*/
|
*/
|
||||||
router.get('/v1/plex/requests/all', mustBeAuthenticated, require('./controllers/plex/fetchRequested.js'));
|
router.get('/v1/plex/requests/all', require('./controllers/plex/fetchRequested.js'));
|
||||||
router.put('/v1/plex/request/:requestId', mustBeAuthenticated, require('./controllers/plex/updateRequested.js'));
|
router.put('/v1/plex/request/:requestId', mustBeAuthenticated, require('./controllers/plex/updateRequested.js'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function historyController(req, res) {
|
|||||||
|
|
||||||
requestRepository.fetchRequested()
|
requestRepository.fetchRequested()
|
||||||
.then((requestedItems) => {
|
.then((requestedItems) => {
|
||||||
res.send({ success: true, requestedItems });
|
res.send({ success: true, results: requestedItems, total_results: requestedItems.length });
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
res.status(401).send({ success: false, error: error.message });
|
res.status(401).send({ success: false, error: error.message });
|
||||||
|
|||||||
Reference in New Issue
Block a user