Browse Source

Redirected to 404 route if station doesn't exist

theflametrooper 8 years ago
parent
commit
e3fdfaf0da

+ 7 - 0
backend/logic/actions/stations.js

@@ -126,6 +126,13 @@ module.exports = {
 		});
 	},
 
+	find: (session, stationId, cb) => {
+		stations.getStation(stationId, (err, station) => {
+			if (err) cb({ status: 'error', message: err });
+			else if (station) cb({ status: 'success', data: station });
+		});
+	},
+
 	getPlaylist: (session, stationId, cb) => {
 		let playlist = [];
 

+ 1 - 1
backend/logic/stations.js

@@ -146,7 +146,7 @@ module.exports = {
 					station = cache.schemas.station(station);
 					cache.hset('stations', stationId, station);
 					next(true, station);
-				} else next('Station not found.');
+				} else next('Station not found');
 			},
 
 		], (err, station) => {

+ 9 - 4
frontend/components/Station/Station.vue

@@ -331,16 +331,21 @@
 
 			io.getSocket((socket) => {
 				_this.socket = socket;
-				io.removeAllListeners();
 
-				if (_this.socket.connected) {
-					_this.joinStation();
-				}
+				io.removeAllListeners();
 
+				if (_this.socket.connected) _this.joinStation();
 				io.onConnect(() => {
 					_this.joinStation();
 				});
 
+				_this.socket.emit('stations.find', _this.stationId, res => {
+					if (res.status === 'error') {
+						_this.$router.go('/404');
+						Toast.methods.addToast(res.message, 3000);
+					}
+				});
+
 				_this.socket.on('event:songs.next', data => {
 					_this.previousSong = (_this.currentSong._id) ? _this.currentSong : null;
 					_this.currentSong = (data.currentSong) ? data.currentSong : {};

+ 7 - 9
frontend/components/pages/Home.vue

@@ -80,14 +80,12 @@
 			auth.getStatus((authenticated, role, username, userId) => {
 				io.getSocket((socket) => {
 					_this.socket = socket;
-					if (_this.socket.connected) {
-						_this.init();
-					}
+					if (_this.socket.connected) _this.init();
 					io.onConnect(() => {
 						_this.init();
 					});
 					_this.socket.on('event:stations.created', station => {
-						if (!station.currentSong) station.currentSong = {thumbnail: '/assets/notes-transparent.png'};
+						if (!station.currentSong) station.currentSong = { thumbnail: '/assets/notes-transparent.png' };
 						if (station.privacy !== 'public') {
 							station.class = {'station-red': true}
 						} else if (station.type === 'community') {
@@ -107,16 +105,16 @@
 			init: function() {
 				let _this = this;
 				auth.getStatus((authenticated, role, username, userId) => {
-					_this.socket.emit("stations.index", data => {
+					_this.socket.emit('stations.index', data => {
 						_this.stations.community = [];
 						_this.stations.official = [];
-						if (data.status === "success")  data.stations.forEach(station => {
-							if (!station.currentSong) station.currentSong = {thumbnail: '/assets/notes-transparent.png'};
+						if (data.status === "success") data.stations.forEach(station => {
+							if (!station.currentSong) station.currentSong = { thumbnail: '/assets/notes-transparent.png' };
 							if (station.privacy !== 'public') {
-								station.class = {'station-red': true}
+								station.class = { 'station-red': true }
 							} else if (station.type === 'community') {
 								if (station.owner === userId) {
-									station.class = {'station-blue': true}
+									station.class = { 'station-blue': true }
 								}
 							}
 							if (station.type == 'official') _this.stations.official.push(station);