feat: Recipe Timeline Images (#2444)

* refactored recipe image paths/service

* added routes for updating/fetching timeline images

* make generate

* added event image upload and rendering

* switched update to patch to preserve timestamp

* added tests

* tweaked order of requests

* always reload events when opening the timeline

* re-arranged elements to make them look nicer

* delete files when timeline event is deleted
This commit is contained in:
Michael Genson
2023-08-06 12:49:30 -05:00
committed by GitHub
parent 06962cf865
commit dfe4942451
16 changed files with 355 additions and 92 deletions

View File

@@ -129,29 +129,48 @@ class Recipe(RecipeSummary):
comments: list[RecipeCommentOut] | None = []
@staticmethod
def directory_from_id(recipe_id: UUID4 | str) -> Path:
return app_dirs.RECIPE_DATA_DIR.joinpath(str(recipe_id))
def _get_dir(dir: Path) -> Path:
"""Gets a directory and creates it if it doesn't exist"""
dir.mkdir(exist_ok=True, parents=True)
return dir
@classmethod
def directory_from_id(cls, recipe_id: UUID4 | str) -> Path:
return cls._get_dir(app_dirs.RECIPE_DATA_DIR.joinpath(str(recipe_id)))
@classmethod
def asset_dir_from_id(cls, recipe_id: UUID4 | str) -> Path:
return cls._get_dir(cls.directory_from_id(recipe_id).joinpath("assets"))
@classmethod
def image_dir_from_id(cls, recipe_id: UUID4 | str) -> Path:
return cls._get_dir(cls.directory_from_id(recipe_id).joinpath("images"))
@classmethod
def timeline_image_dir_from_id(cls, recipe_id: UUID4 | str, timeline_event_id: UUID4 | str) -> Path:
return cls._get_dir(cls.image_dir_from_id(recipe_id).joinpath("timeline").joinpath(str(timeline_event_id)))
@property
def directory(self) -> Path:
if not self.id:
raise ValueError("Recipe has no ID")
folder = app_dirs.RECIPE_DATA_DIR.joinpath(str(self.id))
folder.mkdir(exist_ok=True, parents=True)
return folder
return self.directory_from_id(self.id)
@property
def asset_dir(self) -> Path:
folder = self.directory.joinpath("assets")
folder.mkdir(exist_ok=True, parents=True)
return folder
if not self.id:
raise ValueError("Recipe has no ID")
return self.asset_dir_from_id(self.id)
@property
def image_dir(self) -> Path:
folder = self.directory.joinpath("images")
folder.mkdir(exist_ok=True, parents=True)
return folder
if not self.id:
raise ValueError("Recipe has no ID")
return self.image_dir_from_id(self.id)
class Config:
orm_mode = True