|
1 | | -from __future__ import annotations |
2 | 1 | from typing import TYPE_CHECKING, List # DON'T YOU DARE PUT THIS UNDER TYPE_CHECKING!!! I'm warning you! |
3 | 2 |
|
4 | 3 | if TYPE_CHECKING: |
|
9 | 8 | from . import errors, __version__ |
10 | 9 | from .anime_girls import AGHPB, CategoryNotFound, Book, BookDict |
11 | 10 |
|
12 | | -from fastapi import FastAPI, Query, Request, Response |
| 11 | +from fastapi import FastAPI, Query, Request |
13 | 12 | from fastapi.responses import FileResponse, JSONResponse, RedirectResponse |
14 | 13 |
|
15 | | -from slowapi import Limiter, _rate_limit_exceeded_handler |
| 14 | +from slowapi import Limiter |
16 | 15 | from slowapi.util import get_remote_address |
17 | 16 | from slowapi.errors import RateLimitExceeded |
18 | 17 |
|
|
52 | 51 | root_path = ROOT_PATH |
53 | 52 | ) |
54 | 53 | app.state.limiter = limiter |
55 | | -app.add_exception_handler(RateLimitExceeded, errors.RateLimited) |
| 54 | +app.add_exception_handler(RateLimitExceeded, errors.rate_limit_handler) |
56 | 55 |
|
57 | 56 | @app.get( |
58 | 57 | "/", |
@@ -84,13 +83,13 @@ async def root(): |
84 | 83 | "description": "The category was not Found." |
85 | 84 | }, |
86 | 85 | 429: { |
87 | | - "model": errors.RateLimitedClass, |
88 | | - "description": "Rate Limit exceeded" |
| 86 | + "model": errors.RateLimited, |
| 87 | + "description": "Rate limit exceeded!" |
89 | 88 | } |
90 | 89 | }, |
91 | 90 | ) |
92 | 91 | @limiter.limit("3/second") |
93 | | -async def random(request: Request, category: str = None): |
| 92 | +async def random(request: Request, category: str = None) -> FileResponse: |
94 | 93 | """Returns a random book.""" |
95 | 94 | if category is None: |
96 | 95 | category = aghpb.random_category() |
@@ -169,13 +168,13 @@ async def search( |
169 | 168 | "description": "The book was not Found." |
170 | 169 | }, |
171 | 170 | 429: { |
172 | | - "model": errors.RateLimitedClass, |
| 171 | + "model": errors.RateLimited, |
173 | 172 | "description": "Rate Limit exceeded" |
174 | 173 | } |
175 | 174 | }, |
176 | 175 | ) |
177 | 176 | @limiter.limit("3/second") |
178 | | -async def get_id(request: Request, search_id: str): |
| 177 | +async def get_id(request: Request, search_id: str) -> FileResponse: |
179 | 178 | """Returns the book found.""" |
180 | 179 | for book in aghpb.books: |
181 | 180 |
|
|
0 commit comments