spotify.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import mongoose from "mongoose";
  2. import async from "async";
  3. import isLoginRequired from "../hooks/loginRequired";
  4. import { useHasPermission } from "../hooks/hasPermission";
  5. // eslint-disable-next-line
  6. import moduleManager from "../../index";
  7. const DBModule = moduleManager.modules.db;
  8. const UtilsModule = moduleManager.modules.utils;
  9. const SoundcloudModule = moduleManager.modules.soundcloud;
  10. const SpotifyModule = moduleManager.modules.spotify;
  11. export default {
  12. /**
  13. * Fetches tracks from media sources
  14. *
  15. * @returns {{status: string, data: object}}
  16. */
  17. getTracksFromMediaSources: useHasPermission(
  18. "admin.view.spotify",
  19. function getTracksFromMediaSources(session, mediaSources, cb) {
  20. SpotifyModule.runJob("GET_TRACKS_FROM_MEDIA_SOURCES", { mediaSources }, this)
  21. .then(response => {
  22. this.log(
  23. "SUCCESS",
  24. "SPOTIFY_GET_TRACKS_FROM_MEDIA_SOURCES",
  25. `Getting tracks from media sources was successful.`
  26. );
  27. return cb({ status: "success", data: { tracks: response.tracks } });
  28. })
  29. .catch(async err => {
  30. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  31. this.log(
  32. "ERROR",
  33. "SPOTIFY_GET_TRACKS_FROM_MEDIA_SOURCES",
  34. `Getting tracks from media sources failed. "${err}"`
  35. );
  36. return cb({ status: "error", message: err });
  37. });
  38. }
  39. ),
  40. /**
  41. * Fetches albums from ids
  42. *
  43. * @returns {{status: string, data: object}}
  44. */
  45. getAlbumsFromIds: useHasPermission("admin.view.spotify", function getTracksFromMediaSources(session, albumIds, cb) {
  46. SpotifyModule.runJob("GET_ALBUMS_FROM_IDS", { albumIds }, this)
  47. .then(albums => {
  48. this.log("SUCCESS", "SPOTIFY_GET_ALBUMS_FROM_IDS", `Getting albums from ids was successful.`);
  49. return cb({ status: "success", data: { albums } });
  50. })
  51. .catch(async err => {
  52. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  53. this.log("ERROR", "SPOTIFY_GET_ALBUMS_FROM_IDS", `Getting albums from ids failed. "${err}"`);
  54. return cb({ status: "error", message: err });
  55. });
  56. }),
  57. /**
  58. * Fetches artists from ids
  59. *
  60. * @returns {{status: string, data: object}}
  61. */
  62. getArtistsFromIds: useHasPermission(
  63. "admin.view.spotify",
  64. function getTracksFromMediaSources(session, artistIds, cb) {
  65. SpotifyModule.runJob("GET_ARTISTS_FROM_IDS", { artistIds }, this)
  66. .then(artists => {
  67. this.log("SUCCESS", "SPOTIFY_GET_ARTISTS_FROM_IDS", `Getting artists from ids was successful.`);
  68. return cb({ status: "success", data: { artists } });
  69. })
  70. .catch(async err => {
  71. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  72. this.log("ERROR", "SPOTIFY_GET_ARTISTS_FROM_IDS", `Getting artists from ids failed. "${err}"`);
  73. return cb({ status: "error", message: err });
  74. });
  75. }
  76. )
  77. };