Skip to content

Commit

Permalink
fix: use the best pratice one
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikoTan committed Mar 4, 2024
1 parent 0651a26 commit 80b5698
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 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 @@ -89,18 +92,14 @@ class PixivImageSource extends ImageSource<PixivImageSource.Config> {
refresh_token: this.refreshToken,
})

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

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

0 comments on commit 80b5698

Please sign in to comment.