Submit request #15
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ npm-debug.log
|
|||||||
webpage/js/env_variables.js
|
webpage/js/env_variables.js
|
||||||
client/dist
|
client/dist
|
||||||
src/webserver/access.log
|
src/webserver/access.log
|
||||||
|
conf/development.json
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class MovieObject {
|
|||||||
if (this.matchedInPlex) {
|
if (this.matchedInPlex) {
|
||||||
returnList.push(<button onClick={() => this.requestExisting(this)}>Request anyway</button>)
|
returnList.push(<button onClick={() => this.requestExisting(this)}>Request anyway</button>)
|
||||||
} else {
|
} else {
|
||||||
returnList.push(<button onClick={() => this.requestMovie(this)}>Request</button>)
|
returnList.push(<button onClick={() => this.requestMovie(this.id)}>Request</button>)
|
||||||
}
|
}
|
||||||
|
|
||||||
returnList.push(<span>{this.overview}</span>);
|
returnList.push(<span>{this.overview}</span>);
|
||||||
|
|||||||
19
package.json
19
package.json
@@ -2,18 +2,19 @@
|
|||||||
"name": "node-api",
|
"name": "node-api",
|
||||||
"main": "src/webserver/server.js",
|
"main": "src/webserver/server.js",
|
||||||
"scripts": {
|
"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": {
|
"dependencies": {
|
||||||
"express": "~4.0.0",
|
|
||||||
"mongoose": "~3.6.13",
|
|
||||||
"body-parser": "~1.0.1",
|
"body-parser": "~1.0.1",
|
||||||
"cross-env": "^3.1.3",
|
"cross-env": "^3.1.3",
|
||||||
"sqlite": "^2.5.0",
|
"express": "~4.0.0",
|
||||||
"request": "^2.81.0",
|
"mongoose": "~3.6.13",
|
||||||
"python-shell": "^0.4.0",
|
"moviedb": "^0.2.7",
|
||||||
"moviedb": "^0.2.7",
|
"node-cache": "^4.1.1",
|
||||||
"node-cache": "^4.1.1",
|
"nodemailer": "^4.0.1",
|
||||||
"request-promise": "^4.2"
|
"python-shell": "^0.4.0",
|
||||||
|
"request": "^2.81.0",
|
||||||
|
"request-promise": "^4.2",
|
||||||
|
"sqlite": "^2.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/plex/mailTemplate.js
Normal file
26
src/plex/mailTemplate.js
Normal file
@@ -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 `
|
||||||
|
<h1>${info.name} ${info.year}</h1>
|
||||||
|
<img src=${info.poster}>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = mailTemplate;
|
||||||
@@ -8,7 +8,11 @@ const tmdb = new TMDB(configuration.get('tmdb', 'apiKey'));
|
|||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
var rp = require('request-promise');
|
var rp = require('request-promise');
|
||||||
|
|
||||||
|
const MailTemplate = require('src/plex/mailTemplate')
|
||||||
|
|
||||||
var pythonShell = require('python-shell');
|
var pythonShell = require('python-shell');
|
||||||
|
const nodemailer = require('nodemailer');
|
||||||
|
|
||||||
|
|
||||||
class RequestRepository {
|
class RequestRepository {
|
||||||
|
|
||||||
@@ -60,24 +64,57 @@ class RequestRepository {
|
|||||||
sendRequest(identifier) {
|
sendRequest(identifier) {
|
||||||
// TODO try a cache hit on the movie item
|
// TODO try a cache hit on the movie item
|
||||||
|
|
||||||
console.log(identifier)
|
|
||||||
tmdb.lookup(identifier).then(movie => {
|
tmdb.lookup(identifier).then(movie => {
|
||||||
console.log(movie.title)
|
console.log(movie.title)
|
||||||
|
|
||||||
var options = {
|
|
||||||
args: [movie.title, movie.year, movie.poster]
|
|
||||||
}
|
|
||||||
|
|
||||||
pythonShell.run('sendRequest.py', options, function (err, results) {
|
// create reusable transporter object using the default SMTP transport
|
||||||
if (err) throw err;
|
let transporter = nodemailer.createTransport({
|
||||||
// TODO Add error handling!! RequestRepository.ERROR
|
host: configuration.get('mail', 'host'),
|
||||||
// results is an array consisting of messages collected during execution
|
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)
|
const mailTemplate = new MailTemplate(movie)
|
||||||
})
|
|
||||||
return true;
|
// setup email data with unicode symbols
|
||||||
|
let mailOptions = {
|
||||||
|
// TODO get the mail adr from global location (easy to add)
|
||||||
|
from: 'MovieRequester <support@kevinmidboe.com>', // 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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user