Skip to content

Commit

Permalink
Merge pull request FabricLabs#185 from Lucas-C/soundtrack.io
Browse files Browse the repository at this point in the history
Refactoring scattered "soundtrack.io" strings into app.host + fixing expressJS warnings
  • Loading branch information
martindale committed Jan 7, 2016
2 parents 587366f + 4cb71bc commit 5360985
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion controllers/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions lib/last.fm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -82,4 +81,4 @@ module.exports = {
});

}
}
}
3 changes: 1 addition & 2 deletions lib/soundtrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var config = require('../../config');

var DEFAULT_MAX_SOURCE_TIME = 5000;
var DEFAULT_VOLUME = 80;
var COOKIE_EXPIRES = 604800;
Expand Down Expand Up @@ -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':
Expand Down
58 changes: 29 additions & 29 deletions soundtrack.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
// config, general requirements
var config = require('./config');
var database = require('./db');
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -730,15 +730,15 @@ 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
});
chat.save(function(err) {
res.render('partials/message', {
message: {
_author: req.user
, message: req.param('message')
, message: req.params['message']
, created: chat.created
, _track: room.playlist[0]
}
Expand All @@ -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]
Expand All @@ -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({
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'
Expand All @@ -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']
});
});

Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
Expand Down

0 comments on commit 5360985

Please sign in to comment.