feat: refactor whole bunch of stuff
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { fetchResource } from "@lib/marka.ts";
|
||||
import { fetchResource } from "@lib/marka/index.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(_, ctx) {
|
||||
|
||||
@@ -3,15 +3,15 @@ import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
||||
import { createStreamResponse, isValidUrl } from "@lib/helpers.ts";
|
||||
import * as openai from "@lib/openai.ts";
|
||||
import { createLogger } from "@lib/log/index.ts";
|
||||
import { Recipe } from "@lib/resource/recipes.ts";
|
||||
import recipeSchema from "@lib/recipeSchema.ts";
|
||||
import { fileExtension } from "https://deno.land/x/file_extension@v2.1.0/mod.ts";
|
||||
import { safeFileName } from "@lib/string.ts";
|
||||
import { parseJsonLdToRecipeSchema } from "./parseJsonLd.ts";
|
||||
import z from "zod";
|
||||
import { createResource } from "@lib/marka.ts";
|
||||
import { createResource } from "@lib/marka/index.ts";
|
||||
import { webScrape } from "@lib/webScraper.ts";
|
||||
import { Defuddle } from "defuddle/node";
|
||||
import { RecipeResource } from "@lib/marka/schema.ts";
|
||||
|
||||
const log = createLogger("api/article");
|
||||
|
||||
@@ -51,7 +51,7 @@ async function processCreateRecipeFromUrl(
|
||||
recipe = await openai.extractRecipe(result.content);
|
||||
}
|
||||
|
||||
const id = safeFileName(recipe?.title || "");
|
||||
const id = safeFileName(recipe?.name || "");
|
||||
|
||||
if (!recipe) {
|
||||
streamResponse.enqueue("failed to parse recipe");
|
||||
@@ -59,23 +59,13 @@ async function processCreateRecipeFromUrl(
|
||||
return;
|
||||
}
|
||||
|
||||
const newRecipe: Recipe = {
|
||||
const newRecipe: RecipeResource["content"] = {
|
||||
...recipe,
|
||||
_type: "Recipe",
|
||||
name: recipe?.title,
|
||||
description: recipe?.description,
|
||||
recipeIngredient: recipe?.ingredients || [],
|
||||
recipeInstructions: recipe?.instructions || [],
|
||||
keywords: recipe.tags || [],
|
||||
image: recipe?.image,
|
||||
totalTime: recipe?.totalTime
|
||||
? `${recipe?.totalTime?.toString()} minutes`
|
||||
: undefined,
|
||||
url: fetchUrl,
|
||||
author: {
|
||||
_type: "Person",
|
||||
name: recipe?.author,
|
||||
},
|
||||
recipeYield: recipe?.servings,
|
||||
};
|
||||
|
||||
if (newRecipe?.image && newRecipe.image.length > 5) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { json } from "@lib/helpers.ts";
|
||||
import { fetchResource } from "@lib/marka.ts";
|
||||
import { fetchResource } from "@lib/marka/index.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET() {
|
||||
|
||||
Reference in New Issue
Block a user