Browse Source

Removed the function func()

theflametrooper 8 years ago
parent
commit
e3cf374626

+ 2 - 2
backend/logic/actions/hooks/ownerRequired.js

@@ -11,7 +11,7 @@ module.exports = function(next) {
 			if (err || !session || !session.userId) return cb({ status: 'failure', message: 'Login required.' });
 			db.models.user.findOne({_id: session.userId}, (err, user) => {
 				if (err || !user) return cb({ status: 'failure', message: 'Login required.' });
-				if (user.role === 'admin') func();
+				if (user.role === 'admin') pushArgs();
 				else {
 					stations.getStation(stationId, (err, station) => {
 						if (err || !station) return cb({ status: 'failure', message: 'Something went wrong when getting the station.' });
@@ -20,7 +20,7 @@ module.exports = function(next) {
 					});
 				}
 
-				function func() {
+				function pushArgs() {
 					args.push(session.userId);
 					next.apply(null, args);
 				}

+ 5 - 6
backend/logic/actions/stations.js

@@ -159,21 +159,20 @@ module.exports = {
 
 			if (station) {
 
-				if (station.privacy !== 'private') {
-					func();
-				} else {
+				if (station.privacy !== 'private') joinStation();
+				else {
 					// TODO If community, check if on whitelist
 					if (!session.userId) return cb({ status: 'error', message: 'An error occurred while joining the station1' });
 					db.models.user.findOne({_id: session.userId}, (err, user) => {
 						if (err || !user) return cb({ status: 'error', message: 'An error occurred while joining the station2' });
-						if (user.role === 'admin') return func();
+						if (user.role === 'admin') return joinStation();
 						if (station.type === 'official') return cb({ status: 'error', message: 'An error occurred while joining the station3' });
-						if (station.owner === session.userId) return func();
+						if (station.owner === session.userId) return joinStation();
 						return cb({ status: 'error', message: 'An error occurred while joining the station4' });
 					});
 				}
 
-				function func() {
+				function joinStation() {
 					utils.socketJoinRoom(session.socketId, `station.${stationId}`);
 					if (station.currentSong) {
 						utils.socketJoinSongRoom(session.socketId, `song.${station.currentSong._id}`);

+ 4 - 5
backend/logic/cache/index.js

@@ -147,14 +147,13 @@ const lib = {
 	 * @param {Boolean} [parseJson=true] - parse the message as JSON
 	 */
 	sub: (channel, cb, parseJson = true) => {
-		if (initialized) {
-			func();
-		} else {
+		if (initialized) subToChannel();
+		else {
 			callbacks.push(() => {
-				func();
+				subToChannel();
 			});
 		}
-		function func() {
+		function subToChannel() {
 			if (subs[channel] === undefined) {
 				subs[channel] = { client: redis.createClient({ url: lib.url }), cbs: [] };
 				subs[channel].client.on('error', (err) => {

+ 3 - 3
backend/logic/stations.js

@@ -229,7 +229,7 @@ module.exports = {
 						(next) => {
 							if (station.type === "official") {
 								if (station.playlist.length > 0) {
-									function func() {
+									function setCurrentSong() {
 										if (station.currentSongIndex < station.playlist.length - 1) {
 											songs.getSong(station.playlist[station.currentSongIndex + 1], (err, song) => {
 												if (!err) {
@@ -250,9 +250,9 @@ module.exports = {
 													$set.currentSongIndex = station.currentSongIndex + 1;
 													next(null, $set);
 												} else {
-													db.models.station.update({_id: station._id}, {$inc: {currentSongIndex: 1}}, (err) => {
+													db.models.station.update({ _id: station._id }, { $inc: { currentSongIndex: 1 } }, (err) => {
 														_this.updateStation(station._id, () => {
-															func();
+															setCurrentSong();
 														});
 													});
 												}