Update isIPReportedRecently

This commit is contained in:
Sefinek 2024-11-10 06:22:28 +01:00
parent c08b4a5662
commit 5df7e8e068

View file

@ -37,10 +37,14 @@ const fetchBlockedIPs = async () => {
}; };
const isIPReportedRecently = (rayId, ip, reportedIPs) => { const isIPReportedRecently = (rayId, ip, reportedIPs) => {
const lastReport = reportedIPs.find(entry => const lastReport = reportedIPs.reduce((latest, entry) => {
(entry.rayId === rayId || entry.ip === ip) && if (
(entry.status === 'TOO_MANY_REQUESTS' || entry.status === 'REPORTED') (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) { 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' }; return { recentlyReported: true, timeDifference: Date.now() - lastReport.timestamp, reason: lastReport.status === 'TOO_MANY_REQUESTS' ? 'RATE-LIMITED' : 'REPORTED' };