mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
Fix API method case and add day parameter to ranking API
This commit is contained in:
@@ -7,7 +7,7 @@ const API_AUTH: APIMAP = {
|
||||
logout: {
|
||||
url: 'https://passport.bilibili.com/login/exit/v2',
|
||||
_fetch: {
|
||||
method: 'POST',
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
||||
},
|
||||
|
||||
@@ -21,6 +21,7 @@ const API_RANKING: APIMAP = {
|
||||
},
|
||||
params: {
|
||||
season_type: 1,
|
||||
day: 3,
|
||||
},
|
||||
afterHandle: AHS.J_D,
|
||||
},
|
||||
|
||||
@@ -72,6 +72,7 @@ function apiListenerFactory(API_MAP: APIMAP) {
|
||||
|
||||
let { _fetch, url, params = {}, afterHandle } = API_MAP[contentScriptQuery] as API
|
||||
const { method, headers, body } = _fetch as _FETCH
|
||||
const isGET = method.toLocaleLowerCase() === 'get'
|
||||
// merge params and body
|
||||
const targetParams = Object.assign({}, params)
|
||||
let targetBody = Object.assign({}, body)
|
||||
@@ -82,21 +83,22 @@ function apiListenerFactory(API_MAP: APIMAP) {
|
||||
targetParams[key] = rest[key]
|
||||
})
|
||||
|
||||
// generate body or params
|
||||
if (method === 'get') {
|
||||
// generate params
|
||||
if (Object.keys(targetParams).length) {
|
||||
const urlParams = new URLSearchParams()
|
||||
for (const key in targetParams)
|
||||
targetParams[key] && urlParams.append(key, targetParams[key])
|
||||
url += `?${urlParams.toString()}`
|
||||
}
|
||||
else {
|
||||
// post
|
||||
// generate body
|
||||
if (!isGET) {
|
||||
targetBody = (headers && headers['Content-Type'] && headers['Content-Type'].includes('application/x-www-form-urlencoded'))
|
||||
? new URLSearchParams(targetBody)
|
||||
: JSON.stringify(targetBody)
|
||||
}
|
||||
// get cant take body
|
||||
const fetchOpt = method === 'get' ? { method, headers } : { method, headers, body: targetBody }
|
||||
const fetchOpt = { method, headers }
|
||||
!isGET && Object.assign(fetchOpt, { body: targetBody })
|
||||
|
||||
// fetch and after handle
|
||||
let baseFunc = fetch(url, fetchOpt)
|
||||
|
||||
Reference in New Issue
Block a user