From 51d446f378d235e3393cdfcb0c3daf138152869d Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 6 Oct 2017 15:02:44 +0200 Subject: [PATCH 01/16] Added endpoint for updating a requested item. --- seasoned_api/src/webserver/app.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/seasoned_api/src/webserver/app.js b/seasoned_api/src/webserver/app.js index be30da7..7cc1a67 100644 --- a/seasoned_api/src/webserver/app.js +++ b/seasoned_api/src/webserver/app.js @@ -67,7 +67,11 @@ router.get('/v1/plex/request/:mediaId', require('./controllers/plex/readRequest. router.post('/v1/plex/request/:mediaId', require('./controllers/plex/submitRequest.js')); router.get('/v1/plex/hook', require('./controllers/plex/hookDump.js')); +/** + * Requests + */ router.get('/v1/plex/requests/all', mustBeAuthenticated, require('./controllers/plex/fetchRequested.js')); +router.put('/v1/plex/request/:requestId', mustBeAuthenticated, require('./controllers/plex/updateRequested.js')); /** * TMDB -- 2.34.1 From 61c242b5eb6074669bb34911889cf8e8ec7a9ff1 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 6 Oct 2017 15:03:47 +0200 Subject: [PATCH 02/16] Passes the id from request parameter and status we want to change to from the request body. --- .../controllers/plex/updateRequested.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 seasoned_api/src/webserver/controllers/plex/updateRequested.js diff --git a/seasoned_api/src/webserver/controllers/plex/updateRequested.js b/seasoned_api/src/webserver/controllers/plex/updateRequested.js new file mode 100644 index 0000000..4573501 --- /dev/null +++ b/seasoned_api/src/webserver/controllers/plex/updateRequested.js @@ -0,0 +1,23 @@ +const RequestRepository = require('src/searchHistory/searchHistory'); +const requestRepository = new RequestRepository(); + +/** + * Controller: Retrieves search history of a logged in user + * @param {Request} req http request variable + * @param {Response} res + * @returns {Callback} + */ +function updateRequested(req, res) { + const id = req.params.requestId; + const status = req.body.status; + + requestRepository.updateRequested(id, status) + .then(() => { + res.send({ success: true }); + }) + .catch((error) => { + res.status(401).send({ success: false, error: error.message }); + }); +} + +module.exports = updateRequested; -- 2.34.1 From f54bd0f74379b10b0928e4a64cd5ffb4f802d0af Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 6 Oct 2017 15:04:18 +0200 Subject: [PATCH 03/16] Added a function for updating the status from a given id in requests database. --- seasoned_api/src/plex/requestRepository.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index ee05bde..1a177f6 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -22,6 +22,7 @@ class RequestRepository { this.queries = { 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)", 'fetchRequstedItems': "SELECT * FROM requests", + 'updateRequested': "UPDATE stray_eps SET status = '?' WHERE id is '?'", } } @@ -167,6 +168,10 @@ class RequestRepository { return this.database.all(this.queries.fetchRequstedItems); } + updateRequested(id, status) { + this.database.run(this.queries.updateRequested, [status, id]); + } + } module.exports = RequestRepository; \ No newline at end of file -- 2.34.1 From ac38dacedd213fa13020f0e2548d394aec84e774 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 6 Oct 2017 15:04:50 +0200 Subject: [PATCH 04/16] Changed database table name. --- seasoned_api/src/plex/requestRepository.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index 1a177f6..f940a4d 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -22,7 +22,7 @@ class RequestRepository { this.queries = { 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)", 'fetchRequstedItems': "SELECT * FROM requests", - 'updateRequested': "UPDATE stray_eps SET status = '?' WHERE id is '?'", + 'updateRequested': "UPDATE requests SET status = '?' WHERE id is '?'", } } -- 2.34.1 From fb479e7a3710811ee96e4966eaad2d8ea6a6a3c5 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 6 Oct 2017 15:14:31 +0200 Subject: [PATCH 05/16] Renamed function in requestRepo to updateRequestedById --- seasoned_api/src/plex/requestRepository.js | 6 +++--- .../src/webserver/controllers/plex/updateRequested.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index f940a4d..1212e56 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -22,7 +22,7 @@ class RequestRepository { this.queries = { 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)", 'fetchRequstedItems': "SELECT * FROM requests", - 'updateRequested': "UPDATE requests SET status = '?' WHERE id is '?'", + 'updateRequestedById': "UPDATE requests SET status = '?' WHERE id is '?'", } } @@ -168,8 +168,8 @@ class RequestRepository { return this.database.all(this.queries.fetchRequstedItems); } - updateRequested(id, status) { - this.database.run(this.queries.updateRequested, [status, id]); + updateRequestedById(id, status) { + this.database.run(this.queries.updateRequestedById, [status, id]); } } diff --git a/seasoned_api/src/webserver/controllers/plex/updateRequested.js b/seasoned_api/src/webserver/controllers/plex/updateRequested.js index 4573501..4b92047 100644 --- a/seasoned_api/src/webserver/controllers/plex/updateRequested.js +++ b/seasoned_api/src/webserver/controllers/plex/updateRequested.js @@ -11,7 +11,7 @@ function updateRequested(req, res) { const id = req.params.requestId; const status = req.body.status; - requestRepository.updateRequested(id, status) + requestRepository.updateRequestedById(id, status) .then(() => { res.send({ success: true }); }) -- 2.34.1 From 650c2603e45cea99700254321e3870950bd70154 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 6 Oct 2017 15:16:45 +0200 Subject: [PATCH 06/16] Changed the input path of requestRepo --- seasoned_api/src/webserver/controllers/plex/updateRequested.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seasoned_api/src/webserver/controllers/plex/updateRequested.js b/seasoned_api/src/webserver/controllers/plex/updateRequested.js index 4b92047..5a7339f 100644 --- a/seasoned_api/src/webserver/controllers/plex/updateRequested.js +++ b/seasoned_api/src/webserver/controllers/plex/updateRequested.js @@ -1,4 +1,4 @@ -const RequestRepository = require('src/searchHistory/searchHistory'); +const RequestRepository = require('src/plex/requestRepository'); const requestRepository = new RequestRepository(); /** -- 2.34.1 From 3c372aab92e6118d42c8616fff2f4530636ebe8d Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 6 Oct 2017 15:19:08 +0200 Subject: [PATCH 07/16] Added returnstatement to updateRequestedById and fixed the sql query. --- seasoned_api/src/plex/requestRepository.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index 1212e56..40c511f 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -22,7 +22,7 @@ class RequestRepository { this.queries = { 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)", 'fetchRequstedItems': "SELECT * FROM requests", - 'updateRequestedById': "UPDATE requests SET status = '?' WHERE id is '?'", + 'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ?", } } @@ -169,7 +169,7 @@ class RequestRepository { } updateRequestedById(id, status) { - this.database.run(this.queries.updateRequestedById, [status, id]); + return this.database.run(this.queries.updateRequestedById, [status, id]); } } -- 2.34.1 From 307a8352a3abbcbb926d2c5a27ab440624f13244 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 6 Oct 2017 15:37:09 +0200 Subject: [PATCH 08/16] Now takes both id and type because there is two different sets of id pools, and need to select the corrent one. --- seasoned_api/src/plex/requestRepository.js | 6 +++--- .../src/webserver/controllers/plex/updateRequested.js | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index 40c511f..76b5109 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -22,7 +22,7 @@ class RequestRepository { this.queries = { 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)", 'fetchRequstedItems': "SELECT * FROM requests", - 'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ?", + 'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?", } } @@ -168,8 +168,8 @@ class RequestRepository { return this.database.all(this.queries.fetchRequstedItems); } - updateRequestedById(id, status) { - return this.database.run(this.queries.updateRequestedById, [status, id]); + updateRequestedById(id, type, status) { + return this.database.run(this.queries.updateRequestedById, [status, id, type]); } } diff --git a/seasoned_api/src/webserver/controllers/plex/updateRequested.js b/seasoned_api/src/webserver/controllers/plex/updateRequested.js index 5a7339f..57b2638 100644 --- a/seasoned_api/src/webserver/controllers/plex/updateRequested.js +++ b/seasoned_api/src/webserver/controllers/plex/updateRequested.js @@ -9,9 +9,10 @@ const requestRepository = new RequestRepository(); */ function updateRequested(req, res) { const id = req.params.requestId; + const type = req.body.type; const status = req.body.status; - requestRepository.updateRequestedById(id, status) + requestRepository.updateRequestedById(id, type, status) .then(() => { res.send({ success: true }); }) -- 2.34.1 From d9a22f506e2ae52248d0480723e59b6d691edeec Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 6 Oct 2017 15:38:22 +0200 Subject: [PATCH 09/16] When posting a request, the type is also added to the database. --- seasoned_api/src/plex/requestRepository.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index 76b5109..97e5c37 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -20,7 +20,7 @@ class RequestRepository { constructor(database) { this.database = database || establishedDatabase; this.queries = { - 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)", + 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)", 'fetchRequstedItems': "SELECT * FROM requests", 'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?", } @@ -117,7 +117,7 @@ class RequestRepository { tmdb.lookup(identifier, type).then(movie => { // Add request to database - this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, 'NULL', ip, user_agent]) + this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, 'NULL', ip, user_agent, movie.type]) // -- 2.34.1 From 42d0b40825072008cba6825eec20a7e4708b5749 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sat, 7 Oct 2017 14:52:49 +0200 Subject: [PATCH 10/16] Does not fit on this branch, but updated the key value, so it is concat of both id and index of the map function for search results. It was prev just the index, and when rapped this hits same value, which is unacceptable by react. --- client/app/components/FetchRequested.jsx | 10 ++++++++-- client/app/components/MovieObject.jsx | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/app/components/FetchRequested.jsx b/client/app/components/FetchRequested.jsx index 568a526..d565bd7 100644 --- a/client/app/components/FetchRequested.jsx +++ b/client/app/components/FetchRequested.jsx @@ -31,9 +31,14 @@ class RequestElement extends React.Component { createHTMLElement(data, index) { var posterPath = 'https://image.tmdb.org/t/p/w300' + data.image_path; - if (data.user_agent !== null) { + if (data.user_agent) { var user_agent = data.user_agent.split(" "); - var agent_shortened = user_agent[1].replace(/[\(\;]/g, '') + + console.log(data.user_agent.substring('Mozilla')) + if (data.user_agent.includes('Mozilla')) + var agent_shortened = user_agent[1].replace(/[\(\;]/g, ''); + else + var agent_shortened = user_agent[0]; } return ( @@ -42,6 +47,7 @@ class RequestElement extends React.Component {
Name: {data.name} Year: {data.year}

+ Type: {data.type}

Status: {data.status}

Address: {data.ip}

Requested Data: {data.requested_date}

diff --git a/client/app/components/MovieObject.jsx b/client/app/components/MovieObject.jsx index e114900..152b004 100644 --- a/client/app/components/MovieObject.jsx +++ b/client/app/components/MovieObject.jsx @@ -35,6 +35,8 @@ class MovieObject { } getElement(index) { + const element_key = index + this.id; + // TODO set the poster image async by updating the dom after this is returned if (this.poster == null || this.poster == undefined) { var posterPath = 'https://openclipart.org/image/2400px/svg_to_png/211479/Simple-Image-Not-Found-Icon.png' @@ -60,7 +62,7 @@ class MovieObject { return ( -
+
-- 2.34.1 From 45a84cbf85ff8b482d8bb1004d4dfa1526a96016 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 20 Oct 2017 17:20:43 +0200 Subject: [PATCH 11/16] The admin page that has all the fetched elements now prints all the elements out in a grid. Tried a cool thing on how to render the dropdown for changing the status of a element, but its not working atm. --- client/app/components/FetchRequested.jsx | 121 ++++++++++++++++++++--- 1 file changed, 108 insertions(+), 13 deletions(-) diff --git a/client/app/components/FetchRequested.jsx b/client/app/components/FetchRequested.jsx index d565bd7..6683eae 100644 --- a/client/app/components/FetchRequested.jsx +++ b/client/app/components/FetchRequested.jsx @@ -4,16 +4,50 @@ import requestElement from './styles/requestElementStyle.jsx' import { getCookie } from './Cookie.jsx'; +class DropdownList extends React.Component { + constructor(props) { + super(props); + this.state = { + filter: ['all', 'requested', 'downloading', 'downloaded'], + sort: ['requested_date', 'name', 'status', 'requested_by', 'ip', 'user_agent'], + status: ['requested', 'downloading', 'downloaded'], + } + } + + render() { + const {elementType, elementId, elementStatus, elementCallback, props} = this.props; + + console.log(elementCallback('downloaded')) + + switch (elementType) { + case 'status': + return ( +
HERE
+ ) + } + + return ( +
+ +
+ ); + } +} + class RequestElement extends React.Component { constructor(props) { super(props); - this.default_requestList = null; + this.state = { + dropDownState: undefined, + } } filterRequestList(requestList, filter) { if (filter === 'all') return requestList + if (filter === 'movie' || filter === 'show') + return requestList.filter(item => item.type === filter) return requestList.filter(item => item.status === filter) } @@ -28,32 +62,91 @@ class RequestElement extends React.Component { requestList.reverse(); } + userAgent(agent) { + if (agent) { + try { + return agent.split(" ")[1].replace(/[\(\;]/g, ''); + } + catch(e) { + return agent; + } + } + return ''; + } + + updateDropDownState(status) { + if (status !== this.dropDownState) { + this.dropDownState = status; + } + } + + + ItemsStatusDropdown(id, type, status) { + return ( +
+ + + +
+ ) + } + + updateRequestedItem(id, type) { + console.log(id, type, this.dropDownState); + Promise.resolve() + fetch('https://apollo.kevinmidboe.com/api/v1/plex/request/' + id, { + method: 'PUT', + headers: { + 'Content-type': 'application/json', + 'authorization': getCookie('token') + }, + body: JSON.stringify({ + type: type, + status: this.dropDownState, + }) + }) + .then(response => { + if (response.status !== 200) { + console.log('error'); + } + + response.json() + .then(data => { + if (data.success === true) { + console.log('UPDATED :', id, ' with ', this.dropDownState) + } + }) + }) + .catch(error => { + new Error(error); + }) + } + createHTMLElement(data, index) { var posterPath = 'https://image.tmdb.org/t/p/w300' + data.image_path; - - if (data.user_agent) { - var user_agent = data.user_agent.split(" "); - - console.log(data.user_agent.substring('Mozilla')) - if (data.user_agent.includes('Mozilla')) - var agent_shortened = user_agent[1].replace(/[\(\;]/g, ''); - else - var agent_shortened = user_agent[0]; - } return (
- Name: {data.name} + Name: {data.name}

Year: {data.year}

Type: {data.type}

Status: {data.status}

Address: {data.ip}

Requested Data: {data.requested_date}

Requested By: {data.requested_by}

- Agent: {agent_shortened}

+ Agent: { this.userAgent(data.user_agent) }

+ + { this.ItemsStatusDropdown(data.id, data.type, data.status) }
) } @@ -144,6 +237,8 @@ class FetchRequested extends React.Component { + +