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

@@ -65,10 +65,11 @@ class RecipeDataService(BaseService):
self.dir_data = Recipe.directory_from_id(self.recipe_id)
self.dir_image = self.dir_data.joinpath("images")
self.dir_image_timeline = self.dir_image.joinpath("timeline")
self.dir_assets = self.dir_data.joinpath("assets")
self.dir_image.mkdir(parents=True, exist_ok=True)
self.dir_assets.mkdir(parents=True, exist_ok=True)
for dir in [self.dir_image, self.dir_image_timeline, self.dir_assets]:
dir.mkdir(parents=True, exist_ok=True)
def delete_all_data(self) -> None:
try:
@@ -76,9 +77,12 @@ class RecipeDataService(BaseService):
except Exception as e:
self.logger.exception(f"Failed to delete recipe data: {e}")
def write_image(self, file_data: bytes | Path, extension: str) -> Path:
def write_image(self, file_data: bytes | Path, extension: str, image_dir: Path | None = None) -> Path:
if not image_dir:
image_dir = self.dir_image
extension = extension.replace(".", "")
image_path = self.dir_image.joinpath(f"original.{extension}")
image_path = image_dir.joinpath(f"original.{extension}")
image_path.unlink(missing_ok=True)
if isinstance(file_data, Path):