add basic rate limiting
This commit is contained in:
@ -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(
|
||||
|
Reference in New Issue
Block a user