// 检查是否有验证尝试记录
if (!attemptStore[clientIp]) {
attemptStore[clientIp] = { attempts: 0, lastAttempt: currentTime };
}
const clientAttempt = attemptStore[clientIp];
// 检查是否超过重试时间限制
if (currentTime - clientAttempt.lastAttempt < retryTimeout && clientAttempt.attempts >= 3) {
obj.message = '超出尝试次数,请在60秒后重试 | Too many attempts, please retry after 60 seconds.';
} else {
// 如果时间超过60秒,重置尝试次数
if (currentTime - clientAttempt.lastAttempt >= retryTimeout) {
clientAttempt.attempts = 0;
}
// 验证密钥
if (req.body && req.body.token && process.env.AUTH_SECRET_KEY === req.body.token) {
obj = { status: 'Success', message: 'Verify successfully', data: null };
clientAttempt.attempts = 0; // 验证成功,重置尝试次数
} else {
clientAttempt.attempts += 1; // 验证失败,增加尝试次数
obj.message += ` | 当前尝试次数: ${clientAttempt.attempts}`;
}
clientAttempt.lastAttempt = currentTime; // 更新最后尝试时间
}
res.setHeader('Content-type', 'application/json');
res.writeHead(200).end(JSON.stringify(obj));