From adf72fa296e142bece25e9185edfc21bb5514286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Fri, 10 Nov 2017 16:45:59 +0100 Subject: [PATCH 1/2] Don't require the mailconfig, but log out in the console that it wont be enabled. --- server/config/mailconfig.example.js | 6 ++ server/routing/api.js | 106 ++++++++++++++-------------- 2 files changed, 60 insertions(+), 52 deletions(-) diff --git a/server/config/mailconfig.example.js b/server/config/mailconfig.example.js index 2a687cea..54a08dbc 100644 --- a/server/config/mailconfig.example.js +++ b/server/config/mailconfig.example.js @@ -1,3 +1,9 @@ +/** + * + * Have a look at nodemailer's config on how to set this up https://nodemailer.com/about/ + * + */ + var mail_config = { port: 587, host: 'smtp.example.com', diff --git a/server/routing/api.js b/server/routing/api.js index 80021711..569692de 100644 --- a/server/routing/api.js +++ b/server/routing/api.js @@ -1,15 +1,6 @@ var express = require('express'); var router = express.Router(); var path = require('path'); -var nodemailer = require('nodemailer'); -try { - var mailconfig = require(path.join(__dirname, '../config/mailconfig.js')); -} catch(e) { - console.log("Error - missing file"); - console.log("Seems you forgot to create a mailconfig.js in /server/config/. Have a look at the mailconfig.example.js."); - process.exit(); -} - router.use(function(req, res, next) { next(); // make sure we go to the next routes and don't stop here @@ -42,53 +33,55 @@ router.route('/api/list/:channel_name').get(function(req, res) { router.route('/api/conf/:channel_name').get(function(req, res) { var channel_name = req.params.channel_name; - db.collection(channel_name).find({views: {$exists: true}}, - { - addsongs: 1, - adminpass: 1, - allvideos: 1, - frontpage: 1, - longsongs: 1, - removeplay: 1, - shuffle: 1, - skip: 1, - startTime: 1, - userpass: 1, - vote: 1, - _id: 0 - }, function(err, docs) { - if(docs.length > 0) { - var conf = docs[0]; - if(conf.adminpass != "") { - conf.adminpass = true; - } else { - conf.adminpass = false; - } - if(conf.userpass != "") { - conf.userpass = true; - } else { - conf.userpass = false; - } - res.setHeader('Content-Type', 'application/json'); - res.send(JSON.stringify(conf)); + db.collection(channel_name).find({views: {$exists: true}}, { + addsongs: 1, + adminpass: 1, + allvideos: 1, + frontpage: 1, + longsongs: 1, + removeplay: 1, + shuffle: 1, + skip: 1, + startTime: 1, + userpass: 1, + vote: 1, + _id: 0 + }, function(err, docs) { + if(docs.length > 0) { + var conf = docs[0]; + if(conf.adminpass != "") { + conf.adminpass = true; } else { - res.status(404); - res.send(404); + conf.adminpass = false; } + if(conf.userpass != "") { + conf.userpass = true; + } else { + conf.userpass = false; + } + res.setHeader('Content-Type', 'application/json'); + res.send(JSON.stringify(conf)); + } else { + res.status(404); + res.send(404); + } + }); +}); + +router.route('/api/imageblob').post(function(req, res) { + var Jimp = require("jimp"); + Jimp.read('https://img.youtube.com/vi/' + req.body.id + '/mqdefault.jpg', function (err, image) { + if (err) console.log(err); + image.blur(50) + .write(path.join(pathThumbnails, '/public/assets/images/thumbnails/' + req.body.id + '.jpg'), function(e, r) { + res.send(req.body.id + ".jpg"); }); }); +}); - router.route('/api/imageblob').post(function(req, res) { - var Jimp = require("jimp"); - Jimp.read('https://img.youtube.com/vi/' + req.body.id + '/mqdefault.jpg', function (err, image) { - if (err) console.log(err); - image.blur(50) - .write(path.join(pathThumbnails, '/public/assets/images/thumbnails/' + req.body.id + '.jpg'), function(e, r) { - res.send(req.body.id + ".jpg"); - }); - }); - }); - +var nodemailer = require('nodemailer'); +try { + var mailconfig = require(path.join(__dirname, '../config/mailconfig.js')); router.route('/api/mail').post(function(req, res) { let transporter = nodemailer.createTransport(mailconfig); @@ -119,5 +112,14 @@ router.route('/api/conf/:channel_name').get(function(req, res) { } }); }); +} catch(e) { + console.log("Mail not setup and wont work"); + console.log("Seems you forgot to create a mailconfig.js in /server/config/. Have a look at the mailconfig.example.js."); + router.route('/api/mail').post(function(req, res) { + console.log("Someone tried to send a mail, but the mailsystem hasn't been enabled..") + res.send("failed"); + return; + }); +} - module.exports = router; +module.exports = router; From dc7a3478024787d20ef8d7b5c31023054e555bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Fri, 10 Nov 2017 16:47:37 +0100 Subject: [PATCH 2/2] Made changes accordingly to readme.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8e987c30..a9e7db2f 100755 --- a/README.md +++ b/README.md @@ -19,11 +19,10 @@ For the server to run, you have to have the files ``` api_key.js -mailconfig.js -mongo_config.js +mongo_config.js ``` -in ```/server/config```. There are ```*.example.js``` files for all the ones mentioned above. If you're going to deploy the server with a certificate, you also need to create the ```cert_config.js``` in ```/server/config/```. +in ```/server/config```. There are ```*.example.js``` files for all the ones mentioned above. If you're going to deploy the server with a certificate, you also need to create the ```cert_config.js``` in ```/server/config/```. If you want the mailing to work, take a look at ```mailconfig.example.js```. You'll need ```mailconfig.js``` for this to work. Use ```$ npm start``` to start the server.