diff --git a/config.js b/config.js index 3f0d809e..7e2fda41 100644 --- a/config.js +++ b/config.js @@ -14,7 +14,7 @@ module.exports = { , port: process.env.SOUNDTRACK_REDIS_PORT || 6379 }, sessions: { - key: 'put yourself a fancy little key here' + key: process.env.SOUNDTRACK_SESSION_KEY || 'put yourself a fancy little key here' }, connection: { clientTimeout: 2 * 60 * 1000 diff --git a/controllers/people.js b/controllers/people.js index 589efc90..bb508cfc 100644 --- a/controllers/people.js +++ b/controllers/people.js @@ -221,7 +221,7 @@ module.exports = { if (typeof(person.email) == 'string') { var hash = require('crypto').createHash('md5').update( person.email.toLowerCase() ).digest('hex'); - person.avatar.url = 'https://www.gravatar.com/avatar/' + hash + '?d=https://soundtrack.io/img/user-avatar.png'; + person.avatar.url = 'https://www.gravatar.com/avatar/' + hash + '?d=' + ((req.app.config.app.safe) ? 'https://' : 'http://') + req.app.config.app.host + '/img/user-avatar.png'; } person.save(function(err) { diff --git a/lib/last.fm.js b/lib/last.fm.js index d7a25731..3aca6bb6 100644 --- a/lib/last.fm.js +++ b/lib/last.fm.js @@ -2,8 +2,7 @@ var _ = require('underscore'); module.exports = { authSetup: function(req, res) { - //var authUrl = lastfm.getAuthenticationUrl({ cb: ((config.app.safe) ? 'http://' : 'http://') + config.app.host + '/auth/lastfm/callback' }); - var authUrl = lastfm.getAuthenticationUrl({ cb: (( app.config.app.safe) ? 'http://' : 'http://') + 'soundtrack.io/auth/lastfm/callback' }); + var authUrl = lastfm.getAuthenticationUrl({ cb: (( req.app.config.app.safe) ? 'http://' : 'http://') + req.app.config.app.host + '/auth/lastfm/callback' }); res.redirect(authUrl); }, authCallback: function(req, res) { @@ -82,4 +81,4 @@ module.exports = { }); } -} \ No newline at end of file +} diff --git a/lib/soundtrack.js b/lib/soundtrack.js index 28549039..225b1af1 100644 --- a/lib/soundtrack.js +++ b/lib/soundtrack.js @@ -614,8 +614,7 @@ Soundtrack.prototype.lastfmAuthSetup = function(req, res) { var self = this; var app = this.app; - //var authUrl = lastfm.getAuthenticationUrl({ cb: ((config.app.safe) ? 'http://' : 'http://') + config.app.host + '/auth/lastfm/callback' }); - var authUrl = app.lastfm.getAuthenticationUrl({ cb: 'https://soundtrack.io/auth/lastfm/callback' }); + var authUrl = app.lastfm.getAuthenticationUrl({ cb: ((app.config.app.safe) ? 'http://' : 'http://') + app.config.app.host + '/auth/lastfm/callback' }); res.redirect(authUrl); }; Soundtrack.prototype.lastfmAuthCallback = function(req, res) { diff --git a/public/js/app.js b/public/js/app.js index 576933d4..5c3395b6 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,3 +1,5 @@ +var config = require('../../config'); + var DEFAULT_MAX_SOURCE_TIME = 5000; var DEFAULT_VOLUME = 80; var COOKIE_EXPIRES = 604800; @@ -596,7 +598,7 @@ $(window).load(function() { $('.message .message-content').filter(':contains("' + $('a[data-for=user-model]').data('username') + '")').parent().addClass('highlight'); if (msg.data.message.toLowerCase().indexOf('@' + soundtrack.user.username.toLowerCase()) >= 0) { - soundtrack.notify('https://soundtrack.io/favicon.ico', 'New Mention in Chat', msg.data.message); + soundtrack.notify(((config.app.safe) ? 'https://' : 'http://') + config.app.host + '/favicon.ico', 'New Mention in Chat', msg.data.message); } break; case 'ping': diff --git a/soundtrack.js b/soundtrack.js old mode 100644 new mode 100755 index c50f304f..4cadc7c6 --- a/soundtrack.js +++ b/soundtrack.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node // config, general requirements var config = require('./config'); var database = require('./db'); @@ -64,7 +65,9 @@ app.use( session({ maxAge : 30 * 24 * 60 * 60 * 1000 , domain: '.' + config.app.host }, - rolling: true + rolling: true, + resave: true, + saveUninitialized: true })); app.use(passport.initialize()); @@ -114,7 +117,7 @@ app.use(function(req, res, next) { var parts = req.headers.host.split('.'); req.room = parts[0]; - if (req.param('iframe')) return res.render('iframe'); + if (req.params['iframe']) return res.render('iframe'); Room.findOne({ slug: req.room }).populate('_owner bans._tracks bans._people').exec(function(err, room) { @@ -282,7 +285,7 @@ app.post('/tips', requireLogin , function(req, res, next) { receiver: room.track.curator._id, message: '1 bit', context_uid: Math.random(), - context_url: 'https://soundtrack.io' + context_url: ((config.app.safe) ? 'https://' : 'http://') + config.app.host }, function(err, results) { var result = err || results; @@ -507,8 +510,8 @@ var externalizer = function(req, res, next) { } var redirectSetup = function(req, res, next) { - if (req.param('next')) { - req.session.next = req.param('next'); + if (req.params['next']) { + req.session.next = req.params['next']; req.session.save( next ); } else { return next(); @@ -532,7 +535,7 @@ if (config.google && config.google.id && config.google.secret) { clientID: config.google.id, clientSecret: config.google.secret, //callbackURL: ((config.app.safe) ? 'https://' : 'http://') + config.app.host + '/auth/google/callback', - callbackURL: 'https://soundtrack.io/auth/google/callback', + callbackURL: ((config.app.safe) ? 'https://' : 'http://') + config.app.host + '/auth/google/callback', scope: 'profile email https://www.googleapis.com/auth/youtube', passReqToCallback: true }, function(req, accessToken, refreshToken, profile, done) { @@ -606,9 +609,7 @@ if (config.changetip && config.changetip.id && config.changetip.secret) { passport.use(new ChangeTipStrategy({ clientID: config.changetip.id, clientSecret: config.changetip.secret, - //callbackURL: ((config.app.safe) ? 'https://' : 'http://') + config.app.host + '/auth/changetip/callback', - callbackURL: 'https://soundtrack.io/auth/changetip/callback', - //callbackURL: 'http://localhost.localdomain:13000/auth/changetip/callback', + callbackURL: ((config.app.safe) ? 'https://' : 'http://') + config.app.host + '/auth/changetip/callback', passReqToCallback: true }, function(req, accessToken, refreshToken, profile, done) { @@ -659,11 +660,10 @@ if (config.lastfm && config.lastfm.key && config.lastfm.secret) { app.lastfm = lastfm; app.get('/auth/lastfm', function(req, res) { var authUrl = lastfm.getAuthenticationUrl({ cb: ((config.app.safe) ? 'https://' : 'http://') + config.app.host + '/auth/lastfm/callback' }); - //var authUrl = lastfm.getAuthenticationUrl({ cb: ((config.app.safe) ? 'http://' : 'http://') + 'soundtrack.io/auth/lastfm/callback' }); res.redirect(authUrl); }); app.get('/auth/lastfm/callback', function(req, res) { - lastfm.authenticate( req.param('token') , function(err, session) { + lastfm.authenticate( req.params['token'] , function(err, session) { if (err) { console.log(err); req.flash('error', 'Something went wrong with authentication.'); @@ -730,7 +730,7 @@ app.post('/chat', requireLogin, function(req, res) { var chat = new Chat({ _author: req.user._id - , message: req.param('message') + , message: req.params['message'] , _track: (room.playlist[0]) ? room.playlist[0]._id : undefined , _room: (room) ? room._id : undefined }); @@ -738,7 +738,7 @@ app.post('/chat', requireLogin, function(req, res) { res.render('partials/message', { message: { _author: req.user - , message: req.param('message') + , message: req.params['message'] , created: chat.created , _track: room.playlist[0] } @@ -752,7 +752,7 @@ app.post('/chat', requireLogin, function(req, res) { , username: req.user.username , slug: req.user.slug } - , message: req.param('message') + , message: req.params['message'] , formatted: html , created: new Date() , _track: room.playlist[0] @@ -763,12 +763,12 @@ app.post('/chat', requireLogin, function(req, res) { }); }); -app.del('/playlist/:trackID', requireLogin, requireRoom , authorize('host'), function(req, res, next) { - if (!req.param('index') || req.param('index') == 0) { return next(); } +app.delete('/playlist/:trackID', requireLogin, requireRoom , authorize('host'), function(req, res, next) { + if (!req.params['index'] || req.params['index'] == 0) { return next(); } var room = app.rooms[ req.room ]; - room.playlist.splice( req.param('index') , 1 ); + room.playlist.splice( req.params['index'] , 1 ); room.sortPlaylist(); soundtrack.broadcast({ @@ -787,12 +787,12 @@ app.post('/playlist/:trackID', requireLogin, function(req, res, next) { var playlistMap = room.playlist.map(function(x) { return x._id.toString(); }); - var index = playlistMap.indexOf( req.param('trackID') ); + var index = playlistMap.indexOf( req.params['trackID'] ); if (!index) { return next(); } if (!room.playlist[ index ].votes) { room.playlist[ index ].votes = {}; } - room.playlist[ index ].votes[ req.user._id ] = (req.param('v') == 'up') ? 1 : -1; + room.playlist[ index ].votes[ req.user._id ] = (req.params['v'] == 'up') ? 1 : -1; room.playlist[ index ].score = _.reduce( room.playlist[ index ].votes , function(score, vote) { return score + vote; }, 0); @@ -822,7 +822,7 @@ app.post('/playlist', requireLogin , function(req, res) { if (!req.room) return res.send({ status: 'error', message: 'No room to queue to.' }); if (!app.rooms[ req.room ]) return res.send({ status: 'error', message: 'No room to queue to.' }); - soundtrack.trackFromSource( req.param('source') , req.param('id') , req.body, function(err, track) { + soundtrack.trackFromSource( req.params['source'] , req.params['id'] , req.body, function(err, track) { console.log('trackFromSource() callback executing...', err || track._id ); if (err || !track) { console.log(err); @@ -908,7 +908,7 @@ app.post('/set-username', requireLogin, people.setUsername); app.post('/settings', requireLogin, function(req, res, next) { Person.findOne({ _id: req.user._id }).exec(function(err, person) { - person.preferences.scrobble = (req.param('scrobble')) ? true: false; + person.preferences.scrobble = (req.params['scrobble']) ? true: false; person.save(function(err) { res.send({ status: 'success' @@ -920,7 +920,7 @@ app.post('/settings', requireLogin, function(req, res, next) { app.get('/login', function(req, res) { res.render('login', { - next: req.param('next') + next: req.params['next'] }); }); @@ -949,18 +949,18 @@ app.get('/chat/since.json', requireRoom , chat.since); app.get('/rooms', rooms.list ); app.post('/rooms', requireLogin , soundtracker , rooms.create ); app.get('/rooms/:roomSlug', function(req, res, next) { - Room.findOne({ slug: req.param('roomSlug') }).exec(function(err, room) { + Room.findOne({ slug: req.params['roomSlug'] }).exec(function(err, room) { if (err || !room) return next(); res.send(room); }); }); app.patch('/rooms/:roomSlug', requireLogin, function(req, res, next) { - Room.findOne({ slug: req.param('roomSlug') }).exec(function(err, room) { + Room.findOne({ slug: req.params['roomSlug'] }).exec(function(err, room) { if (err || !room) return next(); if (!room._owner) return next(); if (room._owner.toString() !== req.user._id.toString()) return next(); - - room.description = req.param('description'); + + room.description = req.params['description']; room.save(function(err) { res.send(room); }); @@ -977,12 +977,12 @@ app.post('/tracks/:trackID', authorize('editor') , soundtracker app.patch('/tracks/:trackID', requireLogin, requireRoom , authorize('host') , soundtracker , tracks.ban); app.get('/:artistSlug', redirectToMainSite , soundtracker , artists.view); -app.del('/:artistSlug', soundtracker , authorize('admin') , artists.delete); +app.delete('/:artistSlug', soundtracker , authorize('admin') , artists.delete); app.put('/:artistSlug', soundtracker , authorize('editor') , artists.edit); app.post('/:artistSlug', soundtracker , authorize('editor') , artists.edit); -app.del('/playlists/:playlistID/:index', playlists.removeTrackFromPlaylist); -app.del('/playlists/:playlistID', playlists.delete); +app.delete('/playlists/:playlistID/:index', playlists.removeTrackFromPlaylist); +app.delete('/playlists/:playlistID', playlists.delete); app.get('/:usernameSlug/sets/new', redirectToMainSite , playlists.createForm); app.get('/:usernameSlug/sets', redirectToMainSite , playlists.listPerson); app.get('/:usernameSlug/playlists/new', redirectToMainSite , playlists.createForm);