Coverage for src\app.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.10.1, created at 2025-10-19 21:13 +0800

1from fastapi import FastAPI 

2from fastapi.middleware.cors import CORSMiddleware 

3from src.routers import anime, drama, index, movie 

4from src.utility.config import Config 

5from src.utility.lib import MsgSpecJSONResponse 

6from src.utility.rediss import lifespan_factory 

7from tomllib import load 

8 

9 

10def init_api(enable_cache: bool, flush_cache: bool) -> FastAPI: 

11 tags = [ 

12 { 

13 "name": "anime", 

14 "description": "Endpoints for retrieving data from **[Filmarks Animes (フィルマークス・アニメ)](https://filmarks.com/animes)**", 

15 }, 

16 { 

17 "name": "drama", 

18 "description": "Endpoints for retrieving data from **[Filmarks Dramas (フィルマークス・ドラマ)](https://filmarks.com/dramas)**", 

19 }, 

20 { 

21 "name": "movie", 

22 "description": "Endpoints for retrieving data from **[Filmarks Movies (フィルマークス・映画)](https://filmarks.com)**", 

23 }, 

24 ] 

25 

26 api = FastAPI( 

27 title="MarkuAPI", 

28 summary="Web scraper API for Filmarks Animes, Filmarks Dramas, and Filmarks Movies.", 

29 contact={"name": "e0406370", "url": "https://github.com/e0406370/markuapi"}, 

30 version=load(open(file="./pyproject.toml", mode="rb"))["project"]["version"], 

31 openapi_tags=tags, 

32 redoc_url=None, 

33 swagger_ui_parameters={"defaultModelsExpandDepth": -1, "docExpansion": "none"}, 

34 default_response_class=MsgSpecJSONResponse, 

35 lifespan=lifespan_factory(enable_cache, flush_cache), 

36 ) 

37 

38 api.add_middleware( 

39 CORSMiddleware, 

40 allow_origins=["*"], 

41 allow_credentials=True, 

42 allow_methods=["*"], 

43 allow_headers=["*"], 

44 ) 

45 

46 api.include_router(anime.router) 

47 api.include_router(drama.router) 

48 api.include_router(index.router) 

49 api.include_router(movie.router) 

50 

51 return api 

52 

53 

54app = init_api( 

55 enable_cache=Config.REDIS_ENABLE_CACHE, 

56 flush_cache=Config.REDIS_FLUSH_CACHE 

57)