spotify.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 new SoundCloud API key
  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. };