Skip to content

feat(server): upload step pictures from the web editor - #584

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/step-pictures
Sep 30, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/step-pictures

Conversation

@LeMyst

@LeMyst LeMyst commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #562

Follow-up to #533, which let the web editor set a recipe's title picture. A step's picture still had to be copied into the recipe folder by hand. This PR adds it to the same dialog and the same endpoint.

API

/api/recipe_image/{*path} takes ?section=S&step=N. Both are one-based and section defaults to 1. Without step, the route behaves as before.

Title (unchanged) With ?step=
GET { path, image, source, sections }. New: sections lists each section that has steps, with each step's number, its text as plain words, and its picture URL. The editor's picker is built from this one request. { path, section, step, image, source }
PUT Recipe.jpg Recipe.S.N.jpg. The step's older files are removed in both conventions and every extension (Recipe.S.N.{jpeg,png,webp}, Recipe.G.{jpg,jpeg,png,webp}, where G is the step counted across all sections).
DELETE every Recipe.{jpg,jpeg,png,webp} every file of that step in both conventions. 404 if there was none.
  • The upload goes through the same title_image pipeline: 10 MB route limit, Exif orientation, 2048 px, always re-encoded, and the 415 heif message.
  • A step or section the saved recipe does not have returns 400. So do step=0, a non-number, and section without step. Nothing is written.
  • The title picture and other steps' pictures are never touched. An integration test puts decoy files next to the target to check this.
  • Section numbers count every section of the parsed recipe, the same way the recipe page does. The display lookup (Recipe.S.N, then Recipe.G) moved into builders::step_image, and both the page and the API use it, so the API reports what the page shows.
  • The activity line reads alice set the picture of step 1 in section 2 of recipe "Pizza.cook". It contains only numbers and the quoted file name.

UI

  • Editor → Picture: a new Picture for list above the preview: Title picture, then Step N: text… per step, grouped under the section name when the recipe has sections. Steps that already have a picture end with 📷. Preview, drop zone, replace and remove work as they do for the title. For a step, the heading reads Step picture and a note explains that pictures follow the step's position.
  • Opening the dialog saves the editor's text first, so the list numbers steps the way the recipe page will.
  • Recipe page: people who can edit recipes (viewer.can_edit_recipes(), hidden in the static export) get a camera icon-btn on each step. It links to /edit/…#picture=S.N, which opens the dialog on that step. I used a fragment rather than a query because the extensionless /edit/Recipe → /edit/Recipe.cook redirect drops the query, while browsers keep the fragment.
  • New strings are translated in all 8 locales. Tr::tp renders a message with {step} / {text} left in, and the script fills them in.

Screenshots

These use the seed's Easy Pancakes, whose step 3 picture is the older Easy Pancakes.3.jpg file. The dialog and the recipe page find it all the same.

Recipe page: a camera button on each step, for people who can edit recipes:

Recipe page steps, each with a camera button; step 3 shows its picture

Editor: the camera button on step 3 opens the Picture dialog on that step:

Picture dialog on step 3, with the Picture for list, the step's picture, and the note about step positions

Phone, dark mode:

Recipe page on a phone in dark mode, with camera buttons beside the steps Picture dialog on a phone in dark mode, set to step 2 with no picture yet

Choices open to review

  • Always Recipe.S.N.jpg, including for recipes with a single section. The recipe page looks for this name first and the iOS app writes it. Writing Recipe.N.jpg for single-section recipes would also work; switching is a one-line change in picture_files.
  • No renaming when steps move. As Upload step pictures from the web UI #562 notes, inserting or removing an earlier step shifts later pictures onto the wrong step. The dialog says so, and the docs do too. Offering to rename the files is left for a follow-up.
  • Menus don't get the picker: is_menu hides it, and menu pages don't show step pictures.

Tests

  • tests/recipe_image_api_test.rs: 7 new tests. They cover the stored name, the reply and the recipe page HTML; section defaulting to 1; cleanup of both conventions plus 5 untouched decoys; delete then 404; 7 invalid queries across GET/PUT/DELETE with nothing written; HEIC, an empty body and a 2.4 MB body on the step route; and the sections listing with pictures in both conventions.
  • tests/e2e/editor.spec.ts: 3 new Playwright tests: camera button → dialog on that step → upload (📷 marker, JPEG on disk, shown on the recipe page) → change → remove; the picker's grouped options; unsaved text saved before listing.
  • Tr::tp unit test (fr-FR).
  • Locally: cargo fmt, cargo clippy --all-targets (no warnings), cargo test (all pass), docs/api.md regenerated, full Playwright chromium project: 246 passed, 5 skipped.

🤖 Generated with Claude Code

@LeMyst
LeMyst marked this pull request as ready for review September 29, 2026 18:21
The editor's Picture dialog handled only the title picture (cooklang#533), so a
step's picture still had to be dropped into the recipe folder by hand.

`/api/recipe_image/{*path}` now takes `?section=S&step=N` (section
defaults to 1). PUT stores the upload as `Recipe.S.N.jpg` through the
same pipeline as the title picture (10 MB, Exif orientation, 2048 px,
re-encoded, HEIC explained) and removes the step's older files in both
conventions and every extension (`Recipe.S.N.png`, `Recipe.G.jpg`, ...)
so none can come back when the new one is removed. DELETE removes them
all. A step or section the saved recipe does not have is a 400. The
title picture and other steps are never touched. GET without a step
also lists every section's steps with their text and picture.

The lookup the recipe page uses for a step's picture moves to
`builders::step_image`, so the API reports what the page shows.

UI: a "Picture for" list in the dialog (Title / Section > Step N: text,
marked with a camera once a step has a picture). The dialog saves the
editor's text first, so steps are numbered as the page numbers them.
On the recipe page, editors get a camera button on each step that opens
the editor with that step picked (`#picture=S.N`, a fragment so it
survives the /edit redirect). Strings are translated for every locale.

Closes cooklang#562

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst
LeMyst merged commit 745b349 into cooklang:main Sep 30, 2026
5 checks passed
@shsw228 shsw228 mentioned this pull request Sep 30, 2026
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upload step pictures from the web UI

1 participant