Skip to content
This repository has been archived by the owner on Oct 9, 2022. It is now read-only.

fix(fetch): spotify url generation #26

Merged
merged 2 commits into from
Dec 11, 2021

Conversation

nevrending
Copy link
Contributor

@nevrending nevrending commented Oct 21, 2021

Hi, thanks for these amazing packages.

Seems like the package published at NPM is not up to date with the master branch of this repo. Thus, I'm using this package like below:

"dependencies": {
    ...
    "erela.js-spotify": "https://github.com/MenuDocs/erela.js-spotify#build",
    ...
  }

Adding Spotify links to the queue failed, and upon initial investigation:

{
  loadType: 'LOAD_FAILED',
  tracks: [],
  playlist: null,
  exception: {
    message: 'The track artists array was not provided',
    severity: 'COMMON'
  }
}

That led to

{ error: { status: 404, message: 'Service not found' } }

Eventually I found out that the BASE_URL in fetch was "generated" twice

{
  coreOptions: {},
  httpMethod: 'GET',
  reqHeaders: {
    authorization: 'Bearer <token>'
  },
  timeoutOptions: {},
  url: URL {
    href: 'https://api.spotify.com/v1/https://api.spotify.com/v1/tracks/2vzpoecVhBE1pKtHzKONaN',
    origin: 'https://api.spotify.com',
    protocol: 'https:',
    username: '',
    password: '',
    host: 'api.spotify.com',
    hostname: 'api.spotify.com',
    port: '',
    pathname: '/v1/https://api.spotify.com/v1/tracks/2vzpoecVhBE1pKtHzKONaN',
    search: '',
    searchParams: URLSearchParams {},
    hash: ''
  }
}

This PR fixed the URL generation

{
  coreOptions: {},
  httpMethod: 'GET',
  reqHeaders: {
    authorization: 'Bearer <token>'
  },
  timeoutOptions: {},
  url: URL {
    href: 'https://api.spotify.com/v1/tracks/2vzpoecVhBE1pKtHzKONaN',
    origin: 'https://api.spotify.com',
    protocol: 'https:',
    username: '',
    password: '',
    host: 'api.spotify.com',
    hostname: 'api.spotify.com',
    port: '',
    pathname: '/v1/tracks/2vzpoecVhBE1pKtHzKONaN',
    search: '',
    searchParams: URLSearchParams {},
    hash: ''
  }
}

And I have tested this with Spotify Track URL, Album URL, and Playlist URL.
All tracks were successfully loaded and successfully played.

Some additional environment info:

  • Node.js v16.11.0
  • Discord.js v13.2.0
  • erela.js v2.3.3

@viztea viztea merged commit 42591f1 into MenuDocs:master Dec 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants