feat(twitter): skip invalid token

This commit is contained in:
DIYgod 2024-08-26 15:33:19 +08:00
parent 292471ec23
commit 3ce18dff48
No known key found for this signature in database
1 changed files with 8 additions and 3 deletions

View File

@ -119,17 +119,22 @@ export const twitterGot = async (url, params) => {
},
dispatcher: dispatchers[token].agent,
onResponse: async ({ response }) => {
if (response.status === 403 || response.status === 401) {
logger.debug(`Delete twitter cookie for token ${token}`);
if (response.status === 403 || response.status === 401 || response.status === 429) {
const newCookie = await login({
username: config.twitter.username?.[index],
password: config.twitter.password?.[index],
authenticationSecret: config.twitter.authenticationSecret?.[index],
});
if (newCookie) {
await cache.set(`twitter:cookie:${token}`, newCookie, config.cache.contentExpire);
logger.debug(`Reset twitter cookie for token ${token}`);
} else {
config.twitter.authToken?.splice(index, 1);
config.twitter.username?.splice(index, 1);
config.twitter.password?.splice(index, 1);
await cache.set(`twitter:cookie:${token}`, '', config.cache.contentExpire);
logger.debug(`Delete twitter cookie for token ${token}, remaining tokens: ${config.twitter.authToken?.length}`);
}
await cache.set(`twitter:cookie:${token}`, newCookie || '', config.cache.contentExpire);
}
},
});