fix: step.replace is not a function when Gemini returns steps as objects
- PHP generateRecipeStream: normalize recipe.steps to plain strings after
parsing Gemini JSON (handles [{text:'...'}, ...] objects gracefully)
- JS: add _stepStr(s) helper near cooking mode — safely extracts text from
a step regardless of type (string or object {text/description/step key})
and strips leading 'Passo N:' prefix in one place
- JS: replace all 7 manual step.replace(/^Passo.../) calls with _stepStr()
across renderRecipe, renderCookingStep, startCookingMode, replayCookingTTS,
toggleCookingTTS, navigateCookingStep — no more crash if Gemini schema drifts
This commit is contained in:
+8
-1
@@ -5571,7 +5571,14 @@ PROMPT;
|
||||
return;
|
||||
}
|
||||
|
||||
// ── Post-process: fuzzy-match ingredients → inventory (same as generateRecipe) ──
|
||||
// Normalize steps: Gemini sometimes returns [{"text":"..."}, ...] instead of ["...", ...]
|
||||
if (!empty($recipe['steps']) && is_array($recipe['steps'])) {
|
||||
$recipe['steps'] = array_values(array_map(function($s) {
|
||||
if (is_string($s)) return $s;
|
||||
if (is_array($s)) return $s['text'] ?? $s['description'] ?? $s['step'] ?? json_encode($s, JSON_UNESCAPED_UNICODE);
|
||||
return (string)$s;
|
||||
}, $recipe['steps']));
|
||||
}
|
||||
if (!empty($recipe['ingredients'])) {
|
||||
$itemsLookup = [];
|
||||
foreach ($items as $item) {
|
||||
|
||||
Reference in New Issue
Block a user