diff --git a/src/dependencies.py b/src/dependencies.py index d5ff76d..9ef0a5b 100644 --- a/src/dependencies.py +++ b/src/dependencies.py @@ -1,4 +1,7 @@ from functools import lru_cache +from typing import Annotated + +from fastapi import Depends from .services.member import MemberService from .services.video import VideoService @@ -6,20 +9,15 @@ @lru_cache -def get_settings() -> Settings: - print("Loading settings") +def get_settings(): return Settings() -@lru_cache -def get_member_service() -> MemberService: +def get_member_service(settings: Annotated[Settings, Depends(get_settings)]): """Get the member service.""" - print("Loading member service") - return MemberService(get_settings().server_base_path) + return MemberService(settings.server_base_path) -@lru_cache -def get_video_service() -> VideoService: +def get_video_service(settings: Annotated[Settings, Depends(get_settings)]): """Get the video service.""" - print("Loading video service") - return VideoService(get_settings().server_base_path) + return VideoService(settings.server_base_path) diff --git a/src/main.py b/src/main.py index 7ff6694..fac5702 100644 --- a/src/main.py +++ b/src/main.py @@ -4,16 +4,18 @@ from fastapi import FastAPI -from .dependencies import get_member_service, get_video_service +from .dependencies import get_settings from .routers import health, member, video - -member_service = get_member_service() -video_service = get_video_service() +from .services.member import MemberService +from .services.video import VideoService @asynccontextmanager async def lifespan(api: FastAPI): # pylint: disable=unused-argument """Create the base paths for the video and member folders on startup.""" + settings = get_settings() + member_service = MemberService(settings.server_base_path) + video_service = VideoService(settings.server_base_path) video_service.create_base_path() member_service.create_base_path() yield diff --git a/src/services/member.py b/src/services/member.py index 082926c..645f7ba 100644 --- a/src/services/member.py +++ b/src/services/member.py @@ -13,6 +13,11 @@ class MemberService: def __init__(self, base_path: str): self.id_paths_base = Path(base_path, "m") self.url_paths_base = Path(base_path, "member") + self.profile_picture_sizes = [ + ImgFormat(1920, 1080, "xl"), + ImgFormat(1280, 720, "l"), + ImgFormat(854, 480, "m"), + ] def create_folder_structure(self, member: Member): """ @@ -38,12 +43,7 @@ def create_profile_picture(self, img_file: bytes, member_id: UUID): :return: None """ profile_picture_path = Path(self.to_id_path(member_id), "profile") - profile_picture_sizes = [ - ImgFormat(1920, 1080, "xl"), - ImgFormat(1280, 720, "l"), - ImgFormat(854, 480, "m"), - ] - create_images(img_file, profile_picture_path, profile_picture_sizes) + create_images(img_file, profile_picture_path, self.profile_picture_sizes) def update_symlink(self, member: Member): """ diff --git a/src/services/video.py b/src/services/video.py index ab5208f..3d5bd6f 100644 --- a/src/services/video.py +++ b/src/services/video.py @@ -13,6 +13,11 @@ class VideoService: def __init__(self, base_path: str): self.id_paths_base = Path(base_path, "v") self.url_paths_base = Path(base_path, "video") + self.poster_sizes = [ + ImgFormat(1920, 1080, "fhd"), + ImgFormat(1280, 720, "hd"), + ImgFormat(854, 480, "sd"), + ] def create_folder_structure(self, video: Video): """ @@ -40,12 +45,7 @@ def create_thumbnails(self, img_file: bytes, video_id: UUID): :return: None """ thumbnail_path = Path(self.to_id_path(video_id), "thumbnail") - poster_sizes = [ - ImgFormat(1920, 1080, "fhd"), - ImgFormat(1280, 720, "hd"), - ImgFormat(854, 480, "sd"), - ] - create_images(img_file, thumbnail_path, poster_sizes) + create_images(img_file, thumbnail_path, self.poster_sizes) def update_symlinks(self, video: Video): """