add basic rate limiting

This commit is contained in:
2025-07-01 11:38:38 -04:00
parent 1991e5b31b
commit c3f753a4f0
9 changed files with 64 additions and 20 deletions

View File

@ -2,7 +2,8 @@ import os
import random
from typing import LiteralString, Optional, Union
import aiosqlite as sqlite3
from fastapi import FastAPI
from fastapi import FastAPI, Depends
from fastapi_throttle import RateLimiter
from fastapi.responses import JSONResponse
from .constructors import RandMsgRequest
@ -19,7 +20,10 @@ class RandMsg(FastAPI):
self.endpoint_name = "randmsg"
app.add_api_route(
f"/{self.endpoint_name}", self.randmsg_handler, methods=["POST"]
f"/{self.endpoint_name}", self.randmsg_handler,
methods=["POST"], dependencies=[Depends(
RateLimiter(times=5, seconds=2)
)]
)
async def randmsg_handler(