Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
csikb committed Apr 3, 2024
1 parent 27f4b4e commit 2a15c39
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
18 changes: 8 additions & 10 deletions src/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
from functools import lru_cache
from typing import Annotated

from fastapi import Depends

from .services.member import MemberService
from .services.video import VideoService
from .settings import Settings


@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)
10 changes: 6 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/services/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
12 changes: 6 additions & 6 deletions src/services/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 2a15c39

Please sign in to comment.