stations.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. 'use strict';
  2. const async = require('async'),
  3. request = require('request'),
  4. config = require('config');
  5. const io = require('../io');
  6. const db = require('../db');
  7. const cache = require('../cache');
  8. const notifications = require('../notifications');
  9. const utils = require('../utils');
  10. const logger = require('../logger');
  11. const stations = require('../stations');
  12. const songs = require('../songs');
  13. const hooks = require('./hooks');
  14. cache.sub('station.updatePartyMode', data => {
  15. utils.emitToRoom(`station.${data.stationId}`, "event:partyMode.updated", data.partyMode);
  16. });
  17. cache.sub('privatePlaylist.selected', data => {
  18. utils.emitToRoom(`station.${data.stationId}`, "event:privatePlaylist.selected", data.playlistId);
  19. });
  20. cache.sub('station.pause', stationId => {
  21. utils.emitToRoom(`station.${stationId}`, "event:stations.pause");
  22. });
  23. cache.sub('station.resume', stationId => {
  24. stations.getStation(stationId, (err, station) => {
  25. utils.emitToRoom(`station.${stationId}`, "event:stations.resume", { timePaused: station.timePaused });
  26. });
  27. });
  28. cache.sub('station.queueUpdate', stationId => {
  29. stations.getStation(stationId, (err, station) => {
  30. if (!err) utils.emitToRoom(`station.${stationId}`, "event:queue.update", station.queue);
  31. });
  32. });
  33. cache.sub('station.voteSkipSong', stationId => {
  34. utils.emitToRoom(`station.${stationId}`, "event:song.voteSkipSong");
  35. });
  36. cache.sub('station.remove', stationId => {
  37. utils.emitToRoom('admin.stations', 'event:admin.station.removed', stationId);
  38. });
  39. cache.sub('station.create', stationId => {
  40. stations.initializeStation(stationId, (err, station) => {
  41. if (err) console.error(err);
  42. utils.emitToRoom('admin.stations', 'event:admin.station.added', station);
  43. // TODO If community, check if on whitelist
  44. if (station.privacy === 'public') utils.emitToRoom('home', "event:stations.created", station);
  45. else {
  46. let sockets = utils.getRoomSockets('home');
  47. for (let socketId in sockets) {
  48. let socket = sockets[socketId];
  49. let session = sockets[socketId].session;
  50. if (session.sessionId) {
  51. cache.hget('sessions', session.sessionId, (err, session) => {
  52. if (!err && session) {
  53. db.models.user.findOne({_id: session.userId}, (err, user) => {
  54. if (user.role === 'admin') socket.emit("event:stations.created", station);
  55. else if (station.type === "community" && station.owner === session.userId) socket.emit("event:stations.created", station);
  56. });
  57. }
  58. });
  59. }
  60. }
  61. }
  62. });
  63. });
  64. module.exports = {
  65. /**
  66. * Get a list of all the stations
  67. *
  68. * @param session
  69. * @param cb
  70. * @return {{ status: String, stations: Array }}
  71. */
  72. index: (session, cb) => {
  73. async.waterfall([
  74. (next) => {
  75. cache.hgetall('stations', next);
  76. },
  77. (stations, next) => {
  78. let resultStations = [];
  79. for (let id in stations) {
  80. resultStations.push(stations[id]);
  81. }
  82. next(null, stations);
  83. },
  84. (stations, next) => {
  85. let resultStations = [];
  86. async.each(stations, (station, next) => {
  87. async.waterfall([
  88. (next) => {
  89. if (station.privacy === 'public') return next(true);
  90. if (!session.sessionId) return next(false);
  91. cache.hget('sessions', session.sessionId, next);
  92. },
  93. (session, next) => {
  94. if (!session) return next(false);
  95. db.models.user.findOne({_id: session.userId}, next);
  96. },
  97. (user, next) => {
  98. if (!user) return next(false);
  99. if (user.role === 'admin') return next(true);
  100. if (station.type === 'official') return next(false);
  101. if (station.owner === session.userId) return next(true);
  102. next(false);
  103. }
  104. ], (err) => {
  105. if (err === true) resultStations.push(station);
  106. next();
  107. });
  108. }, () => {
  109. next(null, resultStations);
  110. });
  111. }
  112. ], (err, stations) => {
  113. if (err) {
  114. err = utils.getError(err);
  115. logger.error("STATIONS_INDEX", `Indexing stations failed. "${err}"`);
  116. return cb({'status': 'failure', 'message': err});
  117. }
  118. logger.success("STATIONS_INDEX", `Indexing stations successful.`);
  119. return cb({'status': 'success', 'stations': stations});
  120. });
  121. },
  122. find: (session, stationId, cb) => {
  123. async.waterfall([
  124. (next) => {
  125. stations.getStation(stationId, next);
  126. },
  127. (station, next) => {
  128. if (!station) return next('Station not found.');
  129. next(null, station);
  130. }
  131. ], (err, station) => {
  132. if (err) {
  133. err = utils.getError(err);
  134. logger.error("STATIONS_FIND", `Finding station "${stationId}" failed. "${err}"`);
  135. return cb({'status': 'failure', 'message': err});
  136. }
  137. logger.success("STATIONS_FIND", `Found station "${stationId}" successfully.`);
  138. cb({status: 'success', data: station});
  139. });
  140. },
  141. getPlaylist: (session, stationId, cb) => {
  142. async.waterfall([
  143. (next) => {
  144. stations.getStation(stationId, next);
  145. },
  146. (station, next) => {
  147. if (!station) return next('Station not found.');
  148. if (station.type !== 'official') return next('This is not an official station.');
  149. next();
  150. },
  151. (next) => {
  152. cache.hget("officialPlaylists", stationId, next);
  153. },
  154. (playlist, next) => {
  155. if (!playlist) return next('Playlist not found.');
  156. next(null, playlist);
  157. }
  158. ], (err, playlist) => {
  159. if (err) {
  160. err = utils.getError(err);
  161. logger.error("STATIONS_GET_PLAYLIST", `Getting playlist for station "${stationId}" failed. "${err}"`);
  162. return cb({'status': 'failure', 'message': err});
  163. }
  164. logger.success("STATIONS_GET_PLAYLIST", `Got playlist for station "${stationId}" successfully.`);
  165. cb({status: 'success', data: playlist.songs})
  166. });
  167. },
  168. /**
  169. * Joins the station by its id
  170. *
  171. * @param session
  172. * @param stationId - the station id
  173. * @param cb
  174. * @return {{ status: String, userCount: Integer }}
  175. */
  176. join: (session, stationId, cb) => {
  177. async.waterfall([
  178. (next) => {
  179. stations.getStation(stationId, next);
  180. },
  181. (station, next) => {
  182. if (!station) return next('Station not found.');
  183. async.waterfall([
  184. (next) => {
  185. if (station.privacy !== 'private') return next(true);
  186. if (!session.userId) return next('An error occurred while joining the station.');
  187. next();
  188. },
  189. (next) => {
  190. db.models.user.findOne({_id: session.userId}, next);
  191. },
  192. (user, next) => {
  193. if (!user) return next('An error occurred while joining the station.');
  194. if (user.role === 'admin') return next(true);
  195. if (station.type === 'official') return next('An error occurred while joining the station.');
  196. if (station.owner === session.userId) return next(true);
  197. next('An error occurred while joining the station.');
  198. }
  199. ], (err) => {
  200. if (err === true) return next(null, station);
  201. next(utils.getError(err));
  202. });
  203. },
  204. (station, next) => {
  205. utils.socketJoinRoom(session.socketId, `station.${stationId}`);
  206. let data = {
  207. type: station.type,
  208. currentSong: station.currentSong,
  209. startedAt: station.startedAt,
  210. paused: station.paused,
  211. timePaused: station.timePaused,
  212. description: station.description,
  213. displayName: station.displayName,
  214. privacy: station.privacy,
  215. partyMode: station.partyMode,
  216. owner: station.owner,
  217. privatePlaylist: station.privatePlaylist
  218. };
  219. next(null, data);
  220. },
  221. (data, next) => {
  222. if (!data.currentSong) return next(null, data);
  223. utils.socketJoinSongRoom(session.socketId, `song.${data.currentSong._id}`);
  224. data.currentSong.skipVotes = data.currentSong.skipVotes.length;
  225. songs.getSong(data.currentSong._id, (err, song) => {
  226. if (!err && song) {
  227. data.currentSong.likes = song.likes;
  228. data.currentSong.dislikes = song.dislikes;
  229. } else {
  230. data.currentSong.likes = -1;
  231. data.currentSong.dislikes = -1;
  232. }
  233. next(null, data);
  234. });
  235. }
  236. ], (err, data) => {
  237. if (err) {
  238. err = utils.getError(err);
  239. logger.error("STATIONS_JOIN", `Joining station "${stationId}" failed. "${err}"`);
  240. return cb({'status': 'failure', 'message': err});
  241. }
  242. logger.success("STATIONS_JOIN", `Joined station "${stationId}" successfully.`);
  243. cb({status: 'success', data});
  244. });
  245. },
  246. /**
  247. * Skips the users current station
  248. *
  249. * @param session
  250. * @param stationId - the station id
  251. * @param cb
  252. */
  253. voteSkip: hooks.loginRequired((session, stationId, cb, userId) => {
  254. async.waterfall([
  255. (next) => {
  256. stations.getStation(stationId, next);
  257. },
  258. (station, next) => {
  259. if (!station) return next('Station not found.');
  260. if (!station.currentSong) return next('There is currently no song to skip.');
  261. if (station.currentSong.skipVotes.indexOf(userId) !== -1) return next('You have already voted to skip this song.');
  262. next(null, station);
  263. },
  264. (station, next) => {
  265. db.models.station.update({_id: stationId}, {$push: {"currentSong.skipVotes": userId}}, next)
  266. },
  267. (res, next) => {
  268. stations.updateStation(stationId, next);
  269. },
  270. (station, next) => {
  271. if (!station) return next('Station not found.');
  272. next(null, station);
  273. }
  274. ], (err, station) => {
  275. if (err) {
  276. err = utils.getError(err);
  277. logger.error("STATIONS_VOTE_SKIP", `Vote skipping station "${stationId}" failed. "${err}"`);
  278. return cb({'status': 'failure', 'message': err});
  279. }
  280. logger.success("STATIONS_VOTE_SKIP", `Vote skipping "${stationId}" successful.`);
  281. cache.pub('station.voteSkipSong', stationId);
  282. if (station.currentSong && station.currentSong.skipVotes.length >= 3) stations.skipStation(stationId)();
  283. cb({ status: 'success', message: 'Successfully voted to skip the song.' });
  284. });
  285. }),
  286. forceSkip: hooks.ownerRequired((session, stationId, cb) => {
  287. async.waterfall([
  288. (next) => {
  289. stations.getStation(stationId, next);
  290. },
  291. (station, next) => {
  292. if (!station) return next('Station not found.');
  293. next();
  294. }
  295. ], (err) => {
  296. if (err) {
  297. err = utils.getError(err);
  298. logger.error("STATIONS_FORCE_SKIP", `Force skipping station "${stationId}" failed. "${err}"`);
  299. return cb({'status': 'failure', 'message': err});
  300. }
  301. notifications.unschedule(`stations.nextSong?id=${stationId}`);
  302. stations.skipStation(stationId)();
  303. logger.error("STATIONS_FORCE_SKIP", `Force skipped station "${stationId}" successfully.`);
  304. return cb({'status': 'success', 'message': 'Successfully skipped station.'});
  305. });
  306. }),
  307. /**
  308. * Leaves the users current station
  309. *
  310. * @param session
  311. * @param stationId
  312. * @param cb
  313. * @return {{ status: String, userCount: Integer }}
  314. */
  315. leave: (session, stationId, cb) => {
  316. async.waterfall([
  317. (next) => {
  318. stations.getStation(stationId, next);
  319. },
  320. (station, next) => {
  321. if (!station) return next('Station not found.');
  322. next();
  323. },
  324. (next) => {
  325. cache.client.hincrby('station.userCounts', stationId, -1, next);
  326. }
  327. ], (err, userCount) => {
  328. if (err) {
  329. err = utils.getError(err);
  330. logger.error("STATIONS_LEAVE", `Leaving station "${stationId}" failed. "${err}"`);
  331. return cb({'status': 'failure', 'message': err});
  332. }
  333. logger.error("STATIONS_LEAVE", `Left station "${stationId}" successfully.`);
  334. utils.socketLeaveRooms(session);
  335. return cb({'status': 'success', 'message': 'Successfully left station.', userCount});
  336. });
  337. },
  338. updateDisplayName: hooks.ownerRequired((session, stationId, newDisplayName, cb) => {
  339. db.models.station.update({_id: stationId}, {$set: {displayName: newDisplayName}}, (err) => {
  340. if (err) return cb({ status: 'failure', message: 'Something went wrong when saving the station.' });
  341. stations.updateStation(stationId, () => {
  342. //TODO Pub/sub for displayName change
  343. cb({ status: 'success', message: 'Successfully updated the display name.' });
  344. })
  345. });
  346. }),
  347. updateDescription: hooks.ownerRequired((session, stationId, newDescription, cb) => {
  348. db.models.station.update({_id: stationId}, {$set: {description: newDescription}}, (err) => {
  349. if (err) return cb({ status: 'failure', message: 'Something went wrong when saving the station.' });
  350. stations.updateStation(stationId, () => {
  351. //TODO Pub/sub for description change
  352. cb({ status: 'success', message: 'Successfully updated the description.' });
  353. })
  354. });
  355. }),
  356. updatePrivacy: hooks.ownerRequired((session, stationId, newPrivacy, cb) => {
  357. db.models.station.update({_id: stationId}, {$set: {privacy: newPrivacy}}, (err) => {
  358. if (err) return cb({ status: 'failure', message: 'Something went wrong when saving the station.' });
  359. stations.updateStation(stationId, (err) => {
  360. //TODO Pub/sub for privacy change
  361. cb({ status: 'success', message: 'Successfully updated the privacy.' });
  362. })
  363. });
  364. }),
  365. updatePartyMode: hooks.ownerRequired((session, stationId, newPartyMode, cb) => {
  366. stations.getStation(stationId, (err, station) => {
  367. if (err) return cb({ status: 'failure', message: err });
  368. if (station.partyMode === newPartyMode) return cb({ status: 'failure', message: 'The party mode was already ' + ((newPartyMode) ? 'enabled.' : 'disabled.') });
  369. db.models.station.update({_id: stationId}, {$set: {partyMode: newPartyMode}}, (err) => {
  370. if (err) return cb({ status: 'failure', message: 'Something went wrong when saving the station.' });
  371. stations.updateStation(stationId, () => {
  372. //TODO Pub/sub for privacy change
  373. cache.pub('station.updatePartyMode', {stationId: stationId, partyMode: newPartyMode});
  374. stations.skipStation(stationId)();
  375. cb({ status: 'success', message: 'Successfully updated the party mode.' });
  376. })
  377. });
  378. });
  379. }),
  380. pause: hooks.ownerRequired((session, stationId, cb) => {
  381. stations.getStation(stationId, (err, station) => {
  382. if (err && err !== true) {
  383. return cb({ status: 'error', message: 'An error occurred while pausing the station' });
  384. } else if (station) {
  385. if (!station.paused) {
  386. station.paused = true;
  387. station.pausedAt = Date.now();
  388. db.models.station.update({_id: stationId}, {$set: {paused: true, pausedAt: Date.now()}}, () => {
  389. if (err) return cb({ status: 'failure', message: 'An error occurred while pausing the station.' });
  390. stations.updateStation(stationId, () => {
  391. cache.pub('station.pause', stationId);
  392. notifications.unschedule(`stations.nextSong?id=${stationId}`);
  393. cb({ status: 'success' });
  394. });
  395. });
  396. } else {
  397. cb({ status: 'failure', message: 'That station was already paused.' });
  398. }
  399. cb({ status: 'success' });
  400. } else {
  401. cb({ status: 'failure', message: `That station doesn't exist, it may have been deleted` });
  402. }
  403. });
  404. }),
  405. resume: hooks.ownerRequired((session, stationId, cb) => {
  406. stations.getStation(stationId, (err, station) => {
  407. if (err && err !== true) return cb({ status: 'error', message: 'An error occurred while resuming the station' });
  408. else if (station) {
  409. if (station.paused) {
  410. station.paused = false;
  411. station.timePaused += (Date.now() - station.pausedAt);
  412. db.models.station.update({ _id: stationId }, { $set: { paused: false }, $inc: { timePaused: Date.now() - station.pausedAt } }, () => {
  413. stations.updateStation(stationId, (err, station) => {
  414. cache.pub('station.resume', stationId);
  415. cb({ status: 'success' });
  416. });
  417. });
  418. } else cb({ status: 'failure', message: 'That station is not paused.' });
  419. } else cb({ status: 'failure', message: `That station doesn't exist, it may have been deleted` });
  420. });
  421. }),
  422. remove: hooks.ownerRequired((session, stationId, cb) => {
  423. db.models.station.remove({ _id: stationId }, (err) => {
  424. if (err) return cb({ status: 'failure', message: 'Something went wrong when deleting that station' });
  425. cache.hdel('stations', stationId, () => {
  426. cache.pub('station.remove', stationId);
  427. return cb({ status: 'success', message: 'Station successfully removed' });
  428. });
  429. });
  430. }),
  431. create: hooks.loginRequired((session, data, cb) => {
  432. data._id = data._id.toLowerCase();
  433. let blacklist = ["country", "edm", "musare", "hip-hop", "rap", "top-hits", "todays-hits", "old-school", "christmas", "about", "support", "staff", "help", "news", "terms", "privacy", "profile", "c", "community", "tos", "login", "register", "p", "official", "o", "trap", "faq", "team", "donate", "buy", "shop", "forums", "explore", "settings", "admin", "auth", "reset_password"];
  434. async.waterfall([
  435. (next) => {
  436. return (data) ? next() : cb({ 'status': 'failure', 'message': 'Invalid data' });
  437. },
  438. (next) => {
  439. db.models.station.findOne({ $or: [{_id: data._id}, {displayName: new RegExp(`^${data.displayName}$`, 'i')}] }, next);
  440. },
  441. (station, next) => {
  442. if (station) return next({ 'status': 'failure', 'message': 'A station with that name or display name already exists' });
  443. const { _id, displayName, description, genres, playlist, type, blacklistedGenres } = data;
  444. cache.hget('sessions', session.sessionId, (err, session) => {
  445. if (type === 'official') {
  446. db.models.user.findOne({_id: session.userId}, (err, user) => {
  447. if (err) return next({ 'status': 'failure', 'message': 'Something went wrong when getting your user info.' });
  448. if (!user) return next({ 'status': 'failure', 'message': 'User not found.' });
  449. if (user.role !== 'admin') return next({ 'status': 'failure', 'message': 'Admin required.' });
  450. db.models.station.create({
  451. _id,
  452. displayName,
  453. description,
  454. type,
  455. privacy: 'private',
  456. playlist,
  457. genres,
  458. blacklistedGenres,
  459. currentSong: stations.defaultSong
  460. }, next);
  461. });
  462. } else if (type === 'community') {
  463. if (blacklist.indexOf(_id) !== -1) return next({ 'status': 'failure', 'message': 'That id is blacklisted. Please use a different id.' });
  464. db.models.station.create({
  465. _id,
  466. displayName,
  467. description,
  468. type,
  469. privacy: 'private',
  470. owner: session.userId,
  471. queue: [],
  472. currentSong: null
  473. }, next);
  474. }
  475. });
  476. }
  477. ], (err, station) => {
  478. if (err) {
  479. console.error(err);
  480. return cb({ 'status': 'failure', 'message': err.message});
  481. } else {
  482. cache.pub('station.create', data._id);
  483. cb({ 'status': 'success', 'message': 'Successfully created station' });
  484. }
  485. });
  486. }),
  487. addToQueue: hooks.loginRequired((session, stationId, songId, cb, userId) => {
  488. stations.getStation(stationId, (err, station) => {
  489. if (err) return cb(err);
  490. if (station.type === 'community') {
  491. let has = false;
  492. station.queue.forEach(queueSong => {
  493. if (queueSong._id === songId) has = true;
  494. });
  495. if (has) return cb({'status': 'failure', 'message': 'That song has already been added to the queue'});
  496. if (station.currentSong && station.currentSong._id === songId) return cb({'status': 'failure', 'message': 'That song is currently playing'});
  497. songs.getSong(songId, (err, song) => {
  498. if (err) {
  499. utils.getSongFromYouTube(songId, (song) => {
  500. song.artists = [];
  501. song.skipDuration = 0;
  502. song.likes = -1;
  503. song.dislikes = -1;
  504. song.thumbnail = "empty";
  505. song.explicit = false;
  506. cont(song);
  507. });
  508. } else cont(song);
  509. function cont(song) {
  510. song.requestedBy = userId;
  511. db.models.station.update({ _id: stationId }, { $push: { queue: song } }, (err) => {
  512. if (err) return cb({'status': 'failure', 'message': 'Something went wrong'});
  513. stations.updateStation(stationId, (err, station) => {
  514. if (err) return cb(err);
  515. cache.pub('station.queueUpdate', stationId);
  516. cb({ 'status': 'success', 'message': 'Added that song to the queue' });
  517. });
  518. });
  519. }
  520. });
  521. } else cb({'status': 'failure', 'message': 'That station is not a community station'});
  522. });
  523. }),
  524. removeFromQueue: hooks.ownerRequired((session, stationId, songId, cb, userId) => {
  525. stations.getStation(stationId, (err, station) => {
  526. if (err) return cb(err);
  527. if (station.type === 'community') {
  528. let has = false;
  529. station.queue.forEach((queueSong) => {
  530. if (queueSong._id === songId) {
  531. has = true;
  532. }
  533. });
  534. if (!has) return cb({'status': 'failure', 'message': 'That song is not in the queue.'});
  535. db.models.update({_id: stationId}, {$pull: {queue: {songId: songId}}}, (err) => {
  536. if (err) return cb({'status': 'failure', 'message': 'Something went wrong.'});
  537. stations.updateStation(stationId, (err, station) => {
  538. if (err) return cb(err);
  539. cache.pub('station.queueUpdate', stationId);
  540. });
  541. });
  542. } else cb({'status': 'failure', 'message': 'That station is not a community station.'});
  543. });
  544. }),
  545. getQueue: hooks.adminRequired((session, stationId, cb) => {
  546. stations.getStation(stationId, (err, station) => {
  547. if (err) return cb(err);
  548. if (!station) return cb({'status': 'failure', 'message': 'Station not found.'});
  549. if (station.type === 'community') {
  550. cb({'status': 'success', queue: station.queue});
  551. } else cb({'status': 'failure', 'message': 'That station is not a community station.'});
  552. });
  553. }),
  554. selectPrivatePlaylist: hooks.ownerRequired((session, stationId, playlistId, cb, userId) => {
  555. stations.getStation(stationId, (err, station) => {
  556. if (err) return cb(err);
  557. if (station.type === 'community') {
  558. if (station.privatePlaylist === playlistId) return cb({'status': 'failure', 'message': 'That playlist is already selected.'});
  559. db.models.playlist.findOne({ _id: playlistId }, (err, playlist) => {
  560. if (err) return cb(err);
  561. if (playlist) {
  562. let currentSongIndex = (playlist.songs.length > 0) ? playlist.songs.length - 1 : 0;
  563. db.models.station.update({_id: stationId}, { $set: { privatePlaylist: playlistId, currentSongIndex: currentSongIndex } }, (err) => {
  564. if (err) return cb(err);
  565. stations.updateStation(stationId, (err, station) => {
  566. if (err) return cb(err);
  567. if (!station.partyMode) stations.skipStation(stationId)();
  568. cache.pub('privatePlaylist.selected', {playlistId, stationId});
  569. cb({'status': 'success', 'message': 'Playlist selected.'});
  570. });
  571. });
  572. } else cb({'status': 'failure', 'message': 'Playlist not found.'});
  573. });
  574. } else cb({'status': 'failure', 'message': 'That station is not a community station.'});
  575. });
  576. }),
  577. };