Skip to content

Commit

Permalink
feat: support fetch API produced in Koishi v4.17.0 (#138)
Browse files Browse the repository at this point in the history
* fix: encode data

* chore: use Object

* fix: use the best pratice one

---------

Co-authored-by: Maiko Tan <[email protected]>
  • Loading branch information
SaarChaffee and MaikoTan committed Mar 4, 2024
1 parent c75371a commit 7548c54
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/pixiv/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, Schema, trimSlash } from 'koishi'
import { Context, Quester, Schema, trimSlash } from 'koishi'
import { ImageSource } from 'koishi-plugin-booru'
import { PixivAppApi } from './types'

Expand Down Expand Up @@ -73,6 +73,9 @@ class PixivImageSource extends ImageSource<PixivImageSource.Config> {
}
})
} catch (err) {
if (Quester.Error.is(err)) {
throw new Error('get pixiv image failed: ' + `${err.message} (${err.response?.status})`)
}
return
}
}
Expand All @@ -81,17 +84,15 @@ 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,
const data = new URLSearchParams({
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,
const resp = await this.ctx.http.post(url, data, {
headers: {
...this._getHeaders(),
'Content-Type': 'application/x-www-form-urlencoded',
Expand Down

0 comments on commit 7548c54

Please sign in to comment.