Merge pull request #231 from zoff-music/feature/mailrequirement

Feature/mailrequirement
This commit is contained in:
Kasper Rynning-Tønnesen
2017-11-10 16:47:58 +01:00
committed by GitHub
3 changed files with 62 additions and 55 deletions

View File

@@ -19,11 +19,10 @@ For the server to run, you have to have the files
``` ```
api_key.js 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. Use ```$ npm start``` to start the server.

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 = { var mail_config = {
port: 587, port: 587,
host: 'smtp.example.com', host: 'smtp.example.com',

View File

@@ -1,15 +1,6 @@
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
var path = require('path'); 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) { router.use(function(req, res, next) {
next(); // make sure we go to the next routes and don't stop here next(); // make sure we go to the next routes and don't stop here
@@ -42,8 +33,7 @@ router.route('/api/list/:channel_name').get(function(req, res) {
router.route('/api/conf/:channel_name').get(function(req, res) { router.route('/api/conf/:channel_name').get(function(req, res) {
var channel_name = req.params.channel_name; var channel_name = req.params.channel_name;
db.collection(channel_name).find({views: {$exists: true}}, db.collection(channel_name).find({views: {$exists: true}}, {
{
addsongs: 1, addsongs: 1,
adminpass: 1, adminpass: 1,
allvideos: 1, allvideos: 1,
@@ -76,9 +66,9 @@ router.route('/api/conf/:channel_name').get(function(req, res) {
res.send(404); res.send(404);
} }
}); });
}); });
router.route('/api/imageblob').post(function(req, res) { router.route('/api/imageblob').post(function(req, res) {
var Jimp = require("jimp"); var Jimp = require("jimp");
Jimp.read('https://img.youtube.com/vi/' + req.body.id + '/mqdefault.jpg', function (err, image) { Jimp.read('https://img.youtube.com/vi/' + req.body.id + '/mqdefault.jpg', function (err, image) {
if (err) console.log(err); if (err) console.log(err);
@@ -87,8 +77,11 @@ router.route('/api/conf/:channel_name').get(function(req, res) {
res.send(req.body.id + ".jpg"); 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) { router.route('/api/mail').post(function(req, res) {
let transporter = nodemailer.createTransport(mailconfig); 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;