Repository navigation
Description
Summary
#533 (closing #520) let the web editor upload, replace and remove a recipe's title picture (Recipe.jpg). Step pictures were left out of scope. You can still only add them by putting a Recipe.N.jpg / Recipe.S.N.jpg file in the recipe folder yourself. The web server already shows these files, but it can't create them.
That leaves the same gap as #520: someone running cook server on another machine has no way to attach a photo to a step without a separate file manager.
What already exists
- Display:
src/web/builders.rsresolves a step's picture throughcooklang-find'sstep_images(). It supports both naming conventions from image title scheme discrepancy between cli server and ios app #374. It looks forRecipe.S.N.extfirst (section S, step N within that section, as the iOS app writes it). If that isn't there, it falls back toRecipe.N.ext(step N counted across all sections). - Upload pipeline:
src/server/title_image.rsaccepts JPEG/PNG/WebP up to 10 MB. It turns the picture upright from its Exif orientation, scales it to at most 2048 px, drops the Exif data and saves a re-encoded JPEG. It refuses HEIC/AVIF with a helpful415. The editor already shrinks photos before sending them. All of this can be reused unchanged for step pictures. - Route:
/api/recipe_image/{*path}(GET/PUT/DELETE) with its own 10 MB body limit. PUT deliberately leaves step pictures alone.
Proposal
API
Extend the existing route with query parameters instead of adding a new path segment. The catch-all has to stay last, so a path segment would clash with a recipe folder of the same name (see #533):
GET /api/recipe_image/{*path}?section=S&step=N
PUT /api/recipe_image/{*path}?section=S&step=N (body = raw bytes, as today)
DELETE /api/recipe_image/{*path}?section=S&step=N
- Without
step, the route keeps its current behaviour (title picture). stepis 1-based within its section.sectionis 1-based and defaults to 1.- Return
400when the step or section doesn't exist in the parsed recipe. GETwithoutstepcould also list every step picture, so the UI can draw its state in one request.
File naming
- Save as
Recipe.S.N.jpg, the name the display code looks for first and the one the iOS app uses. The other option is to saveRecipe.N.jpgwhen the recipe has a single section, which matches the plain spec convention. That choice is up to the maintainers (see the open questions below). - On replace or delete, remove that step's older files in both conventions and in every extension (
.jpg/.jpeg/.png/.webp). Otherwise an oldRecipe.N.pngcan come back when the new file is deleted, or be picked instead of the new one. - Always save
.jpg, for the same reasons as the title picture (cooklang-findchecks it first, and cook.md sync carries it). - Never touch the title picture or other steps' pictures.
UI
Some ways to expose it:
- Add a step picker to the editor's existing Picture dialog (Title / Section › Step), reusing its preview, drop zone, replace and remove flow.
- Add a small camera button on each step of the recipe page that opens the same dialog, already set to that step.
Option 1 is the smallest change. Option 2 is easier to find, since you see the step you're adding the picture to.
Open questions / known limitations
- Step numbers shift when steps are edited. Pictures are tied to a position, not to the step's content. Inserting or removing a step earlier in a section moves every later picture onto the wrong step. That's already true for pictures added by hand. Should the editor warn about it, or offer to rename the files when the step count changes? That could reasonably be a follow-up.
- Should uploads always use
Recipe.S.N.jpg, orRecipe.N.jpgfor recipes with a single section? - Support multiple step-specific images in recipes #173 (multiple pictures per step) is a separate request. This issue is about one picture per step.
Acceptance criteria
- A step picture can be uploaded, replaced and removed from the web UI, and the recipe page (and cooking mode) show it.
- It goes through the same processing as title pictures: size limit, Exif orientation, re-encoding, HEIC message.
- Older files for the same step, in either convention and any extension, are cleaned up. The title picture and other steps are untouched.
- Integration tests in the style of
tests/recipe_image_api_test.rs(spawned throughcommon::with_isolated_config) and a Playwright test for the UI flow. docs/api.md,api_docs.rsanddocs/server.mdupdated. New strings translated for every locale.
Activity
feat(server): upload step pictures from the web editor
feat(server): upload step pictures from the web editor (cooklang#584)