playlists.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. import async from "async";
  2. import { isAdminRequired, isLoginRequired } from "./hooks";
  3. import moduleManager from "../../index";
  4. const DBModule = moduleManager.modules.db;
  5. const UtilsModule = moduleManager.modules.utils;
  6. const IOModule = moduleManager.modules.io;
  7. const SongsModule = moduleManager.modules.songs;
  8. const CacheModule = moduleManager.modules.cache;
  9. const PlaylistsModule = moduleManager.modules.playlists;
  10. const YouTubeModule = moduleManager.modules.youtube;
  11. const ActivitiesModule = moduleManager.modules.activities;
  12. CacheModule.runJob("SUB", {
  13. channel: "playlist.create",
  14. cb: playlist => {
  15. IOModule.runJob("SOCKETS_FROM_USER", { userId: playlist.createdBy }, this).then(response => {
  16. response.sockets.forEach(socket => {
  17. socket.emit("event:playlist.create", playlist);
  18. });
  19. });
  20. if (playlist.privacy === "public")
  21. IOModule.runJob("EMIT_TO_ROOM", {
  22. room: `profile-${playlist.createdBy}`,
  23. args: ["event:playlist.create", playlist]
  24. });
  25. }
  26. });
  27. CacheModule.runJob("SUB", {
  28. channel: "playlist.delete",
  29. cb: res => {
  30. IOModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }, this).then(response => {
  31. response.sockets.forEach(socket => {
  32. socket.emit("event:playlist.delete", res.playlistId);
  33. });
  34. });
  35. IOModule.runJob("EMIT_TO_ROOM", {
  36. room: `profile-${res.userId}`,
  37. args: ["event:playlist.delete", res.playlistId]
  38. });
  39. }
  40. });
  41. CacheModule.runJob("SUB", {
  42. channel: "playlist.repositionSongs",
  43. cb: res => {
  44. IOModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }, this).then(response =>
  45. response.sockets.forEach(socket =>
  46. socket.emit("event:playlist.repositionSongs", {
  47. playlistId: res.playlistId,
  48. songsBeingChanged: res.songsBeingChanged
  49. })
  50. )
  51. );
  52. }
  53. });
  54. CacheModule.runJob("SUB", {
  55. channel: "playlist.addSong",
  56. cb: res => {
  57. IOModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }, this).then(response => {
  58. response.sockets.forEach(socket => {
  59. socket.emit("event:playlist.addSong", {
  60. playlistId: res.playlistId,
  61. song: res.song
  62. });
  63. });
  64. });
  65. if (res.privacy === "public")
  66. IOModule.runJob("EMIT_TO_ROOM", {
  67. room: `profile-${res.userId}`,
  68. args: [
  69. "event:playlist.addSong",
  70. {
  71. playlistId: res.playlistId,
  72. song: res.song
  73. }
  74. ]
  75. });
  76. }
  77. });
  78. CacheModule.runJob("SUB", {
  79. channel: "playlist.removeSong",
  80. cb: res => {
  81. IOModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }, this).then(response => {
  82. response.sockets.forEach(socket => {
  83. socket.emit("event:playlist.removeSong", {
  84. playlistId: res.playlistId,
  85. songId: res.songId
  86. });
  87. });
  88. });
  89. if (res.privacy === "public")
  90. IOModule.runJob("EMIT_TO_ROOM", {
  91. room: `profile-${res.userId}`,
  92. args: [
  93. "event:playlist.removeSong",
  94. {
  95. playlistId: res.playlistId,
  96. songId: res.songId
  97. }
  98. ]
  99. });
  100. }
  101. });
  102. CacheModule.runJob("SUB", {
  103. channel: "playlist.updateDisplayName",
  104. cb: res => {
  105. IOModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }, this).then(response => {
  106. response.sockets.forEach(socket => {
  107. socket.emit("event:playlist.updateDisplayName", {
  108. playlistId: res.playlistId,
  109. displayName: res.displayName
  110. });
  111. });
  112. });
  113. if (res.privacy === "public")
  114. IOModule.runJob("EMIT_TO_ROOM", {
  115. room: `profile-${res.userId}`,
  116. args: [
  117. "event:playlist.updateDisplayName",
  118. {
  119. playlistId: res.playlistId,
  120. displayName: res.displayName
  121. }
  122. ]
  123. });
  124. }
  125. });
  126. CacheModule.runJob("SUB", {
  127. channel: "playlist.updatePrivacy",
  128. cb: res => {
  129. IOModule.runJob("SOCKETS_FROM_USER", { userId: res.userId }, this).then(response => {
  130. response.sockets.forEach(socket => {
  131. socket.emit("event:playlist.updatePrivacy");
  132. });
  133. });
  134. if (res.playlist.privacy === "public")
  135. return IOModule.runJob("EMIT_TO_ROOM", {
  136. room: `profile-${res.userId}`,
  137. args: ["event:playlist.create", res.playlist]
  138. });
  139. return IOModule.runJob("EMIT_TO_ROOM", {
  140. room: `profile-${res.userId}`,
  141. args: ["event:playlist.delete", res.playlist._id]
  142. });
  143. }
  144. });
  145. export default {
  146. /**
  147. * Gets all playlists
  148. *
  149. * @param {object} session - the session object automatically added by socket.io
  150. * @param {Function} cb - gets called with the result
  151. */
  152. index: isAdminRequired(async function index(session, cb) {
  153. const playlistModel = await DBModule.runJob(
  154. "GET_MODEL",
  155. {
  156. modelName: "playlist"
  157. },
  158. this
  159. );
  160. async.waterfall(
  161. [
  162. next => {
  163. playlistModel.find({}).sort({ createdAt: "desc" }).exec(next);
  164. }
  165. ],
  166. async (err, playlists) => {
  167. if (err) {
  168. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  169. this.log("ERROR", "PLAYLISTS_INDEX", `Indexing playlists failed. "${err}"`);
  170. return cb({ status: "failure", message: err });
  171. }
  172. this.log("SUCCESS", "PLAYLISTS_INDEX", "Indexing playlists successful.");
  173. return cb({ status: "success", data: playlists });
  174. }
  175. );
  176. }),
  177. /**
  178. * Gets the first song from a private playlist
  179. *
  180. * @param {object} session - the session object automatically added by socket.io
  181. * @param {string} playlistId - the id of the playlist we are getting the first song from
  182. * @param {Function} cb - gets called with the result
  183. */
  184. getFirstSong: isLoginRequired(function getFirstSong(session, playlistId, cb) {
  185. async.waterfall(
  186. [
  187. next => {
  188. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  189. .then(playlist => {
  190. next(null, playlist);
  191. })
  192. .catch(next);
  193. },
  194. (playlist, next) => {
  195. if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found.");
  196. return next(null, playlist.songs[0]);
  197. }
  198. ],
  199. async (err, song) => {
  200. if (err) {
  201. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  202. this.log(
  203. "ERROR",
  204. "PLAYLIST_GET_FIRST_SONG",
  205. `Getting the first song of playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  206. );
  207. return cb({ status: "failure", message: err });
  208. }
  209. this.log(
  210. "SUCCESS",
  211. "PLAYLIST_GET_FIRST_SONG",
  212. `Successfully got the first song of playlist "${playlistId}" for user "${session.userId}".`
  213. );
  214. return cb({
  215. status: "success",
  216. song
  217. });
  218. }
  219. );
  220. }),
  221. /**
  222. * Gets a list of all the playlists for a specific user
  223. *
  224. * @param {object} session - the session object automatically added by socket.io
  225. * @param {string} userId - the user id in question
  226. * @param {Function} cb - gets called with the result
  227. */
  228. indexForUser: async function indexForUser(session, userId, cb) {
  229. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  230. const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
  231. async.waterfall(
  232. [
  233. next => {
  234. userModel.findById(userId).select({ "preferences.orderOfPlaylists": -1 }).exec(next);
  235. },
  236. ({ preferences }, next) => {
  237. const { orderOfPlaylists } = preferences;
  238. const match = {
  239. createdBy: userId
  240. };
  241. // if a playlist order exists
  242. if (orderOfPlaylists > 0) match._id = { $in: orderOfPlaylists };
  243. playlistModel
  244. .aggregate()
  245. .match(match)
  246. .addFields({
  247. weight: { $indexOfArray: [orderOfPlaylists, "$_id"] }
  248. })
  249. .sort({ weight: 1 })
  250. .exec(next);
  251. },
  252. (playlists, next) => {
  253. if (session.userId === userId) return next(null, playlists); // user requesting playlists is the owner of the playlists
  254. const filteredPlaylists = [];
  255. return async.each(
  256. playlists,
  257. (playlist, nextPlaylist) => {
  258. if (playlist.privacy === "public") filteredPlaylists.push(playlist);
  259. return nextPlaylist();
  260. },
  261. () => next(null, filteredPlaylists)
  262. );
  263. }
  264. ],
  265. async (err, playlists) => {
  266. if (err) {
  267. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  268. this.log(
  269. "ERROR",
  270. "PLAYLIST_INDEX_FOR_USER",
  271. `Indexing playlists for user "${userId}" failed. "${err}"`
  272. );
  273. return cb({ status: "failure", message: err });
  274. }
  275. this.log("SUCCESS", "PLAYLIST_INDEX_FOR_USER", `Successfully indexed playlists for user "${userId}".`);
  276. return cb({
  277. status: "success",
  278. data: playlists
  279. });
  280. }
  281. );
  282. },
  283. /**
  284. * Gets all playlists for the user requesting it
  285. *
  286. * @param {object} session - the session object automatically added by socket.io
  287. * @param {boolean} showNonModifiablePlaylists - whether or not to show non modifiable playlists e.g. liked songs
  288. * @param {Function} cb - gets called with the result
  289. */
  290. indexMyPlaylists: isLoginRequired(async function indexMyPlaylists(session, showNonModifiablePlaylists, cb) {
  291. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  292. const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
  293. async.waterfall(
  294. [
  295. next => {
  296. userModel.findById(session.userId).select({ "preferences.orderOfPlaylists": -1 }).exec(next);
  297. },
  298. ({ preferences }, next) => {
  299. const { orderOfPlaylists } = preferences;
  300. const match = {
  301. createdBy: session.userId
  302. };
  303. // if non modifiable playlists should be shown as well
  304. if (!showNonModifiablePlaylists) match.type = "user";
  305. // if a playlist order exists
  306. if (orderOfPlaylists > 0) match._id = { $in: orderOfPlaylists };
  307. playlistModel
  308. .aggregate()
  309. .match(match)
  310. .addFields({
  311. weight: { $indexOfArray: [orderOfPlaylists, "$_id"] }
  312. })
  313. .sort({ weight: 1 })
  314. .exec(next);
  315. }
  316. ],
  317. async (err, playlists) => {
  318. if (err) {
  319. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  320. this.log(
  321. "ERROR",
  322. "PLAYLIST_INDEX_FOR_ME",
  323. `Indexing playlists for user "${session.userId}" failed. "${err}"`
  324. );
  325. return cb({ status: "failure", message: err });
  326. }
  327. this.log(
  328. "SUCCESS",
  329. "PLAYLIST_INDEX_FOR_ME",
  330. `Successfully indexed playlists for user "${session.userId}".`
  331. );
  332. return cb({
  333. status: "success",
  334. data: playlists
  335. });
  336. }
  337. );
  338. }),
  339. /**
  340. * Creates a new private playlist
  341. *
  342. * @param {object} session - the session object automatically added by socket.io
  343. * @param {object} data - the data for the new private playlist
  344. * @param {Function} cb - gets called with the result
  345. */
  346. create: isLoginRequired(async function create(session, data, cb) {
  347. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  348. const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
  349. const blacklist = ["liked songs", "likedsongs", "disliked songs", "dislikedsongs"];
  350. async.waterfall(
  351. [
  352. next => (data ? next() : cb({ status: "failure", message: "Invalid data" })),
  353. next => {
  354. const { displayName, songs } = data;
  355. if (blacklist.indexOf(displayName.toLowerCase()) !== -1)
  356. return next("That playlist name is blacklisted. Please use a different name.");
  357. return playlistModel.create(
  358. {
  359. displayName,
  360. songs,
  361. createdBy: session.userId,
  362. createdAt: Date.now(),
  363. createdFor: null,
  364. type: "user"
  365. },
  366. next
  367. );
  368. },
  369. (playlist, next) => {
  370. userModel.updateOne(
  371. { _id: session.userId },
  372. { $push: { "preferences.orderOfPlaylists": playlist._id } },
  373. err => {
  374. if (err) return next(err);
  375. return next(null, playlist);
  376. }
  377. );
  378. }
  379. ],
  380. async (err, playlist) => {
  381. if (err) {
  382. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  383. this.log(
  384. "ERROR",
  385. "PLAYLIST_CREATE",
  386. `Creating private playlist failed for user "${session.userId}". "${err}"`
  387. );
  388. return cb({ status: "failure", message: err });
  389. }
  390. CacheModule.runJob("PUB", {
  391. channel: "playlist.create",
  392. value: playlist
  393. });
  394. ActivitiesModule.runJob("ADD_ACTIVITY", {
  395. userId: session.userId,
  396. activityType: "created_playlist",
  397. payload: [playlist._id]
  398. });
  399. this.log(
  400. "SUCCESS",
  401. "PLAYLIST_CREATE",
  402. `Successfully created private playlist for user "${session.userId}".`
  403. );
  404. return cb({
  405. status: "success",
  406. message: "Successfully created playlist",
  407. data: {
  408. _id: playlist._id
  409. }
  410. });
  411. }
  412. );
  413. }),
  414. /**
  415. * Gets a playlist from id
  416. *
  417. * @param {object} session - the session object automatically added by socket.io
  418. * @param {string} playlistId - the id of the playlist we are getting
  419. * @param {Function} cb - gets called with the result
  420. */
  421. getPlaylist: isLoginRequired(function getPlaylist(session, playlistId, cb) {
  422. async.waterfall(
  423. [
  424. next => {
  425. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  426. .then(playlist => {
  427. next(null, playlist);
  428. })
  429. .catch(next);
  430. },
  431. (playlist, next) => {
  432. if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found");
  433. return next(null, playlist);
  434. }
  435. ],
  436. async (err, playlist) => {
  437. if (err) {
  438. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  439. this.log(
  440. "ERROR",
  441. "PLAYLIST_GET",
  442. `Getting private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  443. );
  444. return cb({ status: "failure", message: err });
  445. }
  446. this.log(
  447. "SUCCESS",
  448. "PLAYLIST_GET",
  449. `Successfully got private playlist "${playlistId}" for user "${session.userId}".`
  450. );
  451. return cb({
  452. status: "success",
  453. data: playlist
  454. });
  455. }
  456. );
  457. }),
  458. /**
  459. * Obtains basic metadata of a playlist in order to format an activity
  460. *
  461. * @param {object} session - the session object automatically added by socket.io
  462. * @param {string} playlistId - the playlist id
  463. * @param {Function} cb - callback
  464. */
  465. getPlaylistForActivity(session, playlistId, cb) {
  466. async.waterfall(
  467. [
  468. next => {
  469. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  470. .then(playlist => {
  471. next(null, playlist);
  472. })
  473. .catch(next);
  474. }
  475. ],
  476. async (err, playlist) => {
  477. if (err) {
  478. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  479. this.log(
  480. "ERROR",
  481. "PLAYLISTS_GET_PLAYLIST_FOR_ACTIVITY",
  482. `Failed to obtain metadata of playlist ${playlistId} for activity formatting. "${err}"`
  483. );
  484. return cb({ status: "failure", message: err });
  485. }
  486. this.log(
  487. "SUCCESS",
  488. "PLAYLISTS_GET_PLAYLIST_FOR_ACTIVITY",
  489. `Obtained metadata of playlist ${playlistId} for activity formatting successfully.`
  490. );
  491. return cb({
  492. status: "success",
  493. data: {
  494. title: playlist.displayName
  495. }
  496. });
  497. }
  498. );
  499. },
  500. // TODO Remove this
  501. /**
  502. * Updates a private playlist
  503. *
  504. * @param {object} session - the session object automatically added by socket.io
  505. * @param {string} playlistId - the id of the playlist we are updating
  506. * @param {object} playlist - the new private playlist object
  507. * @param {Function} cb - gets called with the result
  508. */
  509. update: isLoginRequired(async function update(session, playlistId, playlist, cb) {
  510. const playlistModel = await DBModule.runJob(
  511. "GET_MODEL",
  512. {
  513. modelName: "playlist"
  514. },
  515. this
  516. );
  517. async.waterfall(
  518. [
  519. next => {
  520. playlistModel.updateOne(
  521. { _id: playlistId, createdBy: session.userId },
  522. playlist,
  523. { runValidators: true },
  524. next
  525. );
  526. },
  527. (res, next) => {
  528. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  529. .then(playlist => {
  530. next(null, playlist);
  531. })
  532. .catch(next);
  533. }
  534. ],
  535. async (err, playlist) => {
  536. if (err) {
  537. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  538. this.log(
  539. "ERROR",
  540. "PLAYLIST_UPDATE",
  541. `Updating private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  542. );
  543. return cb({ status: "failure", message: err });
  544. }
  545. this.log(
  546. "SUCCESS",
  547. "PLAYLIST_UPDATE",
  548. `Successfully updated private playlist "${playlistId}" for user "${session.userId}".`
  549. );
  550. return cb({
  551. status: "success",
  552. data: playlist
  553. });
  554. }
  555. );
  556. }),
  557. /**
  558. * Shuffles songs in a private playlist
  559. *
  560. * @param {object} session - the session object automatically added by socket.io
  561. * @param {string} playlistId - the id of the playlist we are updating
  562. * @param {Function} cb - gets called with the result
  563. */
  564. shuffle: isLoginRequired(async function shuffle(session, playlistId, cb) {
  565. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  566. async.waterfall(
  567. [
  568. next => {
  569. if (!playlistId) return next("No playlist id.");
  570. return playlistModel.findById(playlistId, next);
  571. },
  572. (playlist, next) => {
  573. if (playlist.type !== "user") return next("Playlist cannot be shuffled.");
  574. return UtilsModule.runJob("SHUFFLE", { array: playlist.songs }, this)
  575. .then(result => next(null, result.array))
  576. .catch(next);
  577. },
  578. (songs, next) => {
  579. playlistModel.updateOne({ _id: playlistId }, { $set: { songs } }, { runValidators: true }, next);
  580. },
  581. (res, next) => {
  582. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  583. .then(playlist => next(null, playlist))
  584. .catch(next);
  585. }
  586. ],
  587. async (err, playlist) => {
  588. if (err) {
  589. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  590. this.log(
  591. "ERROR",
  592. "PLAYLIST_SHUFFLE",
  593. `Updating private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  594. );
  595. return cb({ status: "failure", message: err });
  596. }
  597. this.log(
  598. "SUCCESS",
  599. "PLAYLIST_SHUFFLE",
  600. `Successfully updated private playlist "${playlistId}" for user "${session.userId}".`
  601. );
  602. return cb({
  603. status: "success",
  604. message: "Successfully shuffled playlist.",
  605. data: playlist
  606. });
  607. }
  608. );
  609. }),
  610. /**
  611. * Changes the order of song(s) in a private playlist
  612. *
  613. * @param {object} session - the session object automatically added by socket.io
  614. * @param {string} playlistId - the id of the playlist we are targeting
  615. * @param {Array} songsBeingChanged - the songs to be repositioned, each element contains "songId" and "position" properties
  616. * @param {Function} cb - gets called with the result
  617. */
  618. repositionSongs: isLoginRequired(async function repositionSongs(session, playlistId, songsBeingChanged, cb) {
  619. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  620. async.waterfall(
  621. [
  622. // update playlist object with each song's new position
  623. next =>
  624. async.each(
  625. songsBeingChanged,
  626. (song, nextSong) =>
  627. playlistModel.updateOne(
  628. { _id: playlistId, "songs.songId": song.songId },
  629. {
  630. $set: {
  631. "songs.$.position": song.position
  632. }
  633. },
  634. err => {
  635. if (err) return next(err);
  636. return nextSong();
  637. }
  638. ),
  639. next
  640. ),
  641. // update the cache with the new songs positioning
  642. next => {
  643. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  644. .then(playlist => next(null, playlist))
  645. .catch(next);
  646. }
  647. ],
  648. async err => {
  649. if (err) {
  650. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  651. this.log(
  652. "ERROR",
  653. "PLAYLIST_REPOSITION_SONGS",
  654. `Repositioning songs for private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  655. );
  656. return cb({ status: "failure", message: err });
  657. }
  658. this.log(
  659. "SUCCESS",
  660. "PLAYLIST_REPOSITION_SONGS",
  661. `Successfully repositioned songs for private playlist "${playlistId}" for user "${session.userId}".`
  662. );
  663. CacheModule.runJob("PUB", {
  664. channel: "playlist.repositionSongs",
  665. value: {
  666. userId: session.userId,
  667. playlistId,
  668. songsBeingChanged
  669. }
  670. });
  671. return cb({
  672. status: "success",
  673. message: "Order of songs successfully updated"
  674. });
  675. }
  676. );
  677. }),
  678. /**
  679. * Moves a song to the bottom of the list in a private playlist
  680. *
  681. * @param {object} session - the session object automatically added by socket.io
  682. * @param {string} playlistId - the id of the playlist we are moving the song to the bottom from
  683. * @param {string} songId - the id of the song we are moving to the bottom of the list
  684. * @param {Function} cb - gets called with the result
  685. */
  686. moveSongToBottom: isLoginRequired(async function moveSongToBottom(session, playlistId, songId, cb) {
  687. async.waterfall(
  688. [
  689. next => {
  690. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  691. .then(playlist => next(null, playlist))
  692. .catch(next);
  693. },
  694. (playlist, next) => {
  695. if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found");
  696. if (playlist.type !== "user" && playlist.type !== "userSystem") return next("Playlist cannot be modified.");
  697. // sort array by position
  698. playlist.songs.sort((a, b) => a.position - b.position);
  699. // find index of songId
  700. playlist.songs.forEach((song, index) => {
  701. // reorder array (simulates what would be done with a drag and drop interface)
  702. if (song.songId === songId)
  703. playlist.songs.splice(playlist.songs.length, 0, playlist.songs.splice(index, 1)[0]);
  704. });
  705. const songsBeingChanged = [];
  706. playlist.songs.forEach((song, index) => {
  707. // check if position needs updated based on index
  708. if (song.position !== index + 1)
  709. songsBeingChanged.push({
  710. songId: song.songId,
  711. position: index + 1
  712. });
  713. });
  714. // update position property on songs that need to be changed
  715. return IOModule.runJob(
  716. "RUN_ACTION2",
  717. {
  718. session,
  719. namespace: "playlists",
  720. action: "repositionSongs",
  721. args: [playlistId, songsBeingChanged]
  722. },
  723. this
  724. )
  725. .then(res => {
  726. if (res.status === "success") return next();
  727. return next("Unable to reposition song in playlist.");
  728. })
  729. .catch(next);
  730. }
  731. ],
  732. async err => {
  733. if (err) {
  734. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  735. this.log(
  736. "ERROR",
  737. "PLAYLIST_MOVE_SONG_TO_BOTTOM",
  738. `Moving song "${songId}" to the bottom for private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  739. );
  740. return cb({ status: "failure", message: err });
  741. }
  742. this.log(
  743. "SUCCESS",
  744. "PLAYLIST_MOVE_SONG_TO_BOTTOM",
  745. `Successfully moved song "${songId}" to the bottom for private playlist "${playlistId}" for user "${session.userId}".`
  746. );
  747. return cb({
  748. status: "success",
  749. message: "Order of songs successfully updated"
  750. });
  751. }
  752. );
  753. }),
  754. /**
  755. * Adds a song to a private playlist
  756. *
  757. * @param {object} session - the session object automatically added by socket.io
  758. * @param {boolean} isSet - is the song part of a set of songs to be added
  759. * @param {string} songId - the id of the song we are trying to add
  760. * @param {string} playlistId - the id of the playlist we are adding the song to
  761. * @param {Function} cb - gets called with the result
  762. */
  763. addSongToPlaylist: isLoginRequired(async function addSongToPlaylist(session, isSet, songId, playlistId, cb) {
  764. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  765. async.waterfall(
  766. [
  767. next => {
  768. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  769. .then(playlist => {
  770. if (!playlist || playlist.createdBy !== session.userId)
  771. return next("Something went wrong when trying to get the playlist");
  772. return async.each(
  773. playlist.songs,
  774. (song, nextSong) => {
  775. if (song.songId === songId) return next("That song is already in the playlist");
  776. return nextSong();
  777. },
  778. err => next(err, playlist.songs.length + 1)
  779. );
  780. })
  781. .catch(next);
  782. },
  783. (position, next) => {
  784. SongsModule.runJob("GET_SONG", { id: songId }, this)
  785. .then(response => {
  786. const { song } = response;
  787. next(null, {
  788. _id: song._id,
  789. songId,
  790. title: song.title,
  791. duration: song.duration,
  792. position
  793. });
  794. })
  795. .catch(() => {
  796. YouTubeModule.runJob("GET_SONG", { songId }, this)
  797. .then(response => next(null, { ...response.song, position }))
  798. .catch(next);
  799. });
  800. },
  801. (newSong, next) => {
  802. playlistModel.updateOne(
  803. { _id: playlistId },
  804. { $push: { songs: newSong } },
  805. { runValidators: true },
  806. err => {
  807. if (err) return next(err);
  808. return PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  809. .then(playlist => next(null, playlist, newSong))
  810. .catch(next);
  811. }
  812. );
  813. }
  814. ],
  815. async (err, playlist, newSong) => {
  816. if (err) {
  817. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  818. this.log(
  819. "ERROR",
  820. "PLAYLIST_ADD_SONG",
  821. `Adding song "${songId}" to private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  822. );
  823. return cb({ status: "failure", message: err });
  824. }
  825. this.log(
  826. "SUCCESS",
  827. "PLAYLIST_ADD_SONG",
  828. `Successfully added song "${songId}" to private playlist "${playlistId}" for user "${session.userId}".`
  829. );
  830. if (!isSet)
  831. ActivitiesModule.runJob("ADD_ACTIVITY", {
  832. userId: session.userId,
  833. activityType: "added_song_to_playlist",
  834. payload: [{ songId, playlistId }]
  835. });
  836. CacheModule.runJob("PUB", {
  837. channel: "playlist.addSong",
  838. value: {
  839. playlistId: playlist._id,
  840. song: newSong,
  841. userId: session.userId,
  842. privacy: playlist.privacy
  843. }
  844. });
  845. return cb({
  846. status: "success",
  847. message: "Song has been successfully added to the playlist",
  848. data: playlist.songs
  849. });
  850. }
  851. );
  852. }),
  853. /**
  854. * Adds a set of songs to a private playlist
  855. *
  856. * @param {object} session - the session object automatically added by socket.io
  857. * @param {string} url - the url of the the YouTube playlist
  858. * @param {string} playlistId - the id of the playlist we are adding the set of songs to
  859. * @param {boolean} musicOnly - whether to only add music to the playlist
  860. * @param {Function} cb - gets called with the result
  861. */
  862. addSetToPlaylist: isLoginRequired(function addSetToPlaylist(session, url, playlistId, musicOnly, cb) {
  863. let videosInPlaylistTotal = 0;
  864. let songsInPlaylistTotal = 0;
  865. let addSongsStats = null;
  866. const addedSongs = [];
  867. async.waterfall(
  868. [
  869. next => {
  870. YouTubeModule.runJob(
  871. "GET_PLAYLIST",
  872. {
  873. url,
  874. musicOnly
  875. },
  876. this
  877. ).then(response => {
  878. if (response.filteredSongs) {
  879. videosInPlaylistTotal = response.songs.length;
  880. songsInPlaylistTotal = response.filteredSongs.length;
  881. } else {
  882. songsInPlaylistTotal = videosInPlaylistTotal = response.songs.length;
  883. }
  884. next(null, response.songs);
  885. });
  886. },
  887. (songIds, next) => {
  888. let successful = 0;
  889. let failed = 0;
  890. let alreadyInPlaylist = 0;
  891. if (songIds.length === 0) next();
  892. async.eachLimit(
  893. songIds,
  894. 1,
  895. (songId, next) => {
  896. IOModule.runJob(
  897. "RUN_ACTION2",
  898. {
  899. session,
  900. namespace: "playlists",
  901. action: "addSongToPlaylist",
  902. args: [true, songId, playlistId]
  903. },
  904. this
  905. )
  906. .then(res => {
  907. if (res.status === "success") {
  908. successful += 1;
  909. addedSongs.push(songId);
  910. } else failed += 1;
  911. if (res.message === "That song is already in the playlist") alreadyInPlaylist += 1;
  912. })
  913. .catch(() => {
  914. failed += 1;
  915. })
  916. .finally(() => {
  917. next();
  918. });
  919. },
  920. () => {
  921. addSongsStats = { successful, failed, alreadyInPlaylist };
  922. next(null);
  923. }
  924. );
  925. },
  926. next => {
  927. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  928. .then(playlist => {
  929. next(null, playlist);
  930. })
  931. .catch(next);
  932. },
  933. (playlist, next) => {
  934. if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found.");
  935. if (playlist.type !== "user") return next("Playlist cannot be modified.");
  936. return next(null, playlist);
  937. }
  938. ],
  939. async (err, playlist) => {
  940. if (err) {
  941. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  942. this.log(
  943. "ERROR",
  944. "PLAYLIST_IMPORT",
  945. `Importing a YouTube playlist to private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  946. );
  947. return cb({ status: "failure", message: err });
  948. }
  949. ActivitiesModule.runJob("ADD_ACTIVITY", {
  950. userId: session.userId,
  951. activityType: "added_songs_to_playlist",
  952. payload: addedSongs
  953. });
  954. this.log(
  955. "SUCCESS",
  956. "PLAYLIST_IMPORT",
  957. `Successfully imported a YouTube playlist to private playlist "${playlistId}" for user "${session.userId}". Videos in playlist: ${videosInPlaylistTotal}, songs in playlist: ${songsInPlaylistTotal}, songs successfully added: ${addSongsStats.successful}, songs failed: ${addSongsStats.failed}, already in playlist: ${addSongsStats.alreadyInPlaylist}.`
  958. );
  959. return cb({
  960. status: "success",
  961. message: `Playlist has been imported. ${addSongsStats.successful} were added successfully, ${addSongsStats.failed} failed (${addSongsStats.alreadyInPlaylist} were already in the playlist)`,
  962. data: playlist.songs,
  963. stats: {
  964. videosInPlaylistTotal,
  965. songsInPlaylistTotal
  966. }
  967. });
  968. }
  969. );
  970. }),
  971. /**
  972. * Removes a song from a private playlist
  973. *
  974. * @param {object} session - the session object automatically added by socket.io
  975. * @param {string} songId - the id of the song we are removing from the private playlist
  976. * @param {string} playlistId - the id of the playlist we are removing the song from
  977. * @param {Function} cb - gets called with the result
  978. */
  979. removeSongFromPlaylist: isLoginRequired(async function removeSongFromPlaylist(session, songId, playlistId, cb) {
  980. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  981. async.waterfall(
  982. [
  983. next => {
  984. if (!songId || typeof songId !== "string") return next("Invalid song id.");
  985. if (!playlistId) return next("Invalid playlist id.");
  986. return next();
  987. },
  988. next => {
  989. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  990. .then(playlist => next(null, playlist))
  991. .catch(next);
  992. },
  993. (playlist, next) => {
  994. if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found");
  995. // sort array by position
  996. playlist.songs.sort((a, b) => a.position - b.position);
  997. // find index of songId
  998. playlist.songs.forEach((song, ind) => {
  999. // remove song from array
  1000. if (song.songId === songId) playlist.songs.splice(ind, 1);
  1001. });
  1002. const songsBeingChanged = [];
  1003. playlist.songs.forEach((song, index) => {
  1004. // check if position needs updated based on index
  1005. if (song.position !== index + 1)
  1006. songsBeingChanged.push({
  1007. songId: song.songId,
  1008. position: index + 1
  1009. });
  1010. });
  1011. // update position property on songs that need to be changed
  1012. return IOModule.runJob(
  1013. "RUN_ACTION2",
  1014. {
  1015. session,
  1016. namespace: "playlists",
  1017. action: "repositionSongs",
  1018. args: [playlistId, songsBeingChanged]
  1019. },
  1020. this
  1021. )
  1022. .then(res => {
  1023. if (res.status === "success") return next();
  1024. return next("Unable to reposition song in playlist.");
  1025. })
  1026. .catch(next);
  1027. },
  1028. next => playlistModel.updateOne({ _id: playlistId }, { $pull: { songs: { songId } } }, next),
  1029. (res, next) => {
  1030. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  1031. .then(playlist => next(null, playlist))
  1032. .catch(next);
  1033. }
  1034. ],
  1035. async (err, playlist) => {
  1036. if (err) {
  1037. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  1038. this.log(
  1039. "ERROR",
  1040. "PLAYLIST_REMOVE_SONG",
  1041. `Removing song "${songId}" from private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  1042. );
  1043. return cb({ status: "failure", message: err });
  1044. }
  1045. this.log(
  1046. "SUCCESS",
  1047. "PLAYLIST_REMOVE_SONG",
  1048. `Successfully removed song "${songId}" from private playlist "${playlistId}" for user "${session.userId}".`
  1049. );
  1050. CacheModule.runJob("PUB", {
  1051. channel: "playlist.removeSong",
  1052. value: {
  1053. playlistId: playlist._id,
  1054. songId,
  1055. userId: session.userId,
  1056. privacy: playlist.privacy
  1057. }
  1058. });
  1059. return cb({
  1060. status: "success",
  1061. message: "Song has been successfully removed from playlist",
  1062. data: playlist.songs
  1063. });
  1064. }
  1065. );
  1066. }),
  1067. /**
  1068. * Updates the displayName of a private playlist
  1069. *
  1070. * @param {object} session - the session object automatically added by socket.io
  1071. * @param {string} playlistId - the id of the playlist we are updating the displayName for
  1072. * @param {Function} cb - gets called with the result
  1073. */
  1074. updateDisplayName: isLoginRequired(async function updateDisplayName(session, playlistId, displayName, cb) {
  1075. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  1076. async.waterfall(
  1077. [
  1078. next => {
  1079. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  1080. .then(playlist => next(null, playlist))
  1081. .catch(next);
  1082. },
  1083. (playlist, next) => {
  1084. if (playlist.type !== "user") return next("Playlist cannot be modified.");
  1085. return next(null);
  1086. },
  1087. next => {
  1088. playlistModel.updateOne(
  1089. { _id: playlistId, createdBy: session.userId },
  1090. { $set: { displayName } },
  1091. { runValidators: true },
  1092. next
  1093. );
  1094. },
  1095. (res, next) => {
  1096. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  1097. .then(playlist => {
  1098. next(null, playlist);
  1099. })
  1100. .catch(next);
  1101. }
  1102. ],
  1103. async (err, playlist) => {
  1104. if (err) {
  1105. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  1106. this.log(
  1107. "ERROR",
  1108. "PLAYLIST_UPDATE_DISPLAY_NAME",
  1109. `Updating display name to "${displayName}" for private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  1110. );
  1111. return cb({ status: "failure", message: err });
  1112. }
  1113. this.log(
  1114. "SUCCESS",
  1115. "PLAYLIST_UPDATE_DISPLAY_NAME",
  1116. `Successfully updated display name to "${displayName}" for private playlist "${playlistId}" for user "${session.userId}".`
  1117. );
  1118. CacheModule.runJob("PUB", {
  1119. channel: "playlist.updateDisplayName",
  1120. value: {
  1121. playlistId,
  1122. displayName,
  1123. userId: session.userId,
  1124. privacy: playlist.privacy
  1125. }
  1126. });
  1127. return cb({
  1128. status: "success",
  1129. message: "Playlist has been successfully updated"
  1130. });
  1131. }
  1132. );
  1133. }),
  1134. /**
  1135. * Removes a private playlist
  1136. *
  1137. * @param {object} session - the session object automatically added by socket.io
  1138. * @param {string} playlistId - the id of the playlist we are moving the song to the top from
  1139. * @param {Function} cb - gets called with the result
  1140. */
  1141. remove: isLoginRequired(async function remove(session, playlistId, cb) {
  1142. const stationModel = await DBModule.runJob("GET_MODEL", { modelName: "station" }, this);
  1143. const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
  1144. async.waterfall(
  1145. [
  1146. next => {
  1147. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  1148. .then(playlist => next(null, playlist))
  1149. .catch(next);
  1150. },
  1151. (playlist, next) => {
  1152. if (playlist.type !== "user" && playlist.type !== "userSystem") return next("Playlist cannot be removed.");
  1153. return next(null, playlist);
  1154. },
  1155. (playlist, next) => {
  1156. userModel.updateOne(
  1157. { _id: playlist.createdBy },
  1158. { $pull: { "preferences.orderOfPlaylists": playlist._id } },
  1159. err => {
  1160. if (err) return next(err);
  1161. return next(null);
  1162. }
  1163. );
  1164. },
  1165. next => {
  1166. PlaylistsModule.runJob("DELETE_PLAYLIST", { playlistId }, this).then(next).catch(next);
  1167. },
  1168. next => {
  1169. stationModel.find({ privatePlaylist: playlistId }, (err, res) => {
  1170. next(err, res);
  1171. });
  1172. },
  1173. (stations, next) => {
  1174. async.each(
  1175. stations,
  1176. (station, next) => {
  1177. async.waterfall(
  1178. [
  1179. next => {
  1180. stationModel.updateOne(
  1181. { _id: station._id },
  1182. { $set: { privatePlaylist: null } },
  1183. { runValidators: true },
  1184. next
  1185. );
  1186. },
  1187. (res, next) => {
  1188. if (!station.partyMode) {
  1189. moduleManager.modules.stations
  1190. .runJob(
  1191. "UPDATE_STATION",
  1192. {
  1193. stationId: station._id
  1194. },
  1195. this
  1196. )
  1197. .then(station => next(null, station))
  1198. .catch(next);
  1199. CacheModule.runJob("PUB", {
  1200. channel: "privatePlaylist.selected",
  1201. value: {
  1202. playlistId: null,
  1203. stationId: station._id
  1204. }
  1205. });
  1206. } else next();
  1207. }
  1208. ],
  1209. () => {
  1210. next();
  1211. }
  1212. );
  1213. },
  1214. () => {
  1215. next();
  1216. }
  1217. );
  1218. }
  1219. ],
  1220. async err => {
  1221. if (err) {
  1222. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  1223. this.log(
  1224. "ERROR",
  1225. "PLAYLIST_REMOVE",
  1226. `Removing private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  1227. );
  1228. return cb({ status: "failure", message: err });
  1229. }
  1230. this.log(
  1231. "SUCCESS",
  1232. "PLAYLIST_REMOVE",
  1233. `Successfully removed private playlist "${playlistId}" for user "${session.userId}".`
  1234. );
  1235. CacheModule.runJob("PUB", {
  1236. channel: "playlist.delete",
  1237. value: {
  1238. userId: session.userId,
  1239. playlistId
  1240. }
  1241. });
  1242. ActivitiesModule.runJob("ADD_ACTIVITY", {
  1243. userId: session.userId,
  1244. activityType: "deleted_playlist",
  1245. payload: [playlistId]
  1246. });
  1247. return cb({
  1248. status: "success",
  1249. message: "Playlist successfully removed"
  1250. });
  1251. }
  1252. );
  1253. }),
  1254. /**
  1255. * Updates the privacy of a private playlist
  1256. *
  1257. * @param {object} session - the session object automatically added by socket.io
  1258. * @param {string} playlistId - the id of the playlist we are updating the privacy for
  1259. * @param {string} privacy - what the new privacy of the playlist should be e.g. public
  1260. * @param {Function} cb - gets called with the result
  1261. */
  1262. updatePrivacy: isLoginRequired(async function updatePrivacy(session, playlistId, privacy, cb) {
  1263. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  1264. async.waterfall(
  1265. [
  1266. next => {
  1267. playlistModel.updateOne(
  1268. { _id: playlistId, createdBy: session.userId },
  1269. { $set: { privacy } },
  1270. { runValidators: true },
  1271. next
  1272. );
  1273. },
  1274. (res, next) => {
  1275. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  1276. .then(playlist => {
  1277. next(null, playlist);
  1278. })
  1279. .catch(next);
  1280. }
  1281. ],
  1282. async (err, playlist) => {
  1283. if (err) {
  1284. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  1285. this.log(
  1286. "ERROR",
  1287. "PLAYLIST_UPDATE_PRIVACY",
  1288. `Updating privacy to "${privacy}" for private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  1289. );
  1290. return cb({ status: "failure", message: err });
  1291. }
  1292. this.log(
  1293. "SUCCESS",
  1294. "PLAYLIST_UPDATE_PRIVACY",
  1295. `Successfully updated privacy to "${privacy}" for private playlist "${playlistId}" for user "${session.userId}".`
  1296. );
  1297. CacheModule.runJob("PUB", {
  1298. channel: "playlist.updatePrivacy",
  1299. value: {
  1300. userId: session.userId,
  1301. playlist
  1302. }
  1303. });
  1304. return cb({
  1305. status: "success",
  1306. message: "Playlist has been successfully updated"
  1307. });
  1308. }
  1309. );
  1310. })
  1311. };