mirror of
https://github.com/hansputera/tiktok-dl.git
synced 2026-04-06 04:01:57 +02:00
feat(middleware.ratelimit): use "await client.get" instead than callback
Signed-off-by: Hanif Dwy Putra S <47862061+hansputera@users.noreply.github.com>
This commit is contained in:
@@ -14,18 +14,22 @@ export const ratelimitMiddleware = async (
|
||||
.status(401)
|
||||
.json({message: "Couldn't find your real ip address."});
|
||||
}
|
||||
client.get('rate-' + ip, (_, result) => {
|
||||
if (result) {
|
||||
if (parseInt(result) > rateLimitConfig.maxRatelimitPerXSeconds) {
|
||||
return res.status(429).json({
|
||||
message: 'Please try again, you are getting ratelimit!',
|
||||
});
|
||||
}
|
||||
client.incr('rate-' + ip);
|
||||
return true;
|
||||
} else {
|
||||
client.set('rate-' + ip, '1', 'EX', rateLimitConfig.ratelimitTime);
|
||||
return true;
|
||||
const result = await client.get('rate-'.concat(ip.toString()));
|
||||
if (result) {
|
||||
if (parseInt(result) > rateLimitConfig.maxRatelimitPerXSeconds) {
|
||||
return res.status(429).json({
|
||||
message: 'Please try again, you are getting ratelimit!',
|
||||
});
|
||||
}
|
||||
});
|
||||
client.incr('rate-'.concat(ip.toString()));
|
||||
return true;
|
||||
} else {
|
||||
client.set(
|
||||
'rate-'.concat(ip.toString()),
|
||||
'1',
|
||||
'EX',
|
||||
rateLimitConfig.ratelimitTime,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user