diff --git a/scripts/import-duplicates.test.js b/scripts/import-duplicates.test.js index 0366cdc..dd22644 100644 --- a/scripts/import-duplicates.test.js +++ b/scripts/import-duplicates.test.js @@ -24,7 +24,7 @@ test('server: every duplicate answer names the recipe it matched', () => { test('server: a Paprika archive never counts a skipped duplicate as imported', () => { assert.doesNotMatch(routes, /const row = _saveImportedRecipe\(u, r,[^\n]*\n\s*created\.push\(row\);/); - assert.match(routes, /if \(row\) created\.push\(row\);\s*else skipped\.push/); + assert.match(routes, /if \(row\) \{ created\.push\(row\); createdIds\.add\(row\.id\); \}\s*else skipped\.push/); }); test('local mode answers duplicates the same way as the server', () => { diff --git a/scripts/paprika-import.test.js b/scripts/paprika-import.test.js new file mode 100644 index 0000000..a71bbd1 --- /dev/null +++ b/scripts/paprika-import.test.js @@ -0,0 +1,131 @@ +/** + * Paprika exports embed each photo inside the .paprikarecipe JSON: + * `photo_data` (or `photos[0].data` on some versions) holds the base64 + * bytes, `photo` is only the embedded filename, and `photo_url` / + * `image_url` point at the source site. The importer built its data URL + * out of the *filename*, so the magic-byte check downstream rejected + * every picture and Paprika imports arrived imageless. + * + * The same archive can also hold several user-made copies of a recipe + * (same name or same source URL, distinct entries in the app). Dedup + * must compare against the library the user had *before* the import, + * not against rows written earlier in the same batch — otherwise three + * copies import as one and the rest are reported as its "duplicates". + * + * Fixtures are trimmed from a real Paprika 3 export (2026-10). + */ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import { gzipSync } from 'node:zlib'; +import JSZip from 'jszip'; +import { loadRecipeZip, scanLoadedZip, importPaprikaArchive } from '../server/lib/recipe-importers.js'; + +const read = (p) => readFileSync(new URL(`../${p}`, import.meta.url), 'utf8'); + +// JPEG header bytes only — enough to be a plausible photo. The importer +// treats photo_data as opaque base64; the magic-byte validation happens +// later, when the data URL is localized at save time. +const PHOTO_B64 = Buffer.from([0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00]).toString('base64'); + +const paprikaRecipe = (over = {}) => ({ + name: 'Lentil Soup', + ingredients: '1 cup lentils\n2 cups water', + directions: 'Boil.\n\nSimmer.', + photo: 'lentil-soup.jpg', // a filename, not bytes + photo_data: PHOTO_B64, + ...over, +}); + +async function paprikaArchive(entries) { + const z = new JSZip(); + for (const [name, recipe] of entries) { + z.file(name, gzipSync(Buffer.from(JSON.stringify(recipe)))); + } + return z.generateAsync({ type: 'nodebuffer' }); +} + +test('photo_data becomes the image, not the photo filename', async () => { + const out = await scanLoadedZip(await loadRecipeZip(await paprikaArchive([['a.paprikarecipe', paprikaRecipe()]]))); + assert.equal(out.length, 1); + assert.equal(out[0].source, 'paprika'); + assert.equal(out[0].recipe.imgUrl, `data:image/jpeg;base64,${PHOTO_B64}`); +}); + +test('the photos[] array is used when photo_data is absent', async () => { + const withPhotos = paprikaRecipe({ photo_data: null, photos: [{ filename: 'x.jpg', hash: '', data: PHOTO_B64 }] }); + const out = await scanLoadedZip(await loadRecipeZip(await paprikaArchive([['a.paprikarecipe', withPhotos]]))); + assert.equal(out[0].recipe.imgUrl, `data:image/jpeg;base64,${PHOTO_B64}`); +}); + +test('a recipe without embedded bytes falls back to the source-site URL', async () => { + const remote = paprikaRecipe({ photo_data: null, photos: [], image_url: 'https://example.com/soup.jpg' }); + const out = await scanLoadedZip(await loadRecipeZip(await paprikaArchive([['a.paprikarecipe', remote]]))); + assert.equal(out[0].recipe.imgUrl, 'https://example.com/soup.jpg'); +}); + +test('a recipe with no picture imports with a null image', async () => { + const bare = paprikaRecipe({ photo_data: null, photos: [], image_url: null }); + const out = await scanLoadedZip(await loadRecipeZip(await paprikaArchive([['a.paprikarecipe', bare]]))); + assert.equal(out[0].recipe.imgUrl, null); +}); + +test('importPaprikaArchive (the /import path) reads the same fields', async () => { + const recipes = await importPaprikaArchive(await paprikaArchive([ + ['a.paprikarecipe', paprikaRecipe()], + ['b.paprikarecipe', paprikaRecipe({ name: 'Other Soup' })], + ])); + assert.equal(recipes.length, 2); + assert.ok(recipes.every(r => r.imgUrl === `data:image/jpeg;base64,${PHOTO_B64}`)); +}); + +test('a Paprika rating survives import (0 means unrated)', async () => { + const out = await scanLoadedZip(await loadRecipeZip(await paprikaArchive([ + ['a.paprikarecipe', paprikaRecipe({ rating: 4 })], + ['b.paprikarecipe', paprikaRecipe({ name: 'Unrated', rating: 0 })], + ]))); + const byName = Object.fromEntries(out.map(o => [o.recipe.name, o.recipe])); + assert.equal(byName['Lentil Soup'].rating, 4); + assert.equal(byName['Unrated'].rating, null); +}); + +test("Paprika's nutritional_info rides along in notes instead of being dropped", async () => { + const out = await scanLoadedZip(await loadRecipeZip(await paprikaArchive([ + ['a.paprikarecipe', paprikaRecipe({ notes: 'Family favourite.', nutritional_info: '340 kcal per serving' })], + ['b.paprikarecipe', paprikaRecipe({ name: 'Bare', notes: null, nutritional_info: null })], + ]))); + const byName = Object.fromEntries(out.map(o => [o.recipe.name, o.recipe])); + assert.equal(byName['Lentil Soup'].notes, 'Family favourite.\n\nNutrition (from Paprika):\n340 kcal per serving'); + assert.equal(byName['Bare'].notes, null); +}); + +test('the client-side importer copy builds the same data URL', () => { + const client = read('src/lib/recipe-importers-client.js'); + assert.match(client, /function _paprikaImgUrl\(r\)/); + assert.doesNotMatch(client, /data:image\/jpeg;base64,\$\{r\.photo\}/, 'the filename is never used as image bytes'); +}); + +test('server: batch imports dedup against the library, not against the batch', () => { + const routes = read('server/routes/recipes.js'); + assert.match(routes, /function _findImportDuplicate\(u, parsed, excludeIds\)/); + assert.match(routes, /id NOT IN \(\$\{excl\.map/); + assert.match(routes, /_saveImportedRecipe\(u, recipe, \{ addToPantry, applyTags, importCategories, dedup, creatorUsername, excludeIds: createdIds \}\)/); + assert.match(routes, /_saveImportedRecipe\(u, r, \{ addToPantry, applyTags, importCategories, creatorUsername, excludeIds: createdIds \}\)/); + assert.equal((routes.match(/createdIds\.add\(row\.id\)/g) || []).length, 2, 'both server batch paths record what they wrote'); +}); + +test('local mode: batch imports dedup against the library, not against the batch', () => { + const native = read('src/lib/api-native.js'); + assert.match(native, /function _findImportDuplicateLocal\(r, excludeIds\)/); + assert.match(native, /id NOT IN \(\$\{excl\.map/); + assert.match(native, /_saveImportedRecipeLocal\(this, r, \{ addToPantry, applyTags, excludeIds: createdIds \}\)/); + assert.match(native, /_saveImportedRecipeLocal\(this, entry\.recipe, \{ addToPantry, applyTags, dedup, excludeIds: createdIds \}\)/); + assert.equal((native.match(/createdIds\.add\(saved\.id\)/g) || []).length, 2, 'both local batch paths record what they wrote'); +}); + +test('local mode: an embedded data: photo becomes a file before it reaches the table', () => { + const native = read('src/lib/api-native.js'); + assert.match(native, /async function _localizeImportedImage\(api, url\)/); + assert.match(native, /api\.uploadImage\(new File\(\[bytes\]/); + assert.match(native, /await _importedPayloadWithImage\(api, r\)/); +}); diff --git a/server/lib/recipe-importers.js b/server/lib/recipe-importers.js index a0ecadf..77b0f29 100644 --- a/server/lib/recipe-importers.js +++ b/server/lib/recipe-importers.js @@ -816,18 +816,20 @@ function _importPaprika(r) { return { name: r.name || 'Imported recipe', description: r.description || null, - imgUrl: r.photo_url || (r.photo ? `data:image/jpeg;base64,${r.photo}` : null), + imgUrl: _paprikaImgUrl(r), servings: _parseServings(r.servings), yield_text: r.servings || null, prep_minutes: _parseMinutes(r.prep_time), cook_minutes: _parseMinutes(r.cook_time), + // Paprika's 0-5 stars; 0 means unrated, which is null here. + rating: r.rating > 0 ? r.rating : null, ingredients: items.length ? [{ name: '', items }] : [], steps, tags: paprikaCats.slice(1, 13), tools: [], nutrition: {}, source_url: r.source_url || r.source || null, - notes: r.notes || null, + notes: _paprikaNotes(r), category_name: categoryName, // Paprika stores the recipe creation timestamp in `created` (or // older `dateAdded` for legacy exports). Pull this so the imported @@ -858,6 +860,26 @@ export function parseImportedCreatedAt(raw) { } // ── Helpers ───────────────────────────────────────────────────────────────── +// Paprika's photo fields: `photo` is only the embedded filename, the +// bytes live in `photo_data` (base64 JPEG) or `photos[0].data`; +// `photo_url` / `image_url` are remote URLs on the source site. Prefer +// the embedded bytes — _saveImportedRecipe localizes data URLs into +// real files under /uploads/ — and fall back to a remote URL only when +// nothing was embedded. +function _paprikaImgUrl(r) { + const b64 = r.photo_data || r.photos?.[0]?.data; + if (b64) return `data:image/jpeg;base64,${b64}`; + return r.photo_url || r.image_url || null; +} +// Paprika's `nutritional_info` is a free-text blob with no structured +// equivalent here; append it to notes so it survives the import +// instead of being dropped. +function _paprikaNotes(r) { + const nutrition = String(r.nutritional_info || '').trim(); + if (!nutrition) return r.notes || null; + const label = `Nutrition (from Paprika):\n${nutrition}`; + return r.notes ? `${r.notes}\n\n${label}` : label; +} function _parseServings(s) { if (s == null) return null; const m = String(s).match(/(\d+)/); diff --git a/server/routes/recipes.js b/server/routes/recipes.js index 5532525..4cf6650 100644 --- a/server/routes/recipes.js +++ b/server/routes/recipes.js @@ -1678,17 +1678,23 @@ function _aiConfigForUser(u, req) { // then source_url. Returns { id } or null. _saveImportedRecipe skips on // a match (dedup 'skip'), and the routes report the match's id so the // client can open it instead of a recipe that was never written. -function _findImportDuplicate(u, parsed) { +// `excludeIds` (a Set of ids written earlier in the same batch) are +// ignored, so an archive that itself contains several near-copies — +// e.g. Paprika user-made copies sharing a name or source URL — doesn't +// swallow its own entries. +function _findImportDuplicate(u, parsed, excludeIds) { + const excl = excludeIds ? [...excludeIds] : []; + const notIn = excl.length ? ` AND id NOT IN (${excl.map(() => '?').join(',')})` : ''; const lower = String(parsed?.name || '').toLowerCase().trim(); let existing = lower ? db.prepare( `SELECT id FROM recipes - WHERE ${_whereUser(u)} AND deleted_at IS NULL AND lower(name) = ? LIMIT 1` - ).get(...[..._userArgs(u), lower]) : null; + WHERE ${_whereUser(u)} AND deleted_at IS NULL AND lower(name) = ?${notIn} LIMIT 1` + ).get(...[..._userArgs(u), lower, ...excl]) : null; if (!existing && parsed?.source_url) { existing = db.prepare( `SELECT id FROM recipes - WHERE ${_whereUser(u)} AND deleted_at IS NULL AND source_url = ? LIMIT 1` - ).get(...[..._userArgs(u), parsed.source_url]); + WHERE ${_whereUser(u)} AND deleted_at IS NULL AND source_url = ?${notIn} LIMIT 1` + ).get(...[..._userArgs(u), parsed.source_url, ...excl]); } return existing || null; } @@ -1710,9 +1716,12 @@ function _saveImportedRecipe(u, parsed, opts = {}) { // shape; 'force' creates a duplicate (pre-dedup behaviour). Match // is by case-insensitive name first, then by source_url. dedup = 'skip', + // Recipe ids written earlier in the same import batch — near-copies + // inside one archive are not duplicates of each other. + excludeIds = null, } = opts; if (dedup !== 'force' && parsed?.name) { - const existing = _findImportDuplicate(u, parsed); + const existing = _findImportDuplicate(u, parsed, excludeIds); if (existing) { if (dedup === 'skip') return null; // dedup === 'replace' falls through and gets re-inserted; the @@ -2072,6 +2081,12 @@ router.post('/import-zip/commit', _zipImportUpload.single('file'), wrap(async (r const failed = []; const skippedDup = []; let timelineImported = 0; + // Rows written earlier in this same batch. Archives legitimately hold + // several near-copies (e.g. Paprika keeps user-made copies with the + // same name or source URL as distinct recipes), so dedup must compare + // against what the user had *before* the import, not against entries + // from this batch. + const createdIds = new Set(); for (let i = 0; i < scanned.length; i++) { if (wantedIdx && !wantedIdx.has(i)) continue; @@ -2090,16 +2105,17 @@ router.post('/import-zip/commit', _zipImportUpload.single('file'), wrap(async (r } else if (!importImages) { recipe.imgUrl = null; } - const row = _saveImportedRecipe(u, recipe, { addToPantry, applyTags, importCategories, dedup, creatorUsername }); + const row = _saveImportedRecipe(u, recipe, { addToPantry, applyTags, importCategories, dedup, creatorUsername, excludeIds: createdIds }); // Resolve a target recipe_id even when the row was dedup-skipped // so timeline events still land on the existing recipe. let targetRecipeId = row?.id || null; if (!row) { - const existing = _findImportDuplicate(u, recipe); + const existing = _findImportDuplicate(u, recipe, createdIds); targetRecipeId = existing?.id || null; skippedDup.push({ idx: i, name: recipe?.name || `(item ${i})`, existing_id: targetRecipeId }); } else { created.push(row); + createdIds.add(row.id); } // Mealie timeline events ride along with each recipe entry from @@ -2221,12 +2237,14 @@ router.post('/import', _importUpload.single('file'), wrap(async (req, res) => { catch (e) { return res.status(400).json({ error: e.message }); } const created = []; const skipped = []; + // Same-batch exemption — see the createdIds comment in /import-zip/commit. + const createdIds = new Set(); for (const r of recipes) { try { - const row = _saveImportedRecipe(u, r, { addToPantry, applyTags, importCategories, creatorUsername }); + const row = _saveImportedRecipe(u, r, { addToPantry, applyTags, importCategories, creatorUsername, excludeIds: createdIds }); // null = a duplicate that was skipped, not a recipe written. - if (row) created.push(row); - else skipped.push({ name: r?.name || '', existing_id: _findImportDuplicate(u, r)?.id || null }); + if (row) { created.push(row); createdIds.add(row.id); } + else skipped.push({ name: r?.name || '', existing_id: _findImportDuplicate(u, r, createdIds)?.id || null }); } catch (e) { // Continue on per-recipe failure — most archives have many. } diff --git a/src/lib/api-native.js b/src/lib/api-native.js index 604c0ff..e413b36 100644 --- a/src/lib/api-native.js +++ b/src/lib/api-native.js @@ -660,10 +660,14 @@ export const CtApiNative = { const recipes = await importPaprikaArchive(blob); const created = []; const skipped = []; + // Ids written earlier in this same batch — an archive that + // itself holds several near-copies (Paprika user-made copies + // share a name or source URL) must not dedup against itself. + const createdIds = new Set(); for (const r of recipes) { - const saved = await _saveImportedRecipeLocal(this, r, { addToPantry, applyTags }); - if (saved) created.push(saved); - else if (r?.name) skipped.push({ name: r.name, existing_id: (await _findImportDuplicateLocal(r))?.id || null }); + const saved = await _saveImportedRecipeLocal(this, r, { addToPantry, applyTags, excludeIds: createdIds }); + if (saved) { created.push(saved); createdIds.add(saved.id); } + else if (r?.name) skipped.push({ name: r.name, existing_id: (await _findImportDuplicateLocal(r, createdIds))?.id || null }); } return { recipes: created, count: created.length, skipped }; } catch (e) { @@ -732,6 +736,10 @@ export const CtApiNative = { const failed = []; const skipped = []; let timelineImported = 0; + // Rows written earlier in this same batch — near-copies inside one + // archive (Paprika keeps user-made copies with the same name or + // source URL as distinct recipes) are not duplicates of each other. + const createdIds = new Set(); for (const entry of picked) { try { @@ -743,21 +751,26 @@ export const CtApiNative = { const uploaded = await this.uploadImage(new File([blob], `${fileName}.${img.ext}`, { type: blob.type })); entry.recipe.imgUrl = uploaded; } + } else if (!importImages) { + // Same contract as the server's commit: "no images" drops the + // picture the scan found, embedded or remote alike. + entry.recipe.imgUrl = null; } // Save the recipe (or skip + look up the existing one). Either // way we end up with a target recipe_id to attach timeline // events to — re-imports should land cook history on the // existing recipe instead of being dropped alongside. - const saved = await _saveImportedRecipeLocal(this, entry.recipe, { addToPantry, applyTags, dedup }); + const saved = await _saveImportedRecipeLocal(this, entry.recipe, { addToPantry, applyTags, dedup, excludeIds: createdIds }); let targetRecipeId = saved?.id; if (!saved) { // Re-resolve the existing recipe so timeline events still // land on it, and so the summary can link to it. - const existing = await _findImportDuplicateLocal(entry.recipe); + const existing = await _findImportDuplicateLocal(entry.recipe, createdIds); targetRecipeId = existing?.id || null; skipped.push({ name: entry.recipe?.name || '?', existing_id: targetRecipeId }); } else { imported.push(saved); + createdIds.add(saved.id); } if (importTimeline && targetRecipeId && Array.isArray(entry.timelineEvents) && entry.timelineEvents.length) { @@ -1883,27 +1896,56 @@ export const NtApiNative = CtApiNative; * dedup 'skip' (default) | 'force' | 'replace' * @returns {object|null} the saved recipe row, or null when skipped */ -async function _findImportDuplicateLocal(r) { +async function _findImportDuplicateLocal(r, excludeIds) { // The recipe an import would duplicate: case-insensitive name first, - // then source_url. Mirrors the server's _findImportDuplicate. + // then source_url. Mirrors the server's _findImportDuplicate — + // including its excludeIds: ids written earlier in the same import + // batch don't count, so an archive containing several near-copies + // (Paprika user-made copies share a name or source URL) doesn't + // swallow its own entries. + const excl = excludeIds ? [...excludeIds] : []; + const notIn = excl.length ? ` AND id NOT IN (${excl.map(() => '?').join(',')})` : ''; const lower = String(r?.name || '').toLowerCase().trim(); let existing = lower ? (await _query( `SELECT id, name, source_url FROM recipes - WHERE user_id = ? AND deleted_at IS NULL AND LOWER(name) = ? LIMIT 1`, - [LOCAL_USER_ID, lower] + WHERE user_id = ? AND deleted_at IS NULL AND LOWER(name) = ?${notIn} LIMIT 1`, + [LOCAL_USER_ID, lower, ...excl] ))[0] : null; if (!existing && r?.source_url) { existing = (await _query( `SELECT id, name, source_url FROM recipes - WHERE user_id = ? AND deleted_at IS NULL AND source_url = ? LIMIT 1`, - [LOCAL_USER_ID, r.source_url] + WHERE user_id = ? AND deleted_at IS NULL AND source_url = ?${notIn} LIMIT 1`, + [LOCAL_USER_ID, r.source_url, ...excl] ))[0]; } return existing || null; } +// A data: image the importer embedded (Paprika ships photos inside the +// recipe JSON) becomes a real file — the same path every other +// local-mode picture takes — instead of a multi-megabyte base64 string +// in the recipes table. +async function _localizeImportedImage(api, url) { + if (typeof url !== 'string' || !url.startsWith('data:image/')) return url; + try { + const comma = url.indexOf(','); + const mime = url.slice(5, comma).split(';')[0].toLowerCase() || 'image/jpeg'; + const ext = mime === 'image/jpeg' ? 'jpg' : mime.replace('image/', ''); + const bytes = Uint8Array.from(atob(url.slice(comma + 1)), c => c.charCodeAt(0)); + return await api.uploadImage(new File([bytes], `imported.${ext}`, { type: mime })); + } catch { + return null; + } +} + +// The importer's normalised shape as a create/update payload, with any +// embedded photo turned into a stored file first. +async function _importedPayloadWithImage(api, r) { + return _importedToRecipePayload({ ...r, imgUrl: await _localizeImportedImage(api, r.imgUrl) }); +} + async function _saveImportedRecipeLocal(api, r, opts = {}) { - const { addToPantry = true, dedup = 'skip' } = opts; + const { addToPantry = true, dedup = 'skip', excludeIds = null } = opts; if (!r?.name) return null; // Dedup pass — match by case-insensitive name first, then by @@ -1911,16 +1953,16 @@ async function _saveImportedRecipeLocal(api, r, opts = {}) { // existing recipe alone. 'replace' updates the existing row. // 'force' creates a duplicate (the pre-dedup behaviour). if (dedup !== 'force') { - const existing = await _findImportDuplicateLocal(r); + const existing = await _findImportDuplicateLocal(r, excludeIds); if (existing) { if (dedup === 'skip') return null; if (dedup === 'replace') { - return api.updateRecipe(existing.id, _importedToRecipePayload(r)); + return api.updateRecipe(existing.id, await _importedPayloadWithImage(api, r)); } } } - const saved = await api.createRecipe(_importedToRecipePayload(r)); + const saved = await api.createRecipe(await _importedPayloadWithImage(api, r)); // Backdate to the source app's original creation timestamp if the // importer captured one. backdateRecipe only pulls the date back, // never forward, so this is safe to call unconditionally. diff --git a/src/lib/recipe-importers-client.js b/src/lib/recipe-importers-client.js index ef26d2a..b6ee4a2 100644 --- a/src/lib/recipe-importers-client.js +++ b/src/lib/recipe-importers-client.js @@ -471,20 +471,22 @@ function _importPaprika(r) { return { name: r.name || 'Imported recipe', description: r.description || null, - imgUrl: r.photo_url || (r.photo ? `data:image/jpeg;base64,${r.photo}` : null), + imgUrl: _paprikaImgUrl(r), servings: _parseServings(r.servings), yield_text: r.servings || null, prep_minutes: _parseMinutes(r.prep_time), cook_minutes: _parseMinutes(r.cook_time), rest_minutes: _parseMinutes(r.rest_time), total_minutes: _parseMinutes(r.total_time), + // Paprika's 0-5 stars; 0 means unrated, which is null here. + rating: r.rating > 0 ? r.rating : null, ingredients: items.length ? [{ name: '', items }] : [], steps, tags: paprikaCats.slice(1, 13), tools: [], nutrition: {}, source_url: r.source_url || r.source || null, - notes: r.notes || null, + notes: _paprikaNotes(r), category_name: categoryName, // Paprika stores recipe creation timestamp in `created`; older // exports used `dateAdded`. Pulling this lets the save flow @@ -681,6 +683,25 @@ function _parseImportedCreatedAt(raw) { return d.toISOString().replace('T', ' ').slice(0, 19); } +// Paprika's photo fields: `photo` is only the embedded filename, the +// bytes live in `photo_data` (base64 JPEG) or `photos[0].data`; +// `photo_url` / `image_url` are remote URLs on the source site. Prefer +// the embedded bytes — the save flow turns data URLs into real files — +// and fall back to a remote URL only when nothing was embedded. +function _paprikaImgUrl(r) { + const b64 = r.photo_data || r.photos?.[0]?.data; + if (b64) return `data:image/jpeg;base64,${b64}`; + return r.photo_url || r.image_url || null; +} +// Paprika's `nutritional_info` is a free-text blob with no structured +// equivalent here; append it to notes so it survives the import +// instead of being dropped. +function _paprikaNotes(r) { + const nutrition = String(r.nutritional_info || '').trim(); + if (!nutrition) return r.notes || null; + const label = `Nutrition (from Paprika):\n${nutrition}`; + return r.notes ? `${r.notes}\n\n${label}` : label; +} function _parseServings(s) { if (s == null) return null; const m = String(s).match(/(\d+)/);