Skip to content

Commit

Permalink
feat(twitter): remove limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Aug 26, 2024
1 parent 3ce18df commit ef64486
Showing 1 changed file with 0 additions and 17 deletions.
17 changes: 0 additions & 17 deletions lib/routes/twitter/api/web-api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,13 @@ import { CookieAgent, CookieClient } from 'http-cookie-agent/undici';
import { ProxyAgent } from 'undici';
import cache from '@/utils/cache';
import logger from '@/utils/logger';
import { RateLimiterMemory, RateLimiterRedis, RateLimiterQueue } from 'rate-limiter-flexible';
import ofetch from '@/utils/ofetch';
import proxy from '@/utils/proxy';
import login from './login';

const dispatchers = {};
let authTokenIndex = 0;

const loginLimiter = cache.clients.redisClient
? new RateLimiterRedis({
points: 1,
duration: 1,
execEvenly: true,
storeClient: cache.clients.redisClient,
})
: new RateLimiterMemory({
points: 1,
duration: 1,
execEvenly: true,
});

const loginLimiterQueue = new RateLimiterQueue(loginLimiter);

const token2Cookie = (token) =>
cache.tryGet(`twitter:cookie:${token}`, async () => {
const jar = new CookieJar();
Expand All @@ -56,7 +40,6 @@ export const twitterGot = async (url, params) => {
if (!config.twitter.authToken) {
throw new ConfigNotFoundError('Twitter cookie is not configured');
}
await loginLimiterQueue.removeTokens(1);
const index = authTokenIndex++ % config.twitter.authToken.length;
const token = config.twitter.authToken[index];

Expand Down

0 comments on commit ef64486

Please sign in to comment.