stations.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. 'use strict';
  2. const async = require('async'),
  3. request = require('request'),
  4. config = require('config'),
  5. _ = require('underscore')._;
  6. const hooks = require('./hooks');
  7. const moduleManager = require("../../index");
  8. const db = moduleManager.modules["db"];
  9. const cache = moduleManager.modules["cache"];
  10. const notifications = moduleManager.modules["notifications"];
  11. const utils = moduleManager.modules["utils"];
  12. const logger = moduleManager.modules["logger"];
  13. const stations = moduleManager.modules["stations"];
  14. const songs = moduleManager.modules["songs"];
  15. const activities = moduleManager.modules["activities"];
  16. let userList = {};
  17. let usersPerStation = {};
  18. let usersPerStationCount = {};
  19. setInterval(() => {
  20. let stationsCountUpdated = [];
  21. let stationsUpdated = [];
  22. let oldUsersPerStation = usersPerStation;
  23. usersPerStation = {};
  24. let oldUsersPerStationCount = usersPerStationCount;
  25. usersPerStationCount = {};
  26. async.each(Object.keys(userList), function(socketId, next) {
  27. utils.socketFromSession(socketId).then((socket) => {
  28. let stationId = userList[socketId];
  29. if (!socket || Object.keys(socket.rooms).indexOf(`station.${stationId}`) === -1) {
  30. if (stationsCountUpdated.indexOf(stationId) === -1) stationsCountUpdated.push(stationId);
  31. if (stationsUpdated.indexOf(stationId) === -1) stationsUpdated.push(stationId);
  32. delete userList[socketId];
  33. return next();
  34. }
  35. if (!usersPerStationCount[stationId]) usersPerStationCount[stationId] = 0;
  36. usersPerStationCount[stationId]++;
  37. if (!usersPerStation[stationId]) usersPerStation[stationId] = [];
  38. async.waterfall([
  39. (next) => {
  40. if (!socket.session || !socket.session.sessionId) return next('No session found.');
  41. cache.hget('sessions', socket.session.sessionId, next);
  42. },
  43. (session, next) => {
  44. if (!session) return next('Session not found.');
  45. db.models.user.findOne({_id: session.userId}, next);
  46. },
  47. (user, next) => {
  48. if (!user) return next('User not found.');
  49. if (usersPerStation[stationId].indexOf(user.username) !== -1) return next('User already in the list.');
  50. next(null, user.username);
  51. }
  52. ], (err, username) => {
  53. if (!err) {
  54. usersPerStation[stationId].push(username);
  55. }
  56. next();
  57. });
  58. });
  59. //TODO Code to show users
  60. }, (err) => {
  61. for (let stationId in usersPerStationCount) {
  62. if (oldUsersPerStationCount[stationId] !== usersPerStationCount[stationId]) {
  63. if (stationsCountUpdated.indexOf(stationId) === -1) stationsCountUpdated.push(stationId);
  64. }
  65. }
  66. for (let stationId in usersPerStation) {
  67. if (_.difference(usersPerStation[stationId], oldUsersPerStation[stationId]).length > 0 || _.difference(oldUsersPerStation[stationId], usersPerStation[stationId]).length > 0) {
  68. if (stationsUpdated.indexOf(stationId) === -1) stationsUpdated.push(stationId);
  69. }
  70. }
  71. stationsCountUpdated.forEach((stationId) => {
  72. //logger.info("UPDATE_STATION_USER_COUNT", `Updating user count of ${stationId}.`);
  73. cache.pub('station.updateUserCount', stationId);
  74. });
  75. stationsUpdated.forEach((stationId) => {
  76. //logger.info("UPDATE_STATION_USER_LIST", `Updating user list of ${stationId}.`);
  77. cache.pub('station.updateUsers', stationId);
  78. });
  79. //console.log("Userlist", usersPerStation);
  80. });
  81. }, 3000);
  82. cache.sub('station.updateUsers', stationId => {
  83. let list = usersPerStation[stationId] || [];
  84. utils.emitToRoom(`station.${stationId}`, "event:users.updated", list);
  85. });
  86. cache.sub('station.updateUserCount', stationId => {
  87. let count = usersPerStationCount[stationId] || 0;
  88. utils.emitToRoom(`station.${stationId}`, "event:userCount.updated", count);
  89. stations.getStation(stationId, async (err, station) => {
  90. if (station.privacy === 'public') utils.emitToRoom('home', "event:userCount.updated", stationId, count);
  91. else {
  92. let sockets = await utils.getRoomSockets('home');
  93. for (let socketId in sockets) {
  94. let socket = sockets[socketId];
  95. let session = sockets[socketId].session;
  96. if (session.sessionId) {
  97. cache.hget('sessions', session.sessionId, (err, session) => {
  98. if (!err && session) {
  99. db.models.user.findOne({_id: session.userId}, (err, user) => {
  100. if (user.role === 'admin') socket.emit("event:userCount.updated", stationId, count);
  101. else if (station.type === "community" && station.owner === session.userId) socket.emit("event:userCount.updated", stationId, count);
  102. });
  103. }
  104. });
  105. }
  106. }
  107. }
  108. })
  109. });
  110. cache.sub('station.queueLockToggled', data => {
  111. utils.emitToRoom(`station.${data.stationId}`, "event:queueLockToggled", data.locked)
  112. });
  113. cache.sub('station.updatePartyMode', data => {
  114. utils.emitToRoom(`station.${data.stationId}`, "event:partyMode.updated", data.partyMode);
  115. });
  116. cache.sub('privatePlaylist.selected', data => {
  117. utils.emitToRoom(`station.${data.stationId}`, "event:privatePlaylist.selected", data.playlistId);
  118. });
  119. cache.sub('station.pause', stationId => {
  120. stations.getStation(stationId, (err, station) => {
  121. utils.emitToRoom(`station.${stationId}`, "event:stations.pause", { pausedAt: station.pausedAt });
  122. });
  123. });
  124. cache.sub('station.resume', stationId => {
  125. stations.getStation(stationId, (err, station) => {
  126. utils.emitToRoom(`station.${stationId}`, "event:stations.resume", { timePaused: station.timePaused });
  127. });
  128. });
  129. cache.sub('station.queueUpdate', stationId => {
  130. stations.getStation(stationId, (err, station) => {
  131. if (!err) utils.emitToRoom(`station.${stationId}`, "event:queue.update", station.queue);
  132. });
  133. });
  134. cache.sub('station.voteSkipSong', stationId => {
  135. utils.emitToRoom(`station.${stationId}`, "event:song.voteSkipSong");
  136. });
  137. cache.sub('station.remove', stationId => {
  138. utils.emitToRoom(`station.${stationId}`, 'event:stations.remove');
  139. utils.emitToRoom('admin.stations', 'event:admin.station.removed', stationId);
  140. });
  141. cache.sub('station.create', stationId => {
  142. stations.initializeStation(stationId, async (err, station) => {
  143. station.userCount = usersPerStationCount[stationId] || 0;
  144. if (err) console.error(err);
  145. utils.emitToRoom('admin.stations', 'event:admin.station.added', station);
  146. // TODO If community, check if on whitelist
  147. if (station.privacy === 'public') utils.emitToRoom('home', "event:stations.created", station);
  148. else {
  149. let sockets = await utils.getRoomSockets('home');
  150. for (let socketId in sockets) {
  151. let socket = sockets[socketId];
  152. let session = sockets[socketId].session;
  153. if (session.sessionId) {
  154. cache.hget('sessions', session.sessionId, (err, session) => {
  155. if (!err && session) {
  156. db.models.user.findOne({_id: session.userId}, (err, user) => {
  157. if (user.role === 'admin') socket.emit("event:stations.created", station);
  158. else if (station.type === "community" && station.owner === session.userId) socket.emit("event:stations.created", station);
  159. });
  160. }
  161. });
  162. }
  163. }
  164. }
  165. });
  166. });
  167. module.exports = {
  168. /**
  169. * Get a list of all the stations
  170. *
  171. * @param session
  172. * @param cb
  173. * @return {{ status: String, stations: Array }}
  174. */
  175. index: (session, cb) => {
  176. async.waterfall([
  177. (next) => {
  178. cache.hgetall('stations', next);
  179. },
  180. (stations, next) => {
  181. let resultStations = [];
  182. for (let id in stations) {
  183. resultStations.push(stations[id]);
  184. }
  185. next(null, stations);
  186. },
  187. (stationsArray, next) => {
  188. let resultStations = [];
  189. async.each(stationsArray, (station, next) => {
  190. async.waterfall([
  191. (next) => {
  192. stations.canUserViewStation(station, session.userId, (err, exists) => {
  193. next(err, exists);
  194. });
  195. }
  196. ], (err, exists) => {
  197. station.userCount = usersPerStationCount[station._id] || 0;
  198. if (exists) resultStations.push(station);
  199. next();
  200. });
  201. }, () => {
  202. next(null, resultStations);
  203. });
  204. }
  205. ], async (err, stations) => {
  206. if (err) {
  207. err = await utils.getError(err);
  208. logger.error("STATIONS_INDEX", `Indexing stations failed. "${err}"`);
  209. return cb({'status': 'failure', 'message': err});
  210. }
  211. logger.success("STATIONS_INDEX", `Indexing stations successful.`, false);
  212. return cb({'status': 'success', 'stations': stations});
  213. });
  214. },
  215. /**
  216. * Obtains basic metadata of a station in order to format an activity
  217. *
  218. * @param session
  219. * @param stationId - the station id
  220. * @param cb
  221. */
  222. getStationForActivity: (session, stationId, cb) => {
  223. async.waterfall([
  224. (next) => {
  225. stations.getStation(stationId, next);
  226. }
  227. ], async (err, station) => {
  228. if (err) {
  229. err = await utils.getError(err);
  230. logger.error("STATIONS_GET_STATION_FOR_ACTIVITY", `Failed to obtain metadata of station ${stationId} for activity formatting. "${err}"`);
  231. return cb({ status: 'failure', message: err });
  232. } else {
  233. logger.success("STATIONS_GET_STATION_FOR_ACTIVITY", `Obtained metadata of station ${stationId} for activity formatting successfully.`);
  234. return cb({ status: "success", data: {
  235. title: station.displayName,
  236. thumbnail: station.currentSong ? station.currentSong.thumbnail : ""
  237. } });
  238. }
  239. });
  240. },
  241. /**
  242. * Verifies that a station exists
  243. *
  244. * @param session
  245. * @param stationName - the station name
  246. * @param cb
  247. */
  248. existsByName: (session, stationName, cb) => {
  249. async.waterfall([
  250. (next) => {
  251. stations.getStationByName(stationName, next);
  252. },
  253. (station, next) => {
  254. if (!station) return next(null, false);
  255. stations.canUserViewStation(station, session.userId, (err, exists) => {
  256. next(err, exists);
  257. });
  258. }
  259. ], async (err, exists) => {
  260. if (err) {
  261. err = await utils.getError(err);
  262. logger.error("STATION_EXISTS_BY_NAME", `Checking if station "${stationName}" exists failed. "${err}"`);
  263. return cb({'status': 'failure', 'message': err});
  264. }
  265. logger.success("STATION_EXISTS_BY_NAME", `Station "${stationName}" exists successfully.`/*, false*/);
  266. cb({status: 'success', exists});
  267. });
  268. },
  269. /**
  270. * Gets the official playlist for a station
  271. *
  272. * @param session
  273. * @param stationId - the station id
  274. * @param cb
  275. */
  276. getPlaylist: (session, stationId, cb) => {
  277. async.waterfall([
  278. (next) => {
  279. stations.getStation(stationId, next);
  280. },
  281. (station, next) => {
  282. stations.canUserViewStation(station, session.userId, (err, canView) => {
  283. if (err) return next(err);
  284. if (canView) return next(null, station);
  285. return next('Insufficient permissions.');
  286. });
  287. },
  288. (station, next) => {
  289. if (!station) return next('Station not found.');
  290. else if (station.type !== 'official') return next('This is not an official station.');
  291. else next();
  292. },
  293. (next) => {
  294. cache.hget('officialPlaylists', stationId, next);
  295. },
  296. (playlist, next) => {
  297. if (!playlist) return next('Playlist not found.');
  298. next(null, playlist);
  299. }
  300. ], async (err, playlist) => {
  301. if (err) {
  302. err = await utils.getError(err);
  303. logger.error("STATIONS_GET_PLAYLIST", `Getting playlist for station "${stationId}" failed. "${err}"`);
  304. return cb({ status: 'failure', message: err });
  305. } else {
  306. logger.success("STATIONS_GET_PLAYLIST", `Got playlist for station "${stationId}" successfully.`, false);
  307. cb({ status: 'success', data: playlist.songs });
  308. }
  309. });
  310. },
  311. /**
  312. * Joins the station by its name
  313. *
  314. * @param session
  315. * @param stationName - the station name
  316. * @param cb
  317. * @return {{ status: String, userCount: Integer }}
  318. */
  319. join: (session, stationName, cb) => {
  320. async.waterfall([
  321. (next) => {
  322. stations.getStationByName(stationName, next);
  323. },
  324. (station, next) => {
  325. if (!station) return next('Station not found.');
  326. stations.canUserViewStation(station, session.userId, (err, canView) => {
  327. if (err) return next(err);
  328. if (!canView) next("Not allowed to join station.");
  329. else next(null, station);
  330. });
  331. },
  332. (station, next) => {
  333. utils.socketJoinRoom(session.socketId, `station.${station._id}`);
  334. let data = {
  335. _id: station._id,
  336. type: station.type,
  337. currentSong: station.currentSong,
  338. startedAt: station.startedAt,
  339. paused: station.paused,
  340. timePaused: station.timePaused,
  341. pausedAt: station.pausedAt,
  342. description: station.description,
  343. displayName: station.displayName,
  344. privacy: station.privacy,
  345. locked: station.locked,
  346. partyMode: station.partyMode,
  347. owner: station.owner,
  348. privatePlaylist: station.privatePlaylist
  349. };
  350. userList[session.socketId] = station._id;
  351. next(null, data);
  352. },
  353. (data, next) => {
  354. data = JSON.parse(JSON.stringify(data));
  355. data.userCount = usersPerStationCount[data._id] || 0;
  356. data.users = usersPerStation[data._id] || [];
  357. if (!data.currentSong || !data.currentSong.title) return next(null, data);
  358. utils.socketJoinSongRoom(session.socketId, `song.${data.currentSong.songId}`);
  359. data.currentSong.skipVotes = data.currentSong.skipVotes.length;
  360. songs.getSongFromId(data.currentSong.songId, (err, song) => {
  361. if (!err && song) {
  362. data.currentSong.likes = song.likes;
  363. data.currentSong.dislikes = song.dislikes;
  364. } else {
  365. data.currentSong.likes = -1;
  366. data.currentSong.dislikes = -1;
  367. }
  368. next(null, data);
  369. });
  370. }
  371. ], async (err, data) => {
  372. if (err) {
  373. err = await utils.getError(err);
  374. logger.error("STATIONS_JOIN", `Joining station "${stationName}" failed. "${err}"`);
  375. return cb({'status': 'failure', 'message': err});
  376. }
  377. logger.success("STATIONS_JOIN", `Joined station "${data._id}" successfully.`);
  378. cb({status: 'success', data});
  379. });
  380. },
  381. /**
  382. * Toggles if a station is locked
  383. *
  384. * @param session
  385. * @param stationId - the station id
  386. * @param cb
  387. */
  388. toggleLock: hooks.ownerRequired((session, stationId, cb) => {
  389. async.waterfall([
  390. (next) => {
  391. stations.getStation(stationId, next);
  392. },
  393. (station, next) => {
  394. db.models.station.updateOne({ _id: stationId }, { $set: { locked: !station.locked} }, next);
  395. },
  396. (res, next) => {
  397. stations.updateStation(stationId, next);
  398. }
  399. ], async (err, station) => {
  400. if (err) {
  401. err = await utils.getError(err);
  402. logger.error("STATIONS_UPDATE_LOCKED_STATUS", `Toggling the queue lock for station "${stationId}" failed. "${err}"`);
  403. return cb({ status: 'failure', message: err });
  404. } else {
  405. logger.success("STATIONS_UPDATE_LOCKED_STATUS", `Toggled the queue lock for station "${stationId}" successfully to "${station.locked}".`);
  406. cache.pub('station.queueLockToggled', {stationId, locked: station.locked});
  407. return cb({ status: 'success', data: station.locked });
  408. }
  409. });
  410. }),
  411. /**
  412. * Votes to skip a station
  413. *
  414. * @param session
  415. * @param stationId - the station id
  416. * @param cb
  417. */
  418. voteSkip: hooks.loginRequired((session, stationId, cb) => {
  419. let skipVotes = 0;
  420. let shouldSkip = false;
  421. async.waterfall([
  422. (next) => {
  423. stations.getStation(stationId, next);
  424. },
  425. (station, next) => {
  426. if (!station) return next('Station not found.');
  427. stations.canUserViewStation(station, session.userId, (err, canView) => {
  428. if (err) return next(err);
  429. if (canView) return next(null, station);
  430. return next('Insufficient permissions.');
  431. });
  432. },
  433. (station, next) => {
  434. if (!station.currentSong) return next('There is currently no song to skip.');
  435. if (station.currentSong.skipVotes.indexOf(session.userId) !== -1) return next('You have already voted to skip this song.');
  436. next(null, station);
  437. },
  438. (station, next) => {
  439. db.models.station.updateOne({_id: stationId}, {$push: {"currentSong.skipVotes": session.userId}}, next)
  440. },
  441. (res, next) => {
  442. stations.updateStation(stationId, next);
  443. },
  444. (station, next) => {
  445. if (!station) return next('Station not found.');
  446. next(null, station);
  447. },
  448. (station, next) => {
  449. skipVotes = station.currentSong.skipVotes.length;
  450. utils.getRoomSockets(`station.${stationId}`).then(sockets => {
  451. next(null, sockets);
  452. }).catch(next);
  453. },
  454. (sockets, next) => {
  455. if (sockets.length <= skipVotes) shouldSkip = true;
  456. next();
  457. }
  458. ], async (err, station) => {
  459. if (err) {
  460. err = await utils.getError(err);
  461. logger.error("STATIONS_VOTE_SKIP", `Vote skipping station "${stationId}" failed. "${err}"`);
  462. return cb({'status': 'failure', 'message': err});
  463. }
  464. logger.success("STATIONS_VOTE_SKIP", `Vote skipping "${stationId}" successful.`);
  465. cache.pub('station.voteSkipSong', stationId);
  466. cb({ status: 'success', message: 'Successfully voted to skip the song.' });
  467. if (shouldSkip) stations.skipStation(stationId)();
  468. });
  469. }),
  470. /**
  471. * Force skips a station
  472. *
  473. * @param session
  474. * @param stationId - the station id
  475. * @param cb
  476. */
  477. forceSkip: hooks.ownerRequired((session, stationId, cb) => {
  478. async.waterfall([
  479. (next) => {
  480. stations.getStation(stationId, next);
  481. },
  482. (station, next) => {
  483. if (!station) return next('Station not found.');
  484. next();
  485. }
  486. ], async (err) => {
  487. if (err) {
  488. err = await utils.getError(err);
  489. logger.error("STATIONS_FORCE_SKIP", `Force skipping station "${stationId}" failed. "${err}"`);
  490. return cb({'status': 'failure', 'message': err});
  491. }
  492. notifications.unschedule(`stations.nextSong?id=${stationId}`);
  493. stations.skipStation(stationId)();
  494. logger.success("STATIONS_FORCE_SKIP", `Force skipped station "${stationId}" successfully.`);
  495. return cb({'status': 'success', 'message': 'Successfully skipped station.'});
  496. });
  497. }),
  498. /**
  499. * Leaves the user's current station
  500. *
  501. * @param session
  502. * @param stationId
  503. * @param cb
  504. * @return {{ status: String, userCount: Integer }}
  505. */
  506. leave: (session, stationId, cb) => {
  507. async.waterfall([
  508. (next) => {
  509. stations.getStation(stationId, next);
  510. },
  511. (station, next) => {
  512. if (!station) return next('Station not found.');
  513. next();
  514. }
  515. ], async (err, userCount) => {
  516. if (err) {
  517. err = await utils.getError(err);
  518. logger.error("STATIONS_LEAVE", `Leaving station "${stationId}" failed. "${err}"`);
  519. return cb({'status': 'failure', 'message': err});
  520. }
  521. logger.success("STATIONS_LEAVE", `Left station "${stationId}" successfully.`);
  522. utils.socketLeaveRooms(session);
  523. delete userList[session.socketId];
  524. return cb({'status': 'success', 'message': 'Successfully left station.', userCount});
  525. });
  526. },
  527. /**
  528. * Updates a station's name
  529. *
  530. * @param session
  531. * @param stationId - the station id
  532. * @param newName - the new station name
  533. * @param cb
  534. */
  535. updateName: hooks.ownerRequired((session, stationId, newName, cb) => {
  536. async.waterfall([
  537. (next) => {
  538. db.models.station.updateOne({_id: stationId}, {$set: {name: newName}}, {runValidators: true}, next);
  539. },
  540. (res, next) => {
  541. stations.updateStation(stationId, next);
  542. }
  543. ], async (err) => {
  544. if (err) {
  545. err = await utils.getError(err);
  546. logger.error("STATIONS_UPDATE_NAME", `Updating station "${stationId}" name to "${newName}" failed. "${err}"`);
  547. return cb({'status': 'failure', 'message': err});
  548. }
  549. logger.success("STATIONS_UPDATE_NAME", `Updated station "${stationId}" name to "${newName}" successfully.`);
  550. return cb({'status': 'success', 'message': 'Successfully updated the name.'});
  551. });
  552. }),
  553. /**
  554. * Updates a station's display name
  555. *
  556. * @param session
  557. * @param stationId - the station id
  558. * @param newDisplayName - the new station display name
  559. * @param cb
  560. */
  561. updateDisplayName: hooks.ownerRequired((session, stationId, newDisplayName, cb) => {
  562. async.waterfall([
  563. (next) => {
  564. db.models.station.updateOne({_id: stationId}, {$set: {displayName: newDisplayName}}, {runValidators: true}, next);
  565. },
  566. (res, next) => {
  567. stations.updateStation(stationId, next);
  568. }
  569. ], async (err) => {
  570. if (err) {
  571. err = await utils.getError(err);
  572. logger.error("STATIONS_UPDATE_DISPLAY_NAME", `Updating station "${stationId}" displayName to "${newDisplayName}" failed. "${err}"`);
  573. return cb({'status': 'failure', 'message': err});
  574. }
  575. logger.success("STATIONS_UPDATE_DISPLAY_NAME", `Updated station "${stationId}" displayName to "${newDisplayName}" successfully.`);
  576. return cb({'status': 'success', 'message': 'Successfully updated the display name.'});
  577. });
  578. }),
  579. /**
  580. * Updates a station's description
  581. *
  582. * @param session
  583. * @param stationId - the station id
  584. * @param newDescription - the new station description
  585. * @param cb
  586. */
  587. updateDescription: hooks.ownerRequired((session, stationId, newDescription, cb) => {
  588. async.waterfall([
  589. (next) => {
  590. db.models.station.updateOne({_id: stationId}, {$set: {description: newDescription}}, {runValidators: true}, next);
  591. },
  592. (res, next) => {
  593. stations.updateStation(stationId, next);
  594. }
  595. ], async (err) => {
  596. if (err) {
  597. err = await utils.getError(err);
  598. logger.error("STATIONS_UPDATE_DESCRIPTION", `Updating station "${stationId}" description to "${newDescription}" failed. "${err}"`);
  599. return cb({'status': 'failure', 'message': err});
  600. }
  601. logger.success("STATIONS_UPDATE_DESCRIPTION", `Updated station "${stationId}" description to "${newDescription}" successfully.`);
  602. return cb({'status': 'success', 'message': 'Successfully updated the description.'});
  603. });
  604. }),
  605. /**
  606. * Updates a station's privacy
  607. *
  608. * @param session
  609. * @param stationId - the station id
  610. * @param newPrivacy - the new station privacy
  611. * @param cb
  612. */
  613. updatePrivacy: hooks.ownerRequired((session, stationId, newPrivacy, cb) => {
  614. async.waterfall([
  615. (next) => {
  616. db.models.station.updateOne({_id: stationId}, {$set: {privacy: newPrivacy}}, {runValidators: true}, next);
  617. },
  618. (res, next) => {
  619. stations.updateStation(stationId, next);
  620. }
  621. ], async (err) => {
  622. if (err) {
  623. err = await utils.getError(err);
  624. logger.error("STATIONS_UPDATE_PRIVACY", `Updating station "${stationId}" privacy to "${newPrivacy}" failed. "${err}"`);
  625. return cb({'status': 'failure', 'message': err});
  626. }
  627. logger.success("STATIONS_UPDATE_PRIVACY", `Updated station "${stationId}" privacy to "${newPrivacy}" successfully.`);
  628. return cb({'status': 'success', 'message': 'Successfully updated the privacy.'});
  629. });
  630. }),
  631. /**
  632. * Updates a station's genres
  633. *
  634. * @param session
  635. * @param stationId - the station id
  636. * @param newGenres - the new station genres
  637. * @param cb
  638. */
  639. updateGenres: hooks.ownerRequired((session, stationId, newGenres, cb) => {
  640. async.waterfall([
  641. (next) => {
  642. db.models.station.updateOne({_id: stationId}, {$set: {genres: newGenres}}, {runValidators: true}, next);
  643. },
  644. (res, next) => {
  645. stations.updateStation(stationId, next);
  646. }
  647. ], async (err) => {
  648. if (err) {
  649. err = await utils.getError(err);
  650. logger.error("STATIONS_UPDATE_GENRES", `Updating station "${stationId}" genres to "${newGenres}" failed. "${err}"`);
  651. return cb({'status': 'failure', 'message': err});
  652. }
  653. logger.success("STATIONS_UPDATE_GENRES", `Updated station "${stationId}" genres to "${newGenres}" successfully.`);
  654. return cb({'status': 'success', 'message': 'Successfully updated the genres.'});
  655. });
  656. }),
  657. /**
  658. * Updates a station's blacklisted genres
  659. *
  660. * @param session
  661. * @param stationId - the station id
  662. * @param newBlacklistedGenres - the new station blacklisted genres
  663. * @param cb
  664. */
  665. updateBlacklistedGenres: hooks.ownerRequired((session, stationId, newBlacklistedGenres, cb) => {
  666. async.waterfall([
  667. (next) => {
  668. db.models.station.updateOne({_id: stationId}, {$set: {blacklistedGenres: newBlacklistedGenres}}, {runValidators: true}, next);
  669. },
  670. (res, next) => {
  671. stations.updateStation(stationId, next);
  672. }
  673. ], async (err) => {
  674. if (err) {
  675. err = await utils.getError(err);
  676. logger.error("STATIONS_UPDATE_BLACKLISTED_GENRES", `Updating station "${stationId}" blacklisted genres to "${newBlacklistedGenres}" failed. "${err}"`);
  677. return cb({'status': 'failure', 'message': err});
  678. }
  679. logger.success("STATIONS_UPDATE_BLACKLISTED_GENRES", `Updated station "${stationId}" blacklisted genres to "${newBlacklistedGenres}" successfully.`);
  680. return cb({'status': 'success', 'message': 'Successfully updated the blacklisted genres.'});
  681. });
  682. }),
  683. /**
  684. * Updates a station's party mode
  685. *
  686. * @param session
  687. * @param stationId - the station id
  688. * @param newPartyMode - the new station party mode
  689. * @param cb
  690. */
  691. updatePartyMode: hooks.ownerRequired((session, stationId, newPartyMode, cb) => {
  692. async.waterfall([
  693. (next) => {
  694. stations.getStation(stationId, next);
  695. },
  696. (station, next) => {
  697. if (!station) return next('Station not found.');
  698. if (station.partyMode === newPartyMode) return next('The party mode was already ' + ((newPartyMode) ? 'enabled.' : 'disabled.'));
  699. db.models.station.updateOne({_id: stationId}, {$set: {partyMode: newPartyMode}}, {runValidators: true}, next);
  700. },
  701. (res, next) => {
  702. stations.updateStation(stationId, next);
  703. }
  704. ], async (err) => {
  705. if (err) {
  706. err = await utils.getError(err);
  707. logger.error("STATIONS_UPDATE_PARTY_MODE", `Updating station "${stationId}" party mode to "${newPartyMode}" failed. "${err}"`);
  708. return cb({'status': 'failure', 'message': err});
  709. }
  710. logger.success("STATIONS_UPDATE_PARTY_MODE", `Updated station "${stationId}" party mode to "${newPartyMode}" successfully.`);
  711. cache.pub('station.updatePartyMode', {stationId: stationId, partyMode: newPartyMode});
  712. stations.skipStation(stationId)();
  713. return cb({'status': 'success', 'message': 'Successfully updated the party mode.'});
  714. });
  715. }),
  716. /**
  717. * Pauses a station
  718. *
  719. * @param session
  720. * @param stationId - the station id
  721. * @param cb
  722. */
  723. pause: hooks.ownerRequired((session, stationId, cb) => {
  724. async.waterfall([
  725. (next) => {
  726. stations.getStation(stationId, next);
  727. },
  728. (station, next) => {
  729. if (!station) return next('Station not found.');
  730. if (station.paused) return next('That station was already paused.');
  731. db.models.station.updateOne({_id: stationId}, {$set: {paused: true, pausedAt: Date.now()}}, next);
  732. },
  733. (res, next) => {
  734. stations.updateStation(stationId, next);
  735. }
  736. ], async (err) => {
  737. if (err) {
  738. err = await utils.getError(err);
  739. logger.error("STATIONS_PAUSE", `Pausing station "${stationId}" failed. "${err}"`);
  740. return cb({'status': 'failure', 'message': err});
  741. }
  742. logger.success("STATIONS_PAUSE", `Paused station "${stationId}" successfully.`);
  743. cache.pub('station.pause', stationId);
  744. notifications.unschedule(`stations.nextSong?id=${stationId}`);
  745. return cb({'status': 'success', 'message': 'Successfully paused.'});
  746. });
  747. }),
  748. /**
  749. * Resumes a station
  750. *
  751. * @param session
  752. * @param stationId - the station id
  753. * @param cb
  754. */
  755. resume: hooks.ownerRequired((session, stationId, cb) => {
  756. async.waterfall([
  757. (next) => {
  758. stations.getStation(stationId, next);
  759. },
  760. (station, next) => {
  761. if (!station) return next('Station not found.');
  762. if (!station.paused) return next('That station is not paused.');
  763. station.timePaused += (Date.now() - station.pausedAt);
  764. db.models.station.updateOne({_id: stationId}, {$set: {paused: false}, $inc: {timePaused: Date.now() - station.pausedAt}}, next);
  765. },
  766. (res, next) => {
  767. stations.updateStation(stationId, next);
  768. }
  769. ], async (err) => {
  770. if (err) {
  771. err = await utils.getError(err);
  772. logger.error("STATIONS_RESUME", `Resuming station "${stationId}" failed. "${err}"`);
  773. return cb({'status': 'failure', 'message': err});
  774. }
  775. logger.success("STATIONS_RESUME", `Resuming station "${stationId}" successfully.`);
  776. cache.pub('station.resume', stationId);
  777. return cb({'status': 'success', 'message': 'Successfully resumed.'});
  778. });
  779. }),
  780. /**
  781. * Removes a station
  782. *
  783. * @param session
  784. * @param stationId - the station id
  785. * @param cb
  786. */
  787. remove: hooks.ownerRequired((session, stationId, cb) => {
  788. async.waterfall([
  789. (next) => {
  790. db.models.station.deleteOne({ _id: stationId }, err => next(err));
  791. },
  792. (next) => {
  793. cache.hdel('stations', stationId, err => next(err));
  794. }
  795. ], async (err) => {
  796. if (err) {
  797. err = await utils.getError(err);
  798. logger.error("STATIONS_REMOVE", `Removing station "${stationId}" failed. "${err}"`);
  799. return cb({ 'status': 'failure', 'message': err });
  800. }
  801. logger.success("STATIONS_REMOVE", `Removing station "${stationId}" successfully.`);
  802. cache.pub('station.remove', stationId);
  803. activities.addActivity(session.userId, "deleted_station", [ stationId ]);
  804. return cb({ 'status': 'success', 'message': 'Successfully removed.' });
  805. });
  806. }),
  807. /**
  808. * Create a station
  809. *
  810. * @param session
  811. * @param data - the station data
  812. * @param cb
  813. */
  814. create: hooks.loginRequired((session, data, cb) => {
  815. data.name = data.name.toLowerCase();
  816. 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"];
  817. async.waterfall([
  818. (next) => {
  819. if (!data) return next('Invalid data.');
  820. next();
  821. },
  822. (next) => {
  823. db.models.station.findOne({ $or: [{name: data.name}, {displayName: new RegExp(`^${data.displayName}$`, 'i')}] }, next);
  824. },
  825. (station, next) => {
  826. if (station) return next('A station with that name or display name already exists.');
  827. const { name, displayName, description, genres, playlist, type, blacklistedGenres } = data;
  828. if (type === 'official') {
  829. db.models.user.findOne({_id: session.userId}, (err, user) => {
  830. if (err) return next(err);
  831. if (!user) return next('User not found.');
  832. if (user.role !== 'admin') return next('Admin required.');
  833. db.models.station.create({
  834. name,
  835. displayName,
  836. description,
  837. type,
  838. privacy: 'private',
  839. playlist,
  840. genres,
  841. blacklistedGenres,
  842. currentSong: stations.defaultSong
  843. }, next);
  844. });
  845. } else if (type === 'community') {
  846. if (blacklist.indexOf(name) !== -1) return next('That name is blacklisted. Please use a different name.');
  847. db.models.station.create({
  848. name,
  849. displayName,
  850. description,
  851. type,
  852. privacy: 'private',
  853. owner: session.userId,
  854. queue: [],
  855. currentSong: null
  856. }, next);
  857. }
  858. }
  859. ], async (err, station) => {
  860. if (err) {
  861. err = await utils.getError(err);
  862. logger.error("STATIONS_CREATE", `Creating station failed. "${err}"`);
  863. return cb({'status': 'failure', 'message': err});
  864. }
  865. logger.success("STATIONS_CREATE", `Created station "${station._id}" successfully.`);
  866. cache.pub('station.create', station._id);
  867. activities.addActivity(session.userId, "created_station", [ station._id ]);
  868. return cb({'status': 'success', 'message': 'Successfully created station.'});
  869. });
  870. }),
  871. /**
  872. * Adds song to station queue
  873. *
  874. * @param session
  875. * @param stationId - the station id
  876. * @param songId - the song id
  877. * @param cb
  878. */
  879. addToQueue: hooks.loginRequired((session, stationId, songId, cb) => {
  880. async.waterfall([
  881. (next) => {
  882. stations.getStation(stationId, next);
  883. },
  884. (station, next) => {
  885. if (!station) return next('Station not found.');
  886. if (station.locked) {
  887. db.models.user.findOne({ _id: session.userId }, (err, user) => {
  888. if (user.role !== 'admin' && station.owner !== session.userId) return next('Only owners and admins can add songs to a locked queue.');
  889. else return next(null, station);
  890. });
  891. } else {
  892. return next(null, station);
  893. }
  894. },
  895. (station, next) => {
  896. if (station.type !== 'community') return next('That station is not a community station.');
  897. stations.canUserViewStation(station, session.userId, (err, canView) => {
  898. if (err) return next(err);
  899. if (canView) return next(null, station);
  900. return next('Insufficient permissions.');
  901. });
  902. },
  903. (station, next) => {
  904. if (station.currentSong && station.currentSong.songId === songId) return next('That song is currently playing.');
  905. async.each(station.queue, (queueSong, next) => {
  906. if (queueSong.songId === songId) return next('That song is already in the queue.');
  907. next();
  908. }, (err) => {
  909. next(err, station);
  910. });
  911. },
  912. (station, next) => {
  913. songs.getSong(songId, (err, song) => {
  914. if (!err && song) return next(null, song, station);
  915. utils.getSongFromYouTube(songId, (song) => {
  916. song.artists = [];
  917. song.skipDuration = 0;
  918. song.likes = -1;
  919. song.dislikes = -1;
  920. song.thumbnail = "empty";
  921. song.explicit = false;
  922. next(null, song, station);
  923. });
  924. });
  925. },
  926. (song, station, next) => {
  927. let queue = station.queue;
  928. song.requestedBy = session.userId;
  929. queue.push(song);
  930. let totalDuration = 0;
  931. queue.forEach((song) => {
  932. totalDuration += song.duration;
  933. });
  934. if (totalDuration >= 3600 * 3) return next('The max length of the queue is 3 hours.');
  935. next(null, song, station);
  936. },
  937. (song, station, next) => {
  938. let queue = station.queue;
  939. if (queue.length === 0) return next(null, song, station);
  940. let totalDuration = 0;
  941. const userId = queue[queue.length - 1].requestedBy;
  942. station.queue.forEach((song) => {
  943. if (userId === song.requestedBy) {
  944. totalDuration += song.duration;
  945. }
  946. });
  947. if(totalDuration >= 900) return next('The max length of songs per user is 15 minutes.');
  948. next(null, song, station);
  949. },
  950. (song, station, next) => {
  951. let queue = station.queue;
  952. if (queue.length === 0) return next(null, song);
  953. let totalSongs = 0;
  954. const userId = queue[queue.length - 1].requestedBy;
  955. queue.forEach((song) => {
  956. if (userId === song.requestedBy) {
  957. totalSongs++;
  958. }
  959. });
  960. if (totalSongs <= 2) return next(null, song);
  961. if (totalSongs > 3) return next('The max amount of songs per user is 3, and only 2 in a row is allowed.');
  962. if (queue[queue.length - 2].requestedBy !== userId || queue[queue.length - 3] !== userId) return next('The max amount of songs per user is 3, and only 2 in a row is allowed.');
  963. next(null, song);
  964. },
  965. (song, next) => {
  966. db.models.station.updateOne({_id: stationId}, {$push: {queue: song}}, {runValidators: true}, next);
  967. },
  968. (res, next) => {
  969. stations.updateStation(stationId, next);
  970. }
  971. ], async (err, station) => {
  972. if (err) {
  973. err = await utils.getError(err);
  974. logger.error("STATIONS_ADD_SONG_TO_QUEUE", `Adding song "${songId}" to station "${stationId}" queue failed. "${err}"`);
  975. return cb({'status': 'failure', 'message': err});
  976. }
  977. logger.success("STATIONS_ADD_SONG_TO_QUEUE", `Added song "${songId}" to station "${stationId}" successfully.`);
  978. cache.pub('station.queueUpdate', stationId);
  979. return cb({'status': 'success', 'message': 'Successfully added song to queue.'});
  980. });
  981. }),
  982. /**
  983. * Removes song from station queue
  984. *
  985. * @param session
  986. * @param stationId - the station id
  987. * @param songId - the song id
  988. * @param cb
  989. */
  990. removeFromQueue: hooks.ownerRequired((session, stationId, songId, cb) => {
  991. async.waterfall([
  992. (next) => {
  993. if (!songId) return next('Invalid song id.');
  994. stations.getStation(stationId, next);
  995. },
  996. (station, next) => {
  997. if (!station) return next('Station not found.');
  998. if (station.type !== 'community') return next('Station is not a community station.');
  999. async.each(station.queue, (queueSong, next) => {
  1000. if (queueSong.songId === songId) return next(true);
  1001. next();
  1002. }, (err) => {
  1003. if (err === true) return next();
  1004. next('Song is not currently in the queue.');
  1005. });
  1006. },
  1007. (next) => {
  1008. db.models.station.updateOne({_id: stationId}, {$pull: {queue: {songId: songId}}}, next);
  1009. },
  1010. (res, next) => {
  1011. stations.updateStation(stationId, next);
  1012. }
  1013. ], async (err, station) => {
  1014. if (err) {
  1015. err = await utils.getError(err);
  1016. logger.error("STATIONS_REMOVE_SONG_TO_QUEUE", `Removing song "${songId}" from station "${stationId}" queue failed. "${err}"`);
  1017. return cb({'status': 'failure', 'message': err});
  1018. }
  1019. logger.success("STATIONS_REMOVE_SONG_TO_QUEUE", `Removed song "${songId}" from station "${stationId}" successfully.`);
  1020. cache.pub('station.queueUpdate', stationId);
  1021. return cb({'status': 'success', 'message': 'Successfully removed song from queue.'});
  1022. });
  1023. }),
  1024. /**
  1025. * Gets the queue from a station
  1026. *
  1027. * @param session
  1028. * @param stationId - the station id
  1029. * @param cb
  1030. */
  1031. getQueue: (session, stationId, cb) => {
  1032. async.waterfall([
  1033. (next) => {
  1034. stations.getStation(stationId, next);
  1035. },
  1036. (station, next) => {
  1037. if (!station) return next('Station not found.');
  1038. if (station.type !== 'community') return next('Station is not a community station.');
  1039. next(null, station);
  1040. },
  1041. (station, next) => {
  1042. stations.canUserViewStation(station, session.userId, (err, canView) => {
  1043. if (err) return next(err);
  1044. if (canView) return next(null, station);
  1045. return next('Insufficient permissions.');
  1046. });
  1047. }
  1048. ], async (err, station) => {
  1049. if (err) {
  1050. err = await utils.getError(err);
  1051. logger.error("STATIONS_GET_QUEUE", `Getting queue for station "${stationId}" failed. "${err}"`);
  1052. return cb({'status': 'failure', 'message': err});
  1053. }
  1054. logger.success("STATIONS_GET_QUEUE", `Got queue for station "${stationId}" successfully.`);
  1055. return cb({'status': 'success', 'message': 'Successfully got queue.', queue: station.queue});
  1056. });
  1057. },
  1058. /**
  1059. * Selects a private playlist for a station
  1060. *
  1061. * @param session
  1062. * @param stationId - the station id
  1063. * @param playlistId - the private playlist id
  1064. * @param cb
  1065. */
  1066. selectPrivatePlaylist: hooks.ownerRequired((session, stationId, playlistId, cb) => {
  1067. async.waterfall([
  1068. (next) => {
  1069. stations.getStation(stationId, next);
  1070. },
  1071. (station, next) => {
  1072. if (!station) return next('Station not found.');
  1073. if (station.type !== 'community') return next('Station is not a community station.');
  1074. if (station.privatePlaylist === playlistId) return next('That private playlist is already selected.');
  1075. db.models.playlist.findOne({_id: playlistId}, next);
  1076. },
  1077. (playlist, next) => {
  1078. if (!playlist) return next('Playlist not found.');
  1079. let currentSongIndex = (playlist.songs.length > 0) ? playlist.songs.length - 1 : 0;
  1080. db.models.station.updateOne({_id: stationId}, {$set: {privatePlaylist: playlistId, currentSongIndex: currentSongIndex}}, {runValidators: true}, next);
  1081. },
  1082. (res, next) => {
  1083. stations.updateStation(stationId, next);
  1084. }
  1085. ], async (err, station) => {
  1086. if (err) {
  1087. err = await utils.getError(err);
  1088. logger.error("STATIONS_SELECT_PRIVATE_PLAYLIST", `Selecting private playlist "${playlistId}" for station "${stationId}" failed. "${err}"`);
  1089. return cb({'status': 'failure', 'message': err});
  1090. }
  1091. logger.success("STATIONS_SELECT_PRIVATE_PLAYLIST", `Selected private playlist "${playlistId}" for station "${stationId}" successfully.`);
  1092. notifications.unschedule(`stations.nextSong?id${stationId}`);
  1093. if (!station.partyMode) stations.skipStation(stationId)();
  1094. cache.pub('privatePlaylist.selected', {playlistId, stationId});
  1095. return cb({'status': 'success', 'message': 'Successfully selected playlist.'});
  1096. });
  1097. }),
  1098. favoriteStation: hooks.loginRequired((session, stationId, cb) => {
  1099. async.waterfall([
  1100. (next) => {
  1101. stations.getStation(stationId, next);
  1102. },
  1103. (station, next) => {
  1104. if (!station) return next('Station not found.');
  1105. stations.canUserViewStation(station, session.userId, (err, canView) => {
  1106. if (err) return next(err);
  1107. if (canView) return next();
  1108. return next('Insufficient permissions.');
  1109. });
  1110. },
  1111. (next) => {
  1112. db.models.user.updateOne({ _id: session.userId }, { $addToSet: { favoriteStations: stationId } }, next);
  1113. },
  1114. (res, next) => {
  1115. if (res.nModified === 0) return next("The station was already favorited.");
  1116. next();
  1117. }
  1118. ], async (err) => {
  1119. if (err) {
  1120. err = await utils.getError(err);
  1121. logger.error("FAVORITE_STATION", `Favoriting station "${stationId}" failed. "${err}"`);
  1122. return cb({'status': 'failure', 'message': err});
  1123. }
  1124. logger.success("FAVORITE_STATION", `Favorited station "${stationId}" successfully.`);
  1125. cache.pub('user.favoritedStation', { userId: session.userId, stationId });
  1126. return cb({'status': 'success', 'message': 'Succesfully favorited station.'});
  1127. });
  1128. }),
  1129. unfavoriteStation: hooks.loginRequired((session, stationId, cb) => {
  1130. async.waterfall([
  1131. (next) => {
  1132. db.models.user.updateOne({ _id: session.userId }, { $pull: { favoriteStations: stationId } }, next);
  1133. },
  1134. (res, next) => {
  1135. if (res.nModified === 0) return next("The station wasn't favorited.");
  1136. next();
  1137. }
  1138. ], async (err) => {
  1139. if (err) {
  1140. err = await utils.getError(err);
  1141. logger.error("UNFAVORITE_STATION", `Unfavoriting station "${stationId}" failed. "${err}"`);
  1142. return cb({'status': 'failure', 'message': err});
  1143. }
  1144. logger.success("UNFAVORITE_STATION", `Unfavorited station "${stationId}" successfully.`);
  1145. cache.pub('user.unfavoritedStation', { userId: session.userId, stationId });
  1146. return cb({'status': 'success', 'message': 'Succesfully unfavorited station.'});
  1147. });
  1148. }),
  1149. };