playlists.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  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.isUserModifiable = true;
  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. },
  364. next
  365. );
  366. },
  367. (playlist, next) => {
  368. userModel.updateOne(
  369. { _id: session.userId },
  370. { $push: { "preferences.orderOfPlaylists": playlist._id } },
  371. err => {
  372. if (err) return next(err);
  373. return next(null, playlist);
  374. }
  375. );
  376. }
  377. ],
  378. async (err, playlist) => {
  379. if (err) {
  380. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  381. this.log(
  382. "ERROR",
  383. "PLAYLIST_CREATE",
  384. `Creating private playlist failed for user "${session.userId}". "${err}"`
  385. );
  386. return cb({ status: "failure", message: err });
  387. }
  388. CacheModule.runJob("PUB", {
  389. channel: "playlist.create",
  390. value: playlist
  391. });
  392. ActivitiesModule.runJob("ADD_ACTIVITY", {
  393. userId: session.userId,
  394. activityType: "created_playlist",
  395. payload: [playlist._id]
  396. });
  397. this.log(
  398. "SUCCESS",
  399. "PLAYLIST_CREATE",
  400. `Successfully created private playlist for user "${session.userId}".`
  401. );
  402. return cb({
  403. status: "success",
  404. message: "Successfully created playlist",
  405. data: {
  406. _id: playlist._id
  407. }
  408. });
  409. }
  410. );
  411. }),
  412. /**
  413. * Gets a playlist from id
  414. *
  415. * @param {object} session - the session object automatically added by socket.io
  416. * @param {string} playlistId - the id of the playlist we are getting
  417. * @param {Function} cb - gets called with the result
  418. */
  419. getPlaylist: isLoginRequired(function getPlaylist(session, playlistId, cb) {
  420. async.waterfall(
  421. [
  422. next => {
  423. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  424. .then(playlist => {
  425. next(null, playlist);
  426. })
  427. .catch(next);
  428. },
  429. (playlist, next) => {
  430. if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found");
  431. return next(null, playlist);
  432. }
  433. ],
  434. async (err, playlist) => {
  435. if (err) {
  436. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  437. this.log(
  438. "ERROR",
  439. "PLAYLIST_GET",
  440. `Getting private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  441. );
  442. return cb({ status: "failure", message: err });
  443. }
  444. const sortedSongs = playlist.songs.sort((a, b) => a.position - b.position);
  445. playlist.songs = sortedSongs;
  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(
  566. "GET_MODEL",
  567. {
  568. modelName: "playlist"
  569. },
  570. this
  571. );
  572. async.waterfall(
  573. [
  574. next => {
  575. if (!playlistId) return next("No playlist id.");
  576. return playlistModel.findById(playlistId, next);
  577. },
  578. (playlist, next) => {
  579. if (!playlist.isUserModifiable) return next("Playlist cannot be shuffled.");
  580. return UtilsModule.runJob("SHUFFLE", { array: playlist.songs }, this)
  581. .then(result => next(null, result.array))
  582. .catch(next);
  583. },
  584. (songs, next) => {
  585. playlistModel.updateOne({ _id: playlistId }, { $set: { songs } }, { runValidators: true }, next);
  586. },
  587. (res, next) => {
  588. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  589. .then(playlist => {
  590. next(null, playlist);
  591. })
  592. .catch(next);
  593. }
  594. ],
  595. async (err, playlist) => {
  596. if (err) {
  597. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  598. this.log(
  599. "ERROR",
  600. "PLAYLIST_SHUFFLE",
  601. `Updating private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  602. );
  603. return cb({ status: "failure", message: err });
  604. }
  605. this.log(
  606. "SUCCESS",
  607. "PLAYLIST_SHUFFLE",
  608. `Successfully updated private playlist "${playlistId}" for user "${session.userId}".`
  609. );
  610. return cb({
  611. status: "success",
  612. message: "Successfully shuffled playlist.",
  613. data: playlist
  614. });
  615. }
  616. );
  617. }),
  618. /**
  619. * Changes the order of song(s) in a private playlist
  620. *
  621. * @param {object} session - the session object automatically added by socket.io
  622. * @param {string} playlistId - the id of the playlist we are targeting
  623. * @param {Array} songsBeingChanged - the songs to be repositioned, each element contains "songId" and "position" properties
  624. * @param {Function} cb - gets called with the result
  625. */
  626. repositionSongs: isLoginRequired(async function repositionSongs(session, playlistId, songsBeingChanged, cb) {
  627. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  628. async.waterfall(
  629. [
  630. // update playlist object with each song's new position
  631. next =>
  632. async.each(
  633. songsBeingChanged,
  634. (song, nextSong) =>
  635. playlistModel.updateOne(
  636. { _id: playlistId, "songs.songId": song.songId },
  637. {
  638. $set: {
  639. "songs.$.position": song.position
  640. }
  641. },
  642. err => {
  643. if (err) return next(err);
  644. return nextSong();
  645. }
  646. ),
  647. next
  648. ),
  649. // update the cache with the new songs positioning
  650. next => {
  651. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  652. .then(playlist => next(null, playlist))
  653. .catch(next);
  654. }
  655. ],
  656. async err => {
  657. if (err) {
  658. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  659. this.log(
  660. "ERROR",
  661. "PLAYLIST_REPOSITION_SONGS",
  662. `Repositioning songs for private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  663. );
  664. return cb({ status: "failure", message: err });
  665. }
  666. this.log(
  667. "SUCCESS",
  668. "PLAYLIST_REPOSITION_SONGS",
  669. `Successfully repositioned songs for private playlist "${playlistId}" for user "${session.userId}".`
  670. );
  671. CacheModule.runJob("PUB", {
  672. channel: "playlist.repositionSongs",
  673. value: {
  674. userId: session.userId,
  675. playlistId,
  676. songsBeingChanged
  677. }
  678. });
  679. return cb({
  680. status: "success",
  681. message: "Order of songs successfully updated"
  682. });
  683. }
  684. );
  685. }),
  686. /**
  687. * Moves a song to the bottom of the list in a private playlist
  688. *
  689. * @param {object} session - the session object automatically added by socket.io
  690. * @param {string} playlistId - the id of the playlist we are moving the song to the bottom from
  691. * @param {string} songId - the id of the song we are moving to the bottom of the list
  692. * @param {Function} cb - gets called with the result
  693. */
  694. moveSongToBottom: isLoginRequired(async function moveSongToBottom(session, playlistId, songId, cb) {
  695. async.waterfall(
  696. [
  697. next => {
  698. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  699. .then(playlist => next(null, playlist))
  700. .catch(next);
  701. },
  702. (playlist, next) => {
  703. if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found");
  704. if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
  705. // sort array by position
  706. playlist.songs.sort((a, b) => a.position - b.position);
  707. // find index of songId
  708. playlist.songs.forEach((song, index) => {
  709. // reorder array (simulates what would be done with a drag and drop interface)
  710. if (song.songId === songId)
  711. playlist.songs.splice(playlist.songs.length, 0, playlist.songs.splice(index, 1)[0]);
  712. });
  713. const songsBeingChanged = [];
  714. playlist.songs.forEach((song, index) => {
  715. // check if position needs updated based on index
  716. if (song.position !== index + 1)
  717. songsBeingChanged.push({
  718. songId: song.songId,
  719. position: index + 1
  720. });
  721. });
  722. // update position property on songs that need to be changed
  723. return IOModule.runJob(
  724. "RUN_ACTION2",
  725. {
  726. session,
  727. namespace: "playlists",
  728. action: "repositionSongs",
  729. args: [playlistId, songsBeingChanged]
  730. },
  731. this
  732. )
  733. .then(res => {
  734. if (res.status === "success") return next();
  735. return next("Unable to reposition song in playlist.");
  736. })
  737. .catch(next);
  738. }
  739. ],
  740. async err => {
  741. if (err) {
  742. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  743. this.log(
  744. "ERROR",
  745. "PLAYLIST_MOVE_SONG_TO_BOTTOM",
  746. `Moving song "${songId}" to the bottom for private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  747. );
  748. return cb({ status: "failure", message: err });
  749. }
  750. this.log(
  751. "SUCCESS",
  752. "PLAYLIST_MOVE_SONG_TO_BOTTOM",
  753. `Successfully moved song "${songId}" to the bottom for private playlist "${playlistId}" for user "${session.userId}".`
  754. );
  755. return cb({
  756. status: "success",
  757. message: "Order of songs successfully updated"
  758. });
  759. }
  760. );
  761. }),
  762. /**
  763. * Adds a song to a private playlist
  764. *
  765. * @param {object} session - the session object automatically added by socket.io
  766. * @param {boolean} isSet - is the song part of a set of songs to be added
  767. * @param {string} songId - the id of the song we are trying to add
  768. * @param {string} playlistId - the id of the playlist we are adding the song to
  769. * @param {Function} cb - gets called with the result
  770. */
  771. addSongToPlaylist: isLoginRequired(async function addSongToPlaylist(session, isSet, songId, playlistId, cb) {
  772. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  773. async.waterfall(
  774. [
  775. next => {
  776. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  777. .then(playlist => {
  778. if (!playlist || playlist.createdBy !== session.userId)
  779. return next("Something went wrong when trying to get the playlist");
  780. return async.each(
  781. playlist.songs,
  782. (song, nextSong) => {
  783. if (song.songId === songId) return next("That song is already in the playlist");
  784. return nextSong();
  785. },
  786. err => next(err, playlist.songs.length + 1)
  787. );
  788. })
  789. .catch(next);
  790. },
  791. (position, next) => {
  792. SongsModule.runJob("GET_SONG", { id: songId }, this)
  793. .then(response => {
  794. const { song } = response;
  795. next(null, {
  796. _id: song._id,
  797. songId,
  798. title: song.title,
  799. duration: song.duration,
  800. position
  801. });
  802. })
  803. .catch(() => {
  804. YouTubeModule.runJob("GET_SONG", { songId }, this)
  805. .then(response => next(null, { ...response.song, position }))
  806. .catch(next);
  807. });
  808. },
  809. (newSong, next) => {
  810. playlistModel.updateOne(
  811. { _id: playlistId },
  812. { $push: { songs: newSong } },
  813. { runValidators: true },
  814. err => {
  815. if (err) return next(err);
  816. return PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  817. .then(playlist => next(null, playlist, newSong))
  818. .catch(next);
  819. }
  820. );
  821. }
  822. ],
  823. async (err, playlist, newSong) => {
  824. if (err) {
  825. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  826. this.log(
  827. "ERROR",
  828. "PLAYLIST_ADD_SONG",
  829. `Adding song "${songId}" to private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  830. );
  831. return cb({ status: "failure", message: err });
  832. }
  833. this.log(
  834. "SUCCESS",
  835. "PLAYLIST_ADD_SONG",
  836. `Successfully added song "${songId}" to private playlist "${playlistId}" for user "${session.userId}".`
  837. );
  838. if (!isSet)
  839. ActivitiesModule.runJob("ADD_ACTIVITY", {
  840. userId: session.userId,
  841. activityType: "added_song_to_playlist",
  842. payload: [{ songId, playlistId }]
  843. });
  844. CacheModule.runJob("PUB", {
  845. channel: "playlist.addSong",
  846. value: {
  847. playlistId: playlist._id,
  848. song: newSong,
  849. userId: session.userId,
  850. privacy: playlist.privacy
  851. }
  852. });
  853. return cb({
  854. status: "success",
  855. message: "Song has been successfully added to the playlist",
  856. data: playlist.songs
  857. });
  858. }
  859. );
  860. }),
  861. /**
  862. * Adds a set of songs to a private playlist
  863. *
  864. * @param {object} session - the session object automatically added by socket.io
  865. * @param {string} url - the url of the the YouTube playlist
  866. * @param {string} playlistId - the id of the playlist we are adding the set of songs to
  867. * @param {boolean} musicOnly - whether to only add music to the playlist
  868. * @param {Function} cb - gets called with the result
  869. */
  870. addSetToPlaylist: isLoginRequired(function addSetToPlaylist(session, url, playlistId, musicOnly, cb) {
  871. let videosInPlaylistTotal = 0;
  872. let songsInPlaylistTotal = 0;
  873. let addSongsStats = null;
  874. const addedSongs = [];
  875. async.waterfall(
  876. [
  877. next => {
  878. YouTubeModule.runJob(
  879. "GET_PLAYLIST",
  880. {
  881. url,
  882. musicOnly
  883. },
  884. this
  885. ).then(response => {
  886. if (response.filteredSongs) {
  887. videosInPlaylistTotal = response.songs.length;
  888. songsInPlaylistTotal = response.filteredSongs.length;
  889. } else {
  890. songsInPlaylistTotal = videosInPlaylistTotal = response.songs.length;
  891. }
  892. next(null, response.songs);
  893. });
  894. },
  895. (songIds, next) => {
  896. let successful = 0;
  897. let failed = 0;
  898. let alreadyInPlaylist = 0;
  899. if (songIds.length === 0) next();
  900. async.eachLimit(
  901. songIds,
  902. 1,
  903. (songId, next) => {
  904. IOModule.runJob(
  905. "RUN_ACTION2",
  906. {
  907. session,
  908. namespace: "playlists",
  909. action: "addSongToPlaylist",
  910. args: [true, songId, playlistId]
  911. },
  912. this
  913. )
  914. .then(res => {
  915. if (res.status === "success") {
  916. successful += 1;
  917. addedSongs.push(songId);
  918. } else failed += 1;
  919. if (res.message === "That song is already in the playlist") alreadyInPlaylist += 1;
  920. })
  921. .catch(() => {
  922. failed += 1;
  923. })
  924. .finally(() => {
  925. next();
  926. });
  927. },
  928. () => {
  929. addSongsStats = { successful, failed, alreadyInPlaylist };
  930. next(null);
  931. }
  932. );
  933. },
  934. next => {
  935. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  936. .then(playlist => {
  937. next(null, playlist);
  938. })
  939. .catch(next);
  940. },
  941. (playlist, next) => {
  942. if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found.");
  943. if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
  944. return next(null, playlist);
  945. }
  946. ],
  947. async (err, playlist) => {
  948. if (err) {
  949. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  950. this.log(
  951. "ERROR",
  952. "PLAYLIST_IMPORT",
  953. `Importing a YouTube playlist to private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  954. );
  955. return cb({ status: "failure", message: err });
  956. }
  957. ActivitiesModule.runJob("ADD_ACTIVITY", {
  958. userId: session.userId,
  959. activityType: "added_songs_to_playlist",
  960. payload: addedSongs
  961. });
  962. this.log(
  963. "SUCCESS",
  964. "PLAYLIST_IMPORT",
  965. `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}.`
  966. );
  967. return cb({
  968. status: "success",
  969. message: `Playlist has been imported. ${addSongsStats.successful} were added successfully, ${addSongsStats.failed} failed (${addSongsStats.alreadyInPlaylist} were already in the playlist)`,
  970. data: playlist.songs,
  971. stats: {
  972. videosInPlaylistTotal,
  973. songsInPlaylistTotal
  974. }
  975. });
  976. }
  977. );
  978. }),
  979. /**
  980. * Removes a song from a private playlist
  981. *
  982. * @param {object} session - the session object automatically added by socket.io
  983. * @param {string} songId - the id of the song we are removing from the private playlist
  984. * @param {string} playlistId - the id of the playlist we are removing the song from
  985. * @param {Function} cb - gets called with the result
  986. */
  987. removeSongFromPlaylist: isLoginRequired(async function removeSongFromPlaylist(session, songId, playlistId, cb) {
  988. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  989. async.waterfall(
  990. [
  991. next => {
  992. if (!songId || typeof songId !== "string") return next("Invalid song id.");
  993. if (!playlistId) return next("Invalid playlist id.");
  994. return next();
  995. },
  996. next => {
  997. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  998. .then(playlist => next(null, playlist))
  999. .catch(next);
  1000. },
  1001. (playlist, next) => {
  1002. if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found");
  1003. // sort array by position
  1004. playlist.songs.sort((a, b) => a.position - b.position);
  1005. // find index of songId
  1006. playlist.songs.forEach((song, ind) => {
  1007. // remove song from array
  1008. if (song.songId === songId) playlist.songs.splice(ind, 1);
  1009. });
  1010. const songsBeingChanged = [];
  1011. playlist.songs.forEach((song, index) => {
  1012. // check if position needs updated based on index
  1013. if (song.position !== index + 1)
  1014. songsBeingChanged.push({
  1015. songId: song.songId,
  1016. position: index + 1
  1017. });
  1018. });
  1019. // update position property on songs that need to be changed
  1020. return IOModule.runJob(
  1021. "RUN_ACTION2",
  1022. {
  1023. session,
  1024. namespace: "playlists",
  1025. action: "repositionSongs",
  1026. args: [playlistId, songsBeingChanged]
  1027. },
  1028. this
  1029. )
  1030. .then(res => {
  1031. if (res.status === "success") return next();
  1032. return next("Unable to reposition song in playlist.");
  1033. })
  1034. .catch(next);
  1035. },
  1036. next => playlistModel.updateOne({ _id: playlistId }, { $pull: { songs: { songId } } }, next),
  1037. (res, next) => {
  1038. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  1039. .then(playlist => next(null, playlist))
  1040. .catch(next);
  1041. }
  1042. ],
  1043. async (err, playlist) => {
  1044. if (err) {
  1045. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  1046. this.log(
  1047. "ERROR",
  1048. "PLAYLIST_REMOVE_SONG",
  1049. `Removing song "${songId}" from private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  1050. );
  1051. return cb({ status: "failure", message: err });
  1052. }
  1053. this.log(
  1054. "SUCCESS",
  1055. "PLAYLIST_REMOVE_SONG",
  1056. `Successfully removed song "${songId}" from private playlist "${playlistId}" for user "${session.userId}".`
  1057. );
  1058. CacheModule.runJob("PUB", {
  1059. channel: "playlist.removeSong",
  1060. value: {
  1061. playlistId: playlist._id,
  1062. songId,
  1063. userId: session.userId,
  1064. privacy: playlist.privacy
  1065. }
  1066. });
  1067. return cb({
  1068. status: "success",
  1069. message: "Song has been successfully removed from playlist",
  1070. data: playlist.songs
  1071. });
  1072. }
  1073. );
  1074. }),
  1075. /**
  1076. * Updates the displayName of a private playlist
  1077. *
  1078. * @param {object} session - the session object automatically added by socket.io
  1079. * @param {string} playlistId - the id of the playlist we are updating the displayName for
  1080. * @param {Function} cb - gets called with the result
  1081. */
  1082. updateDisplayName: isLoginRequired(async function updateDisplayName(session, playlistId, displayName, cb) {
  1083. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  1084. async.waterfall(
  1085. [
  1086. next => {
  1087. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  1088. .then(playlist => next(null, playlist))
  1089. .catch(next);
  1090. },
  1091. (playlist, next) => {
  1092. if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
  1093. return next(null);
  1094. },
  1095. next => {
  1096. playlistModel.updateOne(
  1097. { _id: playlistId, createdBy: session.userId },
  1098. { $set: { displayName } },
  1099. { runValidators: true },
  1100. next
  1101. );
  1102. },
  1103. (res, next) => {
  1104. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  1105. .then(playlist => {
  1106. next(null, playlist);
  1107. })
  1108. .catch(next);
  1109. }
  1110. ],
  1111. async (err, playlist) => {
  1112. if (err) {
  1113. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  1114. this.log(
  1115. "ERROR",
  1116. "PLAYLIST_UPDATE_DISPLAY_NAME",
  1117. `Updating display name to "${displayName}" for private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  1118. );
  1119. return cb({ status: "failure", message: err });
  1120. }
  1121. this.log(
  1122. "SUCCESS",
  1123. "PLAYLIST_UPDATE_DISPLAY_NAME",
  1124. `Successfully updated display name to "${displayName}" for private playlist "${playlistId}" for user "${session.userId}".`
  1125. );
  1126. CacheModule.runJob("PUB", {
  1127. channel: "playlist.updateDisplayName",
  1128. value: {
  1129. playlistId,
  1130. displayName,
  1131. userId: session.userId,
  1132. privacy: playlist.privacy
  1133. }
  1134. });
  1135. return cb({
  1136. status: "success",
  1137. message: "Playlist has been successfully updated"
  1138. });
  1139. }
  1140. );
  1141. }),
  1142. /**
  1143. * Removes a private playlist
  1144. *
  1145. * @param {object} session - the session object automatically added by socket.io
  1146. * @param {string} playlistId - the id of the playlist we are moving the song to the top from
  1147. * @param {Function} cb - gets called with the result
  1148. */
  1149. remove: isLoginRequired(async function remove(session, playlistId, cb) {
  1150. const stationModel = await DBModule.runJob("GET_MODEL", { modelName: "station" }, this);
  1151. const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
  1152. async.waterfall(
  1153. [
  1154. next => {
  1155. PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
  1156. .then(playlist => next(null, playlist))
  1157. .catch(next);
  1158. },
  1159. (playlist, next) => {
  1160. if (!playlist.isUserModifiable) return next("Playlist cannot be removed.");
  1161. return next(null, playlist);
  1162. },
  1163. (playlist, next) => {
  1164. userModel.updateOne(
  1165. { _id: playlist.createdBy },
  1166. { $pull: { "preferences.orderOfPlaylists": playlist._id } },
  1167. err => {
  1168. if (err) return next(err);
  1169. return next(null);
  1170. }
  1171. );
  1172. },
  1173. next => {
  1174. PlaylistsModule.runJob("DELETE_PLAYLIST", { playlistId }, this).then(next).catch(next);
  1175. },
  1176. next => {
  1177. stationModel.find({ privatePlaylist: playlistId }, (err, res) => {
  1178. next(err, res);
  1179. });
  1180. },
  1181. (stations, next) => {
  1182. async.each(
  1183. stations,
  1184. (station, next) => {
  1185. async.waterfall(
  1186. [
  1187. next => {
  1188. stationModel.updateOne(
  1189. { _id: station._id },
  1190. { $set: { privatePlaylist: null } },
  1191. { runValidators: true },
  1192. next
  1193. );
  1194. },
  1195. (res, next) => {
  1196. if (!station.partyMode) {
  1197. moduleManager.modules.stations
  1198. .runJob(
  1199. "UPDATE_STATION",
  1200. {
  1201. stationId: station._id
  1202. },
  1203. this
  1204. )
  1205. .then(station => next(null, station))
  1206. .catch(next);
  1207. CacheModule.runJob("PUB", {
  1208. channel: "privatePlaylist.selected",
  1209. value: {
  1210. playlistId: null,
  1211. stationId: station._id
  1212. }
  1213. });
  1214. } else next();
  1215. }
  1216. ],
  1217. () => {
  1218. next();
  1219. }
  1220. );
  1221. },
  1222. () => {
  1223. next();
  1224. }
  1225. );
  1226. }
  1227. ],
  1228. async err => {
  1229. if (err) {
  1230. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  1231. this.log(
  1232. "ERROR",
  1233. "PLAYLIST_REMOVE",
  1234. `Removing private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  1235. );
  1236. return cb({ status: "failure", message: err });
  1237. }
  1238. this.log(
  1239. "SUCCESS",
  1240. "PLAYLIST_REMOVE",
  1241. `Successfully removed private playlist "${playlistId}" for user "${session.userId}".`
  1242. );
  1243. CacheModule.runJob("PUB", {
  1244. channel: "playlist.delete",
  1245. value: {
  1246. userId: session.userId,
  1247. playlistId
  1248. }
  1249. });
  1250. ActivitiesModule.runJob("ADD_ACTIVITY", {
  1251. userId: session.userId,
  1252. activityType: "deleted_playlist",
  1253. payload: [playlistId]
  1254. });
  1255. return cb({
  1256. status: "success",
  1257. message: "Playlist successfully removed"
  1258. });
  1259. }
  1260. );
  1261. }),
  1262. /**
  1263. * Updates the privacy of a private playlist
  1264. *
  1265. * @param {object} session - the session object automatically added by socket.io
  1266. * @param {string} playlistId - the id of the playlist we are updating the privacy for
  1267. * @param {string} privacy - what the new privacy of the playlist should be e.g. public
  1268. * @param {Function} cb - gets called with the result
  1269. */
  1270. updatePrivacy: isLoginRequired(async function updatePrivacy(session, playlistId, privacy, cb) {
  1271. const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
  1272. async.waterfall(
  1273. [
  1274. next => {
  1275. playlistModel.updateOne(
  1276. { _id: playlistId, createdBy: session.userId },
  1277. { $set: { privacy } },
  1278. { runValidators: true },
  1279. next
  1280. );
  1281. },
  1282. (res, next) => {
  1283. PlaylistsModule.runJob("UPDATE_PLAYLIST", { playlistId }, this)
  1284. .then(playlist => {
  1285. next(null, playlist);
  1286. })
  1287. .catch(next);
  1288. }
  1289. ],
  1290. async (err, playlist) => {
  1291. if (err) {
  1292. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  1293. this.log(
  1294. "ERROR",
  1295. "PLAYLIST_UPDATE_PRIVACY",
  1296. `Updating privacy to "${privacy}" for private playlist "${playlistId}" failed for user "${session.userId}". "${err}"`
  1297. );
  1298. return cb({ status: "failure", message: err });
  1299. }
  1300. this.log(
  1301. "SUCCESS",
  1302. "PLAYLIST_UPDATE_PRIVACY",
  1303. `Successfully updated privacy to "${privacy}" for private playlist "${playlistId}" for user "${session.userId}".`
  1304. );
  1305. CacheModule.runJob("PUB", {
  1306. channel: "playlist.updatePrivacy",
  1307. value: {
  1308. userId: session.userId,
  1309. playlist
  1310. }
  1311. });
  1312. return cb({
  1313. status: "success",
  1314. message: "Playlist has been successfully updated"
  1315. });
  1316. }
  1317. );
  1318. })
  1319. };