playlists.js 39 KB

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