spotify.js 2.5 KB

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