fix: make recipe crawling work

This commit is contained in:
Max Richter
2025-11-12 15:41:30 +01:00
parent 92126882b6
commit 7ad08daf80
19 changed files with 44 additions and 55 deletions

View File

@@ -37,17 +37,17 @@ async function processCreateRecipeFromUrl(
let recipe: z.infer<typeof recipeSchema> | undefined = undefined;
if (jsonLds.length > 0) {
for (const jsonLd of jsonLds) {
recipe = parseJsonLdToRecipeSchema(jsonLd.textContent || "");
if (recipe) break;
if (jsonLd.textContent) {
recipe = parseJsonLdToRecipeSchema(jsonLd.textContent);
if (recipe) break;
}
}
}
if (!recipe) {
const res = await openai.extractRecipe(result.markdown);
if (!res || "errorMessages" in res) {
const errorMessage = res?.errorMessages?.[0] ||
"could not extract recipe";
streamResponse.error(`failed to extract recipe: ${errorMessage}`);
if (!res || res === "none") {
streamResponse.error(`failed to extract recipe: ${res}`);
return;
}
recipe = res;
@@ -72,9 +72,7 @@ async function processCreateRecipeFromUrl(
if (newRecipe?.image && newRecipe.image.length > 5) {
const extension = fileExtension(newRecipe.image);
const finalPath = `resources/recipes/images/${
safeFileName(id)
}_cover.${extension}`;
const finalPath = `recipes/images/${safeFileName(id)}_cover.${extension}`;
streamResponse.info("downloading image");
try {
streamResponse.info("downloading image");
@@ -82,7 +80,7 @@ async function processCreateRecipeFromUrl(
streamResponse.info("saving image");
const buffer = await res.arrayBuffer();
await createResource(finalPath, buffer);
newRecipe.image = finalPath;
newRecipe.image = `resources/${finalPath}`;
} catch (err) {
console.log("Failed to save image", err);
}