aboutsummaryrefslogtreecommitdiff
path: root/pages/api/v2/source/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'pages/api/v2/source/index.js')
-rw-r--r--pages/api/v2/source/index.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/pages/api/v2/source/index.js b/pages/api/v2/source/index.js
index 51ac5ec..74a63cb 100644
--- a/pages/api/v2/source/index.js
+++ b/pages/api/v2/source/index.js
@@ -1,3 +1,4 @@
+import { rateLimiterRedis, redis } from "@/lib/redis";
import axios from "axios";
const CONSUMET_URI = process.env.API_URI;
@@ -33,6 +34,17 @@ export default async function handler(req, res) {
return res.status(405).json({ message: "Method not allowed" });
}
+ if (redis) {
+ try {
+ const ipAddress = req.socket.remoteAddress;
+ await rateLimiterRedis.consume(ipAddress);
+ } catch (error) {
+ return res.status(429).json({
+ error: `Too Many Requests, retry after ${error.msBeforeNext / 1000}`,
+ });
+ }
+ }
+
const { source, providerId, watchId, episode, id, sub = "sub" } = req.body;
if (source === "anify") {