songs.js 38 KB

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