From 362e5f54d10f0776180c134ba0a94169cb7c58fb Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 28 Nov 2017 20:58:45 +0100 Subject: [PATCH 01/10] Added react-interactive package to make it easier to handle hover and focus on mobile. --- client/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/client/package.json b/client/package.json index 7d36795..f166ff8 100644 --- a/client/package.json +++ b/client/package.json @@ -19,6 +19,7 @@ "react-burger-menu": "^2.1.6", "react-dom": "^15.5.4", "react-infinite-scroller": "^1.0.15", + "react-interactive": "^0.8.1", "react-notify-toast": "^0.3.2", "react-redux": "^5.0.6", "react-responsive": "^1.3.4", -- 2.34.1 From 62b6f5c8ca6935a87dc4a595434c3114e804cda9 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 28 Nov 2017 21:02:25 +0100 Subject: [PATCH 02/10] Using react-interactive we now have hover animations for our buttons. --- client/app/components/MovieObject.jsx | 42 ++++++++++++++++--- .../components/styles/movieObjectStyle.jsx | 15 ++++++- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/client/app/components/MovieObject.jsx b/client/app/components/MovieObject.jsx index 64ea04c..d78747e 100644 --- a/client/app/components/MovieObject.jsx +++ b/client/app/components/MovieObject.jsx @@ -11,6 +11,9 @@ import RequestButton from './buttons/request_button.jsx'; import { fetchJSON } from './http.jsx'; +import Interactive from 'react-interactive'; + + class MovieObject { constructor(object) { this.id = object.id; @@ -42,6 +45,13 @@ class MovieObject { notify.show(this.title + ' requested!', 'success', 3000); } + invertButtonColors(event) { + const event_type = event.type; + if (event_type) + console.log('test') + console.log(event.type) + } + getElement(index) { const element_key = index + this.id; @@ -55,11 +65,26 @@ class MovieObject { var foundInPlex; if (this.matchedInPlex) { - foundInPlex = ; + foundInPlex = {this.requestExisting(this)}} + style={movieStyle.requestButton}> + + Request Anyway + ; } else { - foundInPlex = ; + foundInPlex = {this.requestMovie()}} + onMouseOver={() => {this.invertButtonColors(event)}} + style={movieStyle.requestButton}> + + + Request + ; } if (this.type === 'movie') @@ -105,7 +130,14 @@ class MovieObject {
{foundInPlex} - + + + Info +
diff --git a/client/app/components/styles/movieObjectStyle.jsx b/client/app/components/styles/movieObjectStyle.jsx index 627d7dd..c16a89f 100644 --- a/client/app/components/styles/movieObjectStyle.jsx +++ b/client/app/components/styles/movieObjectStyle.jsx @@ -62,8 +62,9 @@ export default { requestButton: { color: '#e9a131', marginRight: '10px', - background: 'white', + backgroundColor: 'white', border: '#e9a131 2px solid', + borderColor: '#e9a131', borderRadius: '4px', textAlign: 'center', padding: '10px', @@ -74,10 +75,15 @@ export default { cursor: 'pointer' }, + requestButton_hover: { + backgroundColor: '#e9a131', + color: 'white', + }, + tmdbButton: { color: '#00d17c', marginRight: '10px', - background: 'white', + backgroundColor: 'white', border: '#00d17c 2px solid', borderRadius: '4px', textAlign: 'center', @@ -89,6 +95,11 @@ export default { cursor: 'pointer' }, + tmdbButton_hover: { + backgroundColor: '#00d17c', + color: 'white', + }, + row: { width: '100%' }, -- 2.34.1 From 57658f10c148c6cddc84bdd209ea4976aeff4106 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 28 Nov 2017 22:25:06 +0100 Subject: [PATCH 03/10] Used the wrong shows.db. Now corrected. --- .gitignore | 1 + seasoned_api/.gitignore | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 53ffa91..e85cd5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store env +shows.db yarn.lock */yarn.lock diff --git a/seasoned_api/.gitignore b/seasoned_api/.gitignore index 922c3ee..9f7246b 100644 --- a/seasoned_api/.gitignore +++ b/seasoned_api/.gitignore @@ -60,5 +60,4 @@ typings/ # - - - - - # My own gitignore files and folders -shows.db conf -- 2.34.1 From 2b772e30170a594d81ee9c7648b1bb618fc40fc0 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 1 Dec 2017 10:14:22 +0100 Subject: [PATCH 04/10] Long overdue, now we define our database schema so we can finally build our database, and not just move it around. --- seasoned_api/src/database/schema/setup.sql | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 seasoned_api/src/database/schema/setup.sql diff --git a/seasoned_api/src/database/schema/setup.sql b/seasoned_api/src/database/schema/setup.sql new file mode 100644 index 0000000..5d9d8fd --- /dev/null +++ b/seasoned_api/src/database/schema/setup.sql @@ -0,0 +1,57 @@ +CREATE TABLE IF NOT EXISTS user ( + user_name varchar(127) UNIQUE, + password varchar(127), + email varchar(127) UNIQUE, + primary key (user_name) +); + +CREATE TABLE IF NOT EXISTS cache ( + key varchar(255), + value blob, + time_to_live INTEGER DEFAULT 60, + created_at DATE DEFAULT (datetime('now','localtime')), + primary key(key) +); + +CREATE TABLE IF NOT EXISTS search_history ( + id integer, + user_name varchar(127), + search_query varchar(255), + primary key (id), + foreign key(user_name) REFERENCES user(user_name) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS requests( + id TEXT, + name TEXT, + year NUMBER, + poster_path TEXT DEFAULT NULL, + background_path TEXT DEFAULT NULL, + requested_by TEXT, + ip TEXT, + requested_date DATE DEFAULT CURRENT_DATE NOT NULL, + status CHAR(25) DEFAULT 'requested' NOT NULL, + user_agent CHAR(255) DEFAULT NULL, + type CHAR(50) DEFAULT 'movie' +); + + +CREATE TABLE IF NOT EXISTS stray_eps( + id TEXT UNIQUE, + parent TEXT, + path TEXT, + name TEXT, + season NUMBER, + episode NUMBER, + video_files TEXT, + subtitles TEXT, + trash TEXT, + verified BOOLEAN DEFAULT 0, + primary key(id) +); + +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 ac6bbe6ac66d752fa204ba0a42a76e155dfae117 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 1 Dec 2017 10:19:22 +0100 Subject: [PATCH 05/10] Now we can build or database by reading schema files. Also added doc strings to all the functions. This is a much better definition of a database script for our usecases.. --- seasoned_api/src/database/sqliteDatabase.js | 88 ++++++++++++++++----- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/seasoned_api/src/database/sqliteDatabase.js b/seasoned_api/src/database/sqliteDatabase.js index 3d0c5a4..5ac1330 100644 --- a/seasoned_api/src/database/sqliteDatabase.js +++ b/seasoned_api/src/database/sqliteDatabase.js @@ -4,30 +4,80 @@ const sqlite = require('sqlite'); class SqliteDatabase { - constructor(host) { - this.host = host; - this.connection = sqlite; + constructor(host) { + this.host = host; + this.connection = sqlite; + this.schemaDirectory = path.join(__dirname, 'schemas'); + } - // this.schemaDirectory = path.join(__dirname, 'schemas'); - } + /** + * Connect to the database. + * @returns {Promise} succeeds if connection was established + */ + connect() { + return Promise.resolve() + .then(() => sqlite.open(this.host)) + .then(() => sqlite.exec('pragma foreign_keys = on;')); + } - connect() { - return Promise.resolve() - .then(() => sqlite.open(this.host)) - .then(() => sqlite.exec('pragma foreign_keys = on;')); - } + /** + * Run a SQL query against the database. + * @param {String} sql SQL query + * @param {Array} parameters in the SQL query + * @returns {Promise} + */ + run(sql, parameters) { + return this.connection.run(sql, parameters); + } - all(sql, parameters) { - return this.connection.all(sql, parameters); - } + /** + * Run a SQL query against the database and retrieve all the rows. + * @param {String} sql SQL query + * @param {Array} parameters in the SQL query + * @returns {Promise} + */ + all(sql, parameters) { + return this.connection.all(sql, parameters); + } - get(sql, parameters) { - return this.connection.get(sql, parameters); - } + /** + * Run a SQL query against the database and retrieve one row. + * @param {String} sql SQL query + * @param {Array} parameters in the SQL query + * @returns {Promise} + */ + get(sql, parameters) { + return this.connection.get(sql, parameters); + } - run(sql, parameters) { - return this.connection.run(sql, parameters); - } + /** + * Run a SQL query against the database and retrieve the status. + * @param {String} sql SQL query + * @param {Array} parameters in the SQL query + * @returns {Promise} + */ + execute(sql) { + return this.connection.exec(sql); + } + + /** + * Setup the database by running setup.sql file in schemas/. + * @returns {Promise} + */ + setUp() { + const setupSchema = this.readSqlFile('setup.sql'); + return this.execute(setupSchema); + } + + /** + * Returns the file contents of a SQL file in schemas/. + * @returns {String} + */ + readSqlFile(filename) { + const schemaPath = path.join(this.schemaDirectory, filename); + const schema = fs.readFileSync(schemaPath).toString('utf-8'); + return schema; + } } module.exports = SqliteDatabase; -- 2.34.1 From b8647f982d71d2f657795db23210f6840518c8f0 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 1 Dec 2017 10:27:46 +0100 Subject: [PATCH 06/10] This is where we use our setup function to add tables if none are present in our database file. --- seasoned_api/src/database/database.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seasoned_api/src/database/database.js b/seasoned_api/src/database/database.js index 00c9d98..8e509df 100644 --- a/seasoned_api/src/database/database.js +++ b/seasoned_api/src/database/database.js @@ -10,6 +10,6 @@ const database = new SqliteDatabase(configuration.get('database', 'host')); */ Promise.resolve() .then(() => database.connect()) -// .then(() => database.setUp()); +.then(() => database.setUp()); module.exports = database; -- 2.34.1 From db11c968a3db67782adf14f4f3d90ed917baa844 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 1 Dec 2017 10:28:29 +0100 Subject: [PATCH 07/10] Renamed folder the plural. --- seasoned_api/src/database/{schema => schemas}/setup.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename seasoned_api/src/database/{schema => schemas}/setup.sql (100%) diff --git a/seasoned_api/src/database/schema/setup.sql b/seasoned_api/src/database/schemas/setup.sql similarity index 100% rename from seasoned_api/src/database/schema/setup.sql rename to seasoned_api/src/database/schemas/setup.sql -- 2.34.1 From d0597b4e1e650d606710910d0b08c91d82eee929 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 1 Dec 2017 10:34:09 +0100 Subject: [PATCH 08/10] This is our main focus on changing, this is where we add a background parameter in our database entry. --- 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 94bfdc8..ffddd12 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -22,7 +22,7 @@ class RequestRepository { constructor(cache, 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 { user = 'NULL'; console.log(user) // Add request to database - this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, user, ip, user_agent, movie.type]) + this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, movie.background, user, ip, user_agent, movie.type]) // create reusable transporter object using the default SMTP transport -- 2.34.1 From f7b772a170844936d077ca8ad368631a43ad2ee3 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Fri, 1 Dec 2017 10:46:50 +0100 Subject: [PATCH 09/10] Changed the default cache TTL from 7 days to 2 days. --- seasoned_api/src/tmdb/cache.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seasoned_api/src/tmdb/cache.js b/seasoned_api/src/tmdb/cache.js index 1a55117..4c8b62e 100644 --- a/seasoned_api/src/tmdb/cache.js +++ b/seasoned_api/src/tmdb/cache.js @@ -33,7 +33,7 @@ class Cache { * @param {Number} timeToLive the number of seconds before entry expires * @returnsĀ {Object} */ - set(key, value, timeToLive = 86400) { + set(key, value, timeToLive = 172800) { const json = JSON.stringify(value); return Promise.resolve() .then(() => this.database.run(this.queries.create, [key, json, timeToLive])) @@ -41,4 +41,4 @@ class Cache { } } -module.exports = Cache; \ No newline at end of file +module.exports = Cache; -- 2.34.1 From 7d44f1518f19cbeb7c295c04ed5ec74d98687586 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Fri, 1 Dec 2017 10:57:28 +0100 Subject: [PATCH 10/10] Updated gitignore to ignore conf folder and deleted the contents of conf. --- seasoned_api/.gitignore | 2 +- seasoned_api/conf/development.json | 24 ------------------------ seasoned_api/conf/output.log | 1 - seasoned_api/src/webserver/access.log | 4 ---- 4 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 seasoned_api/conf/development.json delete mode 100644 seasoned_api/conf/output.log delete mode 100644 seasoned_api/src/webserver/access.log diff --git a/seasoned_api/.gitignore b/seasoned_api/.gitignore index 922c3ee..436d607 100644 --- a/seasoned_api/.gitignore +++ b/seasoned_api/.gitignore @@ -61,4 +61,4 @@ typings/ # - - - - - # My own gitignore files and folders shows.db -conf +conf/ diff --git a/seasoned_api/conf/development.json b/seasoned_api/conf/development.json deleted file mode 100644 index e349515..0000000 --- a/seasoned_api/conf/development.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "database": { - "host": "../shows.db" - }, - "webserver": { - "port": 31459 - }, - "tmdb": { - "apiKey": "" - }, - "raven": { - "DSN": "" - }, - "mail": { - "host": "", - "user": "", - "password": "", - "user_pi": "", - "password_pi": "" - }, - "authentication": { - "secret": "" - } -} diff --git a/seasoned_api/conf/output.log b/seasoned_api/conf/output.log deleted file mode 100644 index 8b13789..0000000 --- a/seasoned_api/conf/output.log +++ /dev/null @@ -1 +0,0 @@ - diff --git a/seasoned_api/src/webserver/access.log b/seasoned_api/src/webserver/access.log deleted file mode 100644 index 87ba069..0000000 --- a/seasoned_api/src/webserver/access.log +++ /dev/null @@ -1,4 +0,0 @@ -::1 - - [02/Jun/2017:06:34:49 +0000] "GET /api/v1/seasoned/all HTTP/1.1" 200 1016 "-" "curl/7.51.0" -::1 - - [02/Jun/2017:06:34:50 +0000] "GET /api/v1/seasoned/all HTTP/1.1" 200 1016 "-" "curl/7.51.0" -::1 - - [02/Jun/2017:06:45:59 +0000] "GET /api/v1/seasoned/all HTTP/1.1" 200 1016 "-" "curl/7.51.0" -::1 - - [02/Jun/2017:06:48:30 +0000] "GET /api/v1/seasoned/all HTTP/1.1" 200 1016 "-" "curl/7.51.0" -- 2.34.1