From ac2a4b6ca6545fc0bdd184ae601a381b6445e10e Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Sat, 31 Oct 2026 14:32:29 -0500 Subject: [PATCH] feat: manage timeline event image (#8928) --- .../Domain/Recipe/RecipeTimeline.vue | 26 +++++- .../Recipe/RecipeTimelineContextMenu.vue | 80 ++++++++++++++++++- .../Domain/Recipe/RecipeTimelineItem.vue | 18 +++-- frontend/app/composables/api/static-routes.ts | 4 +- mealie/routes/recipe/timeline_events.py | 3 + .../test_recipe_timeline_events.py | 39 +++++++++ 6 files changed, 157 insertions(+), 13 deletions(-) diff --git a/frontend/app/components/Domain/Recipe/RecipeTimeline.vue b/frontend/app/components/Domain/Recipe/RecipeTimeline.vue index 1755730c2..b89400670 100644 --- a/frontend/app/components/Domain/Recipe/RecipeTimeline.vue +++ b/frontend/app/components/Domain/Recipe/RecipeTimeline.vue @@ -103,11 +103,12 @@ diff --git a/frontend/app/components/Domain/Recipe/RecipeTimelineItem.vue b/frontend/app/components/Domain/Recipe/RecipeTimelineItem.vue index 37a452205..7034032b4 100644 --- a/frontend/app/components/Domain/Recipe/RecipeTimelineItem.vue +++ b/frontend/app/components/Domain/Recipe/RecipeTimelineItem.vue @@ -25,14 +25,15 @@ {{ $d(new Date(event.timestamp || "")) }} - + {{ event.subject }} - + import RecipeCardMobile from "./RecipeCardMobile.vue"; import RecipeTimelineContextMenu from "./RecipeTimelineContextMenu.vue"; +import type { TimelineEventEdit } from "./RecipeTimelineContextMenu.vue"; import { useStaticRoutes } from "~/composables/api"; import { useTimelineEventTypes } from "~/composables/recipes/use-recipe-timeline-events"; -import type { Recipe, RecipeTimelineEventOut, RecipeTimelineEventUpdate } from "~/lib/api/types/recipe"; +import type { Recipe, RecipeTimelineEventOut } from "~/lib/api/types/recipe"; import UserAvatar from "~/components/Domain/User/UserAvatar.vue"; import SafeMarkdown from "~/components/global/SafeMarkdown.vue"; @@ -111,7 +113,7 @@ const props = withDefaults(defineProps(), { defineEmits<{ selected: []; - update: [event: RecipeTimelineEventUpdate]; + update: [edit: TimelineEventEdit]; delete: []; }>(); @@ -166,12 +168,18 @@ const icon = computed(() => { }); const hideImage = ref(false); +const imageKey = ref(1); +watch(() => props.event, () => { + hideImage.value = false; + imageKey.value++; +}); + const eventImageUrl = computed(() => { if (props.event.image !== "has image") { return ""; } - return recipeTimelineEventSmallImage(props.event.recipeId, props.event.id); + return recipeTimelineEventSmallImage(props.event.recipeId, props.event.id, imageKey.value); }); diff --git a/frontend/app/composables/api/static-routes.ts b/frontend/app/composables/api/static-routes.ts index 31eda446e..26ba433e8 100644 --- a/frontend/app/composables/api/static-routes.ts +++ b/frontend/app/composables/api/static-routes.ts @@ -27,8 +27,8 @@ export const useStaticRoutes = () => { return `${prefix}/media/recipes/${recipeId}/images/timeline/${timelineEventId}/original.webp`; } - function recipeTimelineEventSmallImage(recipeId: string, timelineEventId: string) { - return `${prefix}/media/recipes/${recipeId}/images/timeline/${timelineEventId}/min-original.webp`; + function recipeTimelineEventSmallImage(recipeId: string, timelineEventId: string, key: string | number = 1) { + return `${prefix}/media/recipes/${recipeId}/images/timeline/${timelineEventId}/min-original.webp?rnd=${key}`; } function recipeTimelineEventTinyImage(recipeId: string, timelineEventId: string) { diff --git a/mealie/routes/recipe/timeline_events.py b/mealie/routes/recipe/timeline_events.py index f7305add6..1c82c2199 100644 --- a/mealie/routes/recipe/timeline_events.py +++ b/mealie/routes/recipe/timeline_events.py @@ -115,6 +115,9 @@ class RecipeTimelineEventsController(BaseCrudController): @router.put("/{item_id}", response_model=RecipeTimelineEventOut) def update_one(self, item_id: UUID4, data: RecipeTimelineEventUpdate): event = self.mixins.patch_one(data, item_id) + if data.image == TimelineEventImage.does_not_have_image.value: + RecipeDataService(event.recipe_id).delete_image(event.image_dir) + recipe = self.group_recipes.get_one(event.recipe_id, "id") if recipe: self.publish_event( diff --git a/tests/integration_tests/user_recipe_tests/test_recipe_timeline_events.py b/tests/integration_tests/user_recipe_tests/test_recipe_timeline_events.py index 2868be1ba..aca26257c 100644 --- a/tests/integration_tests/user_recipe_tests/test_recipe_timeline_events.py +++ b/tests/integration_tests/user_recipe_tests/test_recipe_timeline_events.py @@ -359,6 +359,45 @@ def test_timeline_event_update_image( assert updated_event.image == TimelineEventImage.has_image.value +def test_timeline_event_remove_image( + api_client: TestClient, + unique_user: TestUser, + recipes: list[Recipe], + test_image_jpg: str, +): + new_event_data = { + "recipe_id": str(recipes[0].id), + "user_id": str(unique_user.user_id), + "subject": random_string(), + "event_type": "info", + } + event_response = api_client.post(api_routes.recipes_timeline_events, json=new_event_data, headers=unique_user.token) + new_event = RecipeTimelineEventOut.model_validate(event_response.json()) + + with open(test_image_jpg, "rb") as f: + r = api_client.put( + api_routes.recipes_timeline_events_item_id_image(new_event.id), + files={"image": ("test_image_jpg.jpg", f, "image/jpeg")}, + data={"extension": "jpg"}, + headers=unique_user.token, + ) + r.raise_for_status() + + image_files = list(new_event.image_dir.glob("*.webp")) + assert image_files + + event_response = api_client.put( + api_routes.recipes_timeline_events_item_id(new_event.id), + json={"subject": new_event.subject, "image": TimelineEventImage.does_not_have_image.value}, + headers=unique_user.token, + ) + assert event_response.status_code == 200 + + updated_event = RecipeTimelineEventOut.model_validate(event_response.json()) + assert updated_event.image == TimelineEventImage.does_not_have_image.value + assert not any(image_file.exists() for image_file in image_files) + + @pytest.mark.parametrize("use_other_household_user", [True, False]) def test_create_recipe_with_timeline_event( api_client: TestClient,