import type { DatabaseSync } from "node:sqlite"; import { callLLM } from "./utils/llm.ts"; import { decodeHtmlChars } from "./utils/html.ts"; export const getRecipesList = (db: DatabaseSync, ids?: number[]): Recipe[] => { if (ids) return db .prepare( `SELECT * FROM recipes WHERE id IN (${ids .map(() => "?") .join(",")}) ORDER BY name` ) .all(...ids); else return db.prepare("SELECT * FROM recipes ORDER BY name").all(); }; export const storeRecipe = async (db: DatabaseSync, recipeId: string) => { let recipeUrl = ""; if (!recipeId) throw new Error("Please provide a recipe ID"); else if (recipeId.startsWith("https://")) recipeUrl = recipeId; else recipeUrl = `https://cookidoo.fr/recipes/recipe/fr-FR/${recipeId}`; const recipePage = await fetch(recipeUrl).then((res) => res.text()); const jsonLdTag = recipePage.match( /