From 6322b0b17b0f08de9f2d1b788a2d8dcb26443adc Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 13:45:05 +0200 Subject: [PATCH 1/4] Formatting changes, sorted alpha --- .gitignore | 1 + package.json | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 46158bf..6c8de50 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ npm-debug.log webpage/js/env_variables.js client/dist src/webserver/access.log +conf/development.json diff --git a/package.json b/package.json index 463031b..6d7198c 100644 --- a/package.json +++ b/package.json @@ -2,18 +2,19 @@ "name": "node-api", "main": "src/webserver/server.js", "scripts": { - "start": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/webserver/server.js" + "start": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/webserver/server.js" }, "dependencies": { - "express": "~4.0.0", - "mongoose": "~3.6.13", "body-parser": "~1.0.1", "cross-env": "^3.1.3", - "sqlite": "^2.5.0", - "request": "^2.81.0", - "python-shell": "^0.4.0", - "moviedb": "^0.2.7", - "node-cache": "^4.1.1", - "request-promise": "^4.2" + "express": "~4.0.0", + "mongoose": "~3.6.13", + "moviedb": "^0.2.7", + "node-cache": "^4.1.1", + "nodemailer": "^4.0.1", + "python-shell": "^0.4.0", + "request": "^2.81.0", + "request-promise": "^4.2", + "sqlite": "^2.5.0" } } From a6af5e8c5dfcb2229920557bb9edfc10b189557b Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 13:45:42 +0200 Subject: [PATCH 2/4] Now returns just id of the movie when clicked button. --- client/app/components/MovieObject.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/app/components/MovieObject.jsx b/client/app/components/MovieObject.jsx index 51a98d4..b3e48af 100644 --- a/client/app/components/MovieObject.jsx +++ b/client/app/components/MovieObject.jsx @@ -35,7 +35,7 @@ class MovieObject { if (this.matchedInPlex) { returnList.push() } else { - returnList.push() + returnList.push() } returnList.push({this.overview}); From 30d26d82c30299c75d8972c30ee16ddd76d6a2c5 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 13:47:06 +0200 Subject: [PATCH 3/4] Added nodemailer to send email of the requested movie --- src/plex/requestRepository.js | 59 ++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/src/plex/requestRepository.js b/src/plex/requestRepository.js index a4f1872..a15a8d5 100644 --- a/src/plex/requestRepository.js +++ b/src/plex/requestRepository.js @@ -8,7 +8,11 @@ const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); var Promise = require('bluebird'); var rp = require('request-promise'); +const MailTemplate = require('src/plex/mailTemplate') + var pythonShell = require('python-shell'); +const nodemailer = require('nodemailer'); + class RequestRepository { @@ -60,24 +64,57 @@ class RequestRepository { sendRequest(identifier) { // TODO try a cache hit on the movie item - console.log(identifier) tmdb.lookup(identifier).then(movie => { console.log(movie.title) - var options = { - args: [movie.title, movie.year, movie.poster] - } - pythonShell.run('sendRequest.py', options, function (err, results) { - if (err) throw err; - // TODO Add error handling!! RequestRepository.ERROR - // results is an array consisting of messages collected during execution + // create reusable transporter object using the default SMTP transport + let transporter = nodemailer.createTransport({ + host: configuration.get('mail', 'host'), + port: 26, + ignoreTLS: true, + tls :{rejectUnauthorized: false}, + secure: false, // secure:true for port 465, secure:false for port 587 + auth: { + user: configuration.get('mail', 'user'), + pass: configuration.get('mail', 'password') + } + }); - console.log('results: %j', results) - }) - return true; + const mailTemplate = new MailTemplate(movie) + + // setup email data with unicode symbols + let mailOptions = { + // TODO get the mail adr from global location (easy to add) + from: 'MovieRequester ', // sender address + to: 'kevin.midboe@gmail.com', // list of receivers + subject: 'Download request', // Subject line + text: mailTemplate.toText(), + html: mailTemplate.toHTML() + }; + + // send mail with defined transport object + transporter.sendMail(mailOptions, (error, info) => { + if (error) { + return console.log(error); + } + console.log('Message %s sent: %s', info.messageId, info.response); + }); + + // var options = { + // args: [movie.title, movie.year, movie.poster] + // } + + // pythonShell.run('sendRequest.py', options, function (err, results) { + // if (err) throw err; + // // TODO Add error handling!! RequestRepository.ERROR + // // results is an array consisting of messages collected during execution + + // console.log('results: %j', results) + // }) }) + return Promise.resolve(); } From 6b5a2341bf8d4fb494fa6af21f0dba14b119d8fd Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 13:47:49 +0200 Subject: [PATCH 4/4] Class file that creates and returns objects for the mail sender in a single place. --- src/plex/mailTemplate.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/plex/mailTemplate.js diff --git a/src/plex/mailTemplate.js b/src/plex/mailTemplate.js new file mode 100644 index 0000000..a62e177 --- /dev/null +++ b/src/plex/mailTemplate.js @@ -0,0 +1,26 @@ +class mailTemplate { + + constructor(mediaItem) { + this.mediaItem = mediaItem; + this.posterURL = 'https://image.tmdb.org/t/p/w600/'; + } + + toText() { + return this.mediaItem.title + ' (' + this.mediaItem.year + ')'; // plain text body + } + + toHTML() { + const info = { + name: this.mediaItem.title, + year: '(' + this.mediaItem.year + ')', + poster: this.posterURL + this.mediaItem.poster + } + + return ` +

${info.name} ${info.year}

+ + ` + } +} + +module.exports = mailTemplate; \ No newline at end of file