Add handlers for AniList rate limit (#92)
This commit is contained in:
@@ -131,3 +131,8 @@
|
||||
await page.close()
|
||||
return {resized, mime}
|
||||
}
|
||||
|
||||
/** Wait */
|
||||
export async function wait(seconds) {
|
||||
await new Promise(solve => setTimeout(solve), seconds*1000)
|
||||
}
|
||||
@@ -51,11 +51,22 @@
|
||||
let page = 1
|
||||
let next = false
|
||||
do {
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > anilist > querying api (favorites ${type}s - page ${page})`)
|
||||
const {data:{data:{User:{favourites:{[type]:{nodes, pageInfo:cursor}}}}}} = await imports.axios.post("https://graphql.anilist.co", {variables:{name:user, page}, query:queries.anilist.favorites({type})})
|
||||
page++
|
||||
next = cursor.hasNextPage
|
||||
list.push(...await Promise.all(nodes.map(media => format({media:{progess:null, score:null, media}, imports}))))
|
||||
}
|
||||
catch (error) {
|
||||
if ((error.isAxiosError)&&(error.response.status === 429)) {
|
||||
const delay = Number(error.response.headers["retry-after"])+5
|
||||
console.debug(`metrics/compute/${login}/plugins > anilist > reached requests limit, retrying in ${delay}s`)
|
||||
await imports.wait(delay)
|
||||
continue
|
||||
}
|
||||
throw error
|
||||
}
|
||||
} while (next)
|
||||
//Format and save results
|
||||
result.lists[type].favorites = shuffle ? imports.shuffle(list) : list
|
||||
@@ -75,6 +86,7 @@
|
||||
let page = 1
|
||||
let next = false
|
||||
do {
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > anilist > querying api (favorites characters - page ${page})`)
|
||||
const {data:{data:{User:{favourites:{characters:{nodes, pageInfo:cursor}}}}}} = await imports.axios.post("https://graphql.anilist.co", {variables:{name:user, page}, query:queries.anilist.characters()})
|
||||
page++
|
||||
@@ -83,6 +95,16 @@
|
||||
console.debug(`metrics/compute/${login}/plugins > anilist > processing ${name}`)
|
||||
characters.push({name, artwork:artwork ? await imports.imgb64(artwork) : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg=="})
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
if ((error.isAxiosError)&&(error.response.status === 429)) {
|
||||
const delay = Number(error.response.headers["retry-after"])+5
|
||||
console.debug(`metrics/compute/${login}/plugins > anilist > reached requests limit, retrying in ${delay}s`)
|
||||
await imports.wait(delay)
|
||||
continue
|
||||
}
|
||||
throw error
|
||||
}
|
||||
} while (next)
|
||||
//Format and save results
|
||||
result.characters = shuffle ? imports.shuffle(characters) : characters
|
||||
|
||||
Reference in New Issue
Block a user