fix(import): replace external image URL with local path after download#3140
Open
bigsearcher wants to merge 1 commit into
Open
fix(import): replace external image URL with local path after download#3140bigsearcher wants to merge 1 commit into
bigsearcher wants to merge 1 commit into
Conversation
When importing a recipe from a URL, the image is fetched and saved locally as full.jpg, but the 'image' field in recipe.json kept the original URL. Two consequences: 1. The source URL leaks back to the user on edit (visible in the image field), even though the frontend serves the local copy via the cookbook.recipe.image API route. 2. Re-saving the recipe without changing the image still satisfies the change check on line 283 only because the strings match — but if anything mutates the field (e.g. a filter or user edit that does not intend to re-fetch), the importer would re-download from the external host on every save. After setImageData() succeeds, rewrite the field to the user-relative path of the local file (/<recipe_folder>/full.jpg) and re-write recipe.json. The path is resolvable by the existing local-path branch on line 297 should it ever be needed.
Contributor
Test Results 9 files 444 suites 1m 36s ⏱️ Results for commit 06d9e6a. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a recipe is imported from a URL,
RecipeService::addRecipe()downloads the image and writes it to the recipe folder asfull.jpg(viaImageService::setImageData()), butrecipe.jsonkeeps the original external URL in itsimagefield. This patch rewrites that field to the user-relative path of the local file after the download succeeds, so:recipe.jsonself-consistently reflects what is actually on disk.Background
The frontend (
RecipeCard.vue,RecipeImages.vue) renders images viarecipe.imageUrl, which the backend (RecipeImplementation.php) generates as a link to thecookbook.recipe.imageroute — i.e. the local file. So end-user browsing already does not hit the external host. This patch only fixes the persistent state of the JSON field.I have ~30k imported recipes; on roughly half of them,
recipe.json#imagewas still an external URL pointing to all sorts of food blogs. Cleaning them up after the fact was a one-shot script, but new imports keep reintroducing the divergence — hence this fix at the source.Test plan
imagefield). Confirmfull.jpgexists in the recipe folder./Recipes/<Recipe Name>/full.jpg, not the original URL.imageare untouched (the new code runs only when image data is freshly fetched).