From 0addc761261d24897ed2285dcc53f1e1a47a0f2c Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 9 Jan 2018 23:03:53 +0100 Subject: [PATCH 01/16] Changed the positioning of the type icon in the header and forgot the set the style of the movie info header to the correct css element, this is fixed now. --- client/app/components/admin/AdminRequestInfo.jsx | 2 +- client/app/components/styles/adminRequestInfo.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/app/components/admin/AdminRequestInfo.jsx b/client/app/components/admin/AdminRequestInfo.jsx index a67e7e1..4b10da4 100644 --- a/client/app/components/admin/AdminRequestInfo.jsx +++ b/client/app/components/admin/AdminRequestInfo.jsx @@ -195,7 +195,7 @@ class AdminRequestInfo extends Component {
-

Movie info

+

Movie info

{ this.generateSummary() }
diff --git a/client/app/components/styles/adminRequestInfo.jsx b/client/app/components/styles/adminRequestInfo.jsx index d3a525f..a03e83c 100644 --- a/client/app/components/styles/adminRequestInfo.jsx +++ b/client/app/components/styles/adminRequestInfo.jsx @@ -25,7 +25,7 @@ export default { }, type_icon: { - marginLeft: '-1.9em', + marginLeft: '-0.2em', marginRight: '0.7em', }, type_text: { -- 2.34.1 From 4f98f2fd235f4389f7f6dd15f583e7649082aa86 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 9 Jan 2018 23:08:59 +0100 Subject: [PATCH 02/16] Changed the distance between the search bar and the content to be a little less and added a shadow around the search bar to make it pop a bit more. --- client/app/components/styles/searchRequestStyle.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/app/components/styles/searchRequestStyle.jsx b/client/app/components/styles/searchRequestStyle.jsx index 0700a4e..0702afe 100644 --- a/client/app/components/styles/searchRequestStyle.jsx +++ b/client/app/components/styles/searchRequestStyle.jsx @@ -14,7 +14,7 @@ export default { backgroundColor: 'rgb(1, 28, 35)', // backgroundImage: 'radial-gradient(circle, #004c67 0, #005771 120%)', zIndex: 1, - marginBottom: '80px' + marginBottom: '70px' }, backgroundSmallHeader: { @@ -61,6 +61,7 @@ export default { width: '77%', paddingLeft: '23%', backgroundColor: 'white', + boxShadow: 'grey 0px 1px 2px', }, searchSmallContainer: { -- 2.34.1 From 0b42cf7f129d18d2a0b9393589337cb424919ebd Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 9 Jan 2018 23:12:27 +0100 Subject: [PATCH 03/16] Because the content on the landing page felt static I added a random function to pick between the four list types. --- client/app/components/SearchRequest.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/app/components/SearchRequest.jsx b/client/app/components/SearchRequest.jsx index bdb5098..50e93a4 100644 --- a/client/app/components/SearchRequest.jsx +++ b/client/app/components/SearchRequest.jsx @@ -47,7 +47,7 @@ class SearchRequest extends React.Component { // this.setState({responseMovieList: null}) this.resetPageNumber(); this.state.loadResults = true; - this.fetchTmdbList('discover'); + this.fetchTmdbList(this.allowedListTypes[Math.floor(Math.random()*this.allowedListTypes.length)]); } // Handles all errors of the response of a fetch call -- 2.34.1 From 3639105240bc51409a58d42c21fbd6a3bd2b2807 Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 9 Jan 2018 23:43:32 +0100 Subject: [PATCH 04/16] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0466557..9f50bc6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ [![Build Status](https://travis-ci.org/KevinMidboe/seasonedShows.svg?branch=master)](https://travis-ci.org/KevinMidboe/seasonedShows) [![DUB](https://img.shields.io/dub/l/vibe-d.svg)]() -Your customly *seasoned* movie and show requester, downloader and organizer. +Your customly *seasoned* movie and show requester, downloader and organizer. +Demo can be found [here](https://kevinmidboe.com/request) ## About 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. -- 2.34.1 From 6f6b38c23dc03c95d115d5f4745e18e76626e1ca Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 9 Jan 2018 23:43:44 +0100 Subject: [PATCH 05/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f50bc6..8a8d745 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/KevinMidboe/seasonedShows.svg?branch=master)](https://travis-ci.org/KevinMidboe/seasonedShows) [![DUB](https://img.shields.io/dub/l/vibe-d.svg)]() -Your customly *seasoned* movie and show requester, downloader and organizer. +Your customly *seasoned* movie and show requester, downloader and organizer. Demo can be found [here](https://kevinmidboe.com/request) ## About -- 2.34.1 From c0c958706673b37f9d0a8f8e85e9dc053c18a5f3 Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 9 Jan 2018 23:45:01 +0100 Subject: [PATCH 06/16] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a8d745..300c84b 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ [![Build Status](https://travis-ci.org/KevinMidboe/seasonedShows.svg?branch=master)](https://travis-ci.org/KevinMidboe/seasonedShows) [![DUB](https://img.shields.io/dub/l/vibe-d.svg)]() -Your customly *seasoned* movie and show requester, downloader and organizer. -Demo can be found [here](https://kevinmidboe.com/request) +Your customly *seasoned* movie and show requester, downloader and organizer. Demo page can be viewed [here](https://kevinmidboe.com/request) ## About 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. -- 2.34.1 From 0c3ad3a95e51dc2e95bf6a4fbdd19200f9a0956a Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Fri, 2 Feb 2018 11:51:13 +0100 Subject: [PATCH 07/16] Fixed a issue where the tmdb type was not being selected correctly. (movie/show) --- seasoned_api/src/tmdb/tmdb.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/seasoned_api/src/tmdb/tmdb.js b/seasoned_api/src/tmdb/tmdb.js index 0b55829..3ef3716 100644 --- a/seasoned_api/src/tmdb/tmdb.js +++ b/seasoned_api/src/tmdb/tmdb.js @@ -76,9 +76,9 @@ class TMDB { * @returns {Promise} succeeds if movie was found */ lookup(identifier, queryType = 'movie') { - var type; - if (queryType === 'movie') { type = 'movieInfo'} - else if (queryType === 'show') { type = 'tvInfo'} + var type, tmdbType; + if (queryType === 'movie' || queryType === 'movieInfo') { type = 'movie', tmdbType = 'movieInfo' } + else if (queryType === 'show' || queryType === 'tvInfo') { type = 'show', tmdbType = 'tvInfo' } else { return Promise.resolve() .then(() => { @@ -89,14 +89,12 @@ class TMDB { const cacheKey = `${this.cacheTags.lookup}:${type}:${identifier}`; return Promise.resolve() .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.'); }) .then((response) => this.cache.set(cacheKey, response)) .then((response) => { try { - var car = convertTmdbToSeasoned(response, queryType); - console.log(car); - return car; + return convertTmdbToSeasoned(response, type); } catch (parseError) { throw new Error('Could not parse movie.'); } @@ -142,7 +140,6 @@ class TMDB { const mappedResults = response.results.map((result) => { return convertTmdbToSeasoned(result, type) }) - return [mappedResults, response.page, response.total_pages] }) .catch((error) => { throw new Error(error)}) -- 2.34.1 From bd0c7b8ab52a0d61a2476b18855c27ac3ea0c238 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 5 Feb 2018 13:41:41 +0100 Subject: [PATCH 08/16] Now also has size of the existing file. --- seasoned_api/src/media_classes/movie.js | 4 ++-- seasoned_api/src/plex/convertPlexToSeasoned.js | 11 ++++++++++- seasoned_api/src/tmdb/convertTmdbToSeasoned.js | 8 ++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/seasoned_api/src/media_classes/movie.js b/seasoned_api/src/media_classes/movie.js index 19063ad..98eb2ee 100644 --- a/seasoned_api/src/media_classes/movie.js +++ b/seasoned_api/src/media_classes/movie.js @@ -7,7 +7,7 @@ class Movie { this.release_date = undefined; this.summary = undefined; this.rating = undefined; - this.poster = undefined; + this.poster_path = undefined; this.background = undefined; this.genre = undefined; this.date_added = undefined; @@ -18,4 +18,4 @@ class Movie { } } -module.exports = Movie; \ No newline at end of file +module.exports = Movie; diff --git a/seasoned_api/src/plex/convertPlexToSeasoned.js b/seasoned_api/src/plex/convertPlexToSeasoned.js index 6d0ad14..026b2f1 100644 --- a/seasoned_api/src/plex/convertPlexToSeasoned.js +++ b/seasoned_api/src/plex/convertPlexToSeasoned.js @@ -17,6 +17,15 @@ function convertPlexToSeasoned(plexObject) { 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; } else if (mediaType === 'show') { @@ -36,4 +45,4 @@ function convertPlexToSeasoned(plexObject) { } } -module.exports = convertPlexToSeasoned; \ No newline at end of file +module.exports = convertPlexToSeasoned; diff --git a/seasoned_api/src/tmdb/convertTmdbToSeasoned.js b/seasoned_api/src/tmdb/convertTmdbToSeasoned.js index 1643e8d..c5ced79 100644 --- a/seasoned_api/src/tmdb/convertTmdbToSeasoned.js +++ b/seasoned_api/src/tmdb/convertTmdbToSeasoned.js @@ -25,8 +25,8 @@ function convertTmdbToSeasoned(tmdbObject, strictType=undefined) { movie.id = tmdbObject.id; movie.summary = tmdbObject.overview; movie.rating = tmdbObject.vote_average; - movie.poster = tmdbObject.poster_path; - movie.background = tmdbObject.backdrop_path; + movie.poster_path = tmdbObject.poster_path; + movie.background_path = tmdbObject.backdrop_path; movie.genre = tmdbObject.genre_ids; movie.popularity = tmdbObject.popularity; @@ -42,8 +42,8 @@ function convertTmdbToSeasoned(tmdbObject, strictType=undefined) { show.id = tmdbObject.id; show.summary = tmdbObject.overview; show.rating = tmdbObject.vote_average; - show.poster = tmdbObject.poster_path; - show.background = tmdbObject.backdrop_path; + show.poster_path = tmdbObject.poster_path; + show.background_path = tmdbObject.backdrop_path; show.genre = tmdbObject.genre_ids; show.popularity = tmdbObject.popularity; -- 2.34.1 From 89ec9d496b65cdb91eccec5acd6c48dc543b52da Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 5 Feb 2018 13:42:35 +0100 Subject: [PATCH 09/16] Changed the ip addres of plex server --- seasoned_api/src/plex/plexRepository.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seasoned_api/src/plex/plexRepository.js b/seasoned_api/src/plex/plexRepository.js index aebaf9a..db3b752 100644 --- a/seasoned_api/src/plex/plexRepository.js +++ b/seasoned_api/src/plex/plexRepository.js @@ -7,7 +7,7 @@ class PlexRepository { searchMedia(query) { var options = { - uri: 'http://10.0.0.42:32400/search?query=' + query, + uri: 'http://10.0.0.44:32400/search?query=' + query, headers: { 'Accept': 'application/json' }, @@ -31,7 +31,7 @@ class PlexRepository { nowPlaying() { var options = { - uri: 'http://10.0.0.42:32400/status/sessions', + uri: 'http://10.0.0.44:32400/status/sessions', headers: { 'Accept': 'application/json' }, -- 2.34.1 From cefbb5e41cbf7c93ef7f9f4c85e90b96127fb522 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 5 Feb 2018 13:44:13 +0100 Subject: [PATCH 10/16] Added length of elements in return statement as total_results in api response. --- seasoned_api/src/webserver/controllers/plex/fetchRequested.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seasoned_api/src/webserver/controllers/plex/fetchRequested.js b/seasoned_api/src/webserver/controllers/plex/fetchRequested.js index e8250f8..673e306 100644 --- a/seasoned_api/src/webserver/controllers/plex/fetchRequested.js +++ b/seasoned_api/src/webserver/controllers/plex/fetchRequested.js @@ -13,7 +13,7 @@ function historyController(req, res) { requestRepository.fetchRequested() .then((requestedItems) => { - res.send({ success: true, requestedItems }); + res.send({ success: true, results: requestedItems, total_results: requestedItems.length }); }) .catch((error) => { res.status(401).send({ success: false, error: error.message }); -- 2.34.1 From cfedd4e9c815bef65ea88e586e886da0e82e729e Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 5 Feb 2018 13:47:10 +0100 Subject: [PATCH 11/16] Added ability to check if a element is previously been requested. Also changed the schema of db to store movies poster as poster_path and background as background_path. --- seasoned_api/src/plex/requestRepository.js | 61 +++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index ffddd12..1ebb789 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -25,6 +25,7 @@ class RequestRepository { 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)", 'fetchRequstedItems': "SELECT * FROM requests", '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. let checkIfMatchesPlexObjects = function(title, year, plexarray) { // Iterate all elements in plexarray + console.log(plexArray) for (let plexItem of plexarray) { // If matches with our title and year return true if (plexItem.title === title && plexItem.year === year) @@ -84,25 +86,72 @@ class RequestRepository { } lookup(identifier, type = 'movie') { - if (type === 'movie') { type = 'movieInfo'} +// console.log('Lookup: ', identifier + ' : ' + type) +// 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; +// }); + 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) => { + console.log('plexMovies lookup: ', plexMovies) for (var i = 0; i < plexMovies.length; i++) { if (tmdbMovie.title === plexMovies[i].title && tmdbMovie.year === plexMovies[i].year) { + console.log('matched') tmdbMovie.matchedInPlex = true; return tmdbMovie; } } }) + // Add it here .catch((error) => { - return error; - }); + console.log('there was a error:', error) + return tmdbMovie; + }) return tmdbMovie; - }); + }) + .catch((error) => { + console.log(error) + }) + .then((item) => { + return this.checkID(item.id, item.type) + .then((result) => { + item.requested = result; + return item + }) + }) + } + + checkID(id, type) { + return this.database.get(this.queries.checkIfIdRequested, [id, type]) + .then((result, error) => { + if (error) return false + + if (result) + return true + else + return false + }) + } /** @@ -117,7 +166,7 @@ class RequestRepository { user = 'NULL'; console.log(user) // 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 @@ -171,4 +220,4 @@ class RequestRepository { } -module.exports = RequestRepository; \ No newline at end of file +module.exports = RequestRepository; -- 2.34.1 From eedfe4cf3f688202ac7563f2813ffdacbbdf7576 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 5 Feb 2018 13:48:16 +0100 Subject: [PATCH 12/16] Changed schema to reflect changes movie title from name to title. --- seasoned_api/src/database/schemas/setup.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seasoned_api/src/database/schemas/setup.sql b/seasoned_api/src/database/schemas/setup.sql index 5d9d8fd..9b54acd 100644 --- a/seasoned_api/src/database/schemas/setup.sql +++ b/seasoned_api/src/database/schemas/setup.sql @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS search_history ( CREATE TABLE IF NOT EXISTS requests( id TEXT, - name TEXT, + title TEXT, year NUMBER, poster_path TEXT DEFAULT NULL, background_path TEXT DEFAULT NULL, @@ -54,4 +54,4 @@ CREATE TABLE IF NOT EXISTS shows( show_names TEXT, date_added DATE, date_modified DATE DEFUALT CURRENT_DATE NOT NULL -); \ No newline at end of file +); -- 2.34.1 From 77d7167fcbc7be3acdb6fd28c3e9a6363d15c22d Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 5 Feb 2018 14:22:44 +0100 Subject: [PATCH 13/16] Changed so that one must not be auth to get requested elements. This might change. --- seasoned_api/src/webserver/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seasoned_api/src/webserver/app.js b/seasoned_api/src/webserver/app.js index 6b4d888..505667a 100644 --- a/seasoned_api/src/webserver/app.js +++ b/seasoned_api/src/webserver/app.js @@ -61,7 +61,7 @@ app.use(function onError(err, req, res, next) { */ router.post('/v1/user', require('./controllers/user/register.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 @@ -83,7 +83,7 @@ router.get('/v1/plex/hook', require('./controllers/plex/hookDump.js')); /** * 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')); /** -- 2.34.1 From 80582f00223648502deadd67d2dbab3662268b6a Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 5 Feb 2018 14:23:40 +0100 Subject: [PATCH 14/16] Changed so that tmdb now gets its own type, tmdbtype --- seasoned_api/src/plex/requestRepository.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index 1ebb789..ed392bf 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -106,10 +106,11 @@ class RequestRepository { // }); // return tmdbMovie; // }); - if (type === 'movie') { type = 'movieInfo'} - else if (type === 'tv') { type = 'tvInfo'} + let tmdbType = undefined; + if (type === 'movie') { tmdbType = 'movieInfo'} + else if (type === 'tv') { tmdbType = 'tvInfo'} return Promise.resolve() - .then(() => tmdb.lookup(identifier, type)) + .then(() => tmdb.lookup(identifier, tmdbType)) .then((tmdbMovie) => { return Promise.resolve(plexRepository.searchMedia(tmdbMovie.title)) .then((plexMovies) => { -- 2.34.1 From 9b0fa88a72667f75a6d39607892a396f0dea5644 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Mon, 5 Feb 2018 14:25:13 +0100 Subject: [PATCH 15/16] Changed docstring and removed the unused port variable. --- seasoned_api/src/webserver/app.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/seasoned_api/src/webserver/app.js b/seasoned_api/src/webserver/app.js index 6b4d888..71b0225 100644 --- a/seasoned_api/src/webserver/app.js +++ b/seasoned_api/src/webserver/app.js @@ -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. Raven.config(configuration.get('raven', 'DSN')).install(); + + const app = express(); // define our app using express app.use(Raven.requestHandler()); // this will let us get the data from a POST @@ -18,7 +20,6 @@ app.use(bodyParser.json()); /* Decode the Authorization header if provided */ // router.use(tokenToUser); -const port = 31459; // set our port const router = express.Router(); 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 -/* Decode the Authorization header if provided */ +/* Translate the user token to a user name */ router.use(tokenToUser); // TODO: Should have a separate middleware/router for handling headers. -- 2.34.1 From cfb878fa64c7678c47a88142013025c0a78d77f4 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Mon, 5 Feb 2018 14:55:49 +0100 Subject: [PATCH 16/16] Fixed issue where a item would not be returned when nothing was found matching query in plex. Also moved checkId up in the request. --- seasoned_api/src/plex/requestRepository.js | 25 +++++++++------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index ed392bf..6ef1072 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -111,6 +111,7 @@ class RequestRepository { else if (type === 'tv') { tmdbType = 'tvInfo'} return Promise.resolve() .then(() => tmdb.lookup(identifier, tmdbType)) + .then((tmdbMovie) => this.checkID(tmdbMovie)) .then((tmdbMovie) => { return Promise.resolve(plexRepository.searchMedia(tmdbMovie.title)) .then((plexMovies) => { @@ -122,35 +123,29 @@ class RequestRepository { return tmdbMovie; } } + return tmdbMovie; }) // Add it here .catch((error) => { console.log('there was a error:', error) return tmdbMovie; }) - return tmdbMovie; }) .catch((error) => { console.log(error) }) - .then((item) => { - return this.checkID(item.id, item.type) - .then((result) => { - item.requested = result; - return item - }) - }) } - checkID(id, type) { - return this.database.get(this.queries.checkIfIdRequested, [id, type]) + checkID(tmdbMovie) { + return Promise.resolve() + .then(() => this.database.get(this.queries.checkIfIdRequested, [tmdbMovie.id, tmdbMovie.type])) .then((result, error) => { - if (error) return false - + let already_requested = false; if (result) - return true - else - return false + already_requested = true + + tmdbMovie.requested = already_requested; + return tmdbMovie; }) } -- 2.34.1