playlists.js 39 KB

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