Skip to content

Commit

Permalink
fix: encode data
Browse files Browse the repository at this point in the history
  • Loading branch information
SaarChaffee committed Mar 2, 2024
1 parent c75371a commit 584b1f7
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions packages/pixiv/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,25 @@ class PixivImageSource extends ImageSource<PixivImageSource.Config> {
const endpoint = 'https://oauth.secure.pixiv.net/' // OAuth Endpoint
const url = trimSlash(endpoint) + '/auth/token'

const data = {
get_secure_url: true,
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
grant_type: 'refresh_token',
refresh_token: this.refreshToken,
}

const resp = await this.ctx.http.axios(url, {
method: 'POST',
data,
headers: {
...this._getHeaders(),
'Content-Type': 'application/x-www-form-urlencoded',
'host': 'oauth.secure.pixiv.net',
},
validateStatus: () => true,
})
const urlencoded = new URLSearchParams()
urlencoded.append('get_secure_url', 'true')
urlencoded.append('client_id', CLIENT_ID)
urlencoded.append('client_secret', CLIENT_SECRET)
urlencoded.append('grant_type', 'refresh_token')
urlencoded.append('refresh_token', this.refreshToken)

const resp = await this.ctx.http(url,
{
method: 'POST',
headers: {
...this._getHeaders(),
'Content-Type': 'application/x-www-form-urlencoded',
'host': 'oauth.secure.pixiv.net',
},
data: urlencoded,
validateStatus: () => true,
}
)

const SUCCESS_STATUS = [200, 301, 302]
if (!SUCCESS_STATUS.includes(resp.status)) {
Expand Down

0 comments on commit 584b1f7

Please sign in to comment.