Don't require the mailconfig, but log out in the console that it wont be enabled.

This commit is contained in:
Kasper Rynning-Tønnesen
2017-11-10 16:45:59 +01:00
parent 4e58c0a77f
commit adf72fa296
2 changed files with 60 additions and 52 deletions

View File

@@ -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',

View File

@@ -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;