songs.js 38 KB

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