Update isIPReportedRecently
This commit is contained in:
parent
c08b4a5662
commit
5df7e8e068
1 changed files with 8 additions and 4 deletions
12
index.js
12
index.js
|
|
@ -37,10 +37,14 @@ const fetchBlockedIPs = async () => {
|
|||
};
|
||||
|
||||
const isIPReportedRecently = (rayId, ip, reportedIPs) => {
|
||||
const lastReport = reportedIPs.find(entry =>
|
||||
(entry.rayId === rayId || entry.ip === ip) &&
|
||||
(entry.status === 'TOO_MANY_REQUESTS' || entry.status === 'REPORTED')
|
||||
);
|
||||
const lastReport = reportedIPs.reduce((latest, entry) => {
|
||||
if (
|
||||
(entry.rayId === rayId || entry.ip === ip) &&
|
||||
(entry.status === 'TOO_MANY_REQUESTS' || entry.status === 'REPORTED') &&
|
||||
(!latest || entry.timestamp > latest.timestamp)
|
||||
) return entry;
|
||||
return latest;
|
||||
}, null);
|
||||
|
||||
if (lastReport && (Date.now() - lastReport.timestamp) < REPORTED_IP_COOLDOWN_MS) {
|
||||
return { recentlyReported: true, timeDifference: Date.now() - lastReport.timestamp, reason: lastReport.status === 'TOO_MANY_REQUESTS' ? 'RATE-LIMITED' : 'REPORTED' };
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue