Skip to content

Commit

Permalink
Lets try this now
Browse files Browse the repository at this point in the history
  • Loading branch information
markjfannon committed Sep 23, 2024
1 parent e343e55 commit f3f48e5
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions pages/api/message.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,19 @@
/*import Axios from 'axios';
import Axios from 'axios';
import requestIp from 'request-ip'

// Any IP starting with 128.243 belongs to Uni of Nottingham
const UON_PREFIX = "128.243"

const rateLimitMap = new Map();
export default async function handler(req, res) {
//var url = process.env.SLACK_URL
//var x = await Axios.post(url, {text:req.body.msg})

const detectedIp = requestIp.getClientIp(req)
const limit = 5; // Limiting requests to 5 per minute per IP
const windowMs = 60 * 1000; // 1 minute
const campus = detectedIp.indexOf("128.243") == 0;

if (req.body.msg.length >= 200) {
return res.status(200).json({});
}
if (!rateLimitMap.has(detectedIp)) {
rateLimitMap.set(detectedIp, {
count: 0,
lastReset: Date.now(),
});
}
const ipData = rateLimitMap.get(detectedIp);
if (Date.now() - ipData.lastReset > windowMs) {
ipData.count = 0;
ipData.lastReset = Date.now();
}
if (ipData.count >= limit) {
return res.status(429).send("Too Many Requests");
}
ipData.count += 1;

var discord = process.env.DISCORD_URL
await Axios.post(discord, {
Expand Down Expand Up @@ -66,4 +41,3 @@ export default async function handler(req, res) {
res.status(200).json({})
}

*/

0 comments on commit f3f48e5

Please sign in to comment.