Add Product
{text}
}Add {textVal}
{body}
) }) FormMessage.displayName = "FormMessage" export { useFormField, Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField, } ================================================ FILE: src/components/ui/input.tsx ================================================ import * as React from "react" import { cn } from "~/lib/utils" export interface InputProps extends React.InputHTMLAttributes{user.name}
} {user.username && ({user.username}
)}Users
${section}
`).join("") } export const StepsToStringSchema = z .union([z.array(StepSchema), z.string()]) .transform((steps) => { if (typeof steps === "string") return beautifyInstructions(steps) return beautifyInstructions(steps.map((step) => step.text).join("\n\n")) }) const baseUrlSchema = z.union([z.string(), z.object({ url: z.string() })]) export const RecipeImageUrlSchema = z .union([baseUrlSchema, baseUrlSchema.array()]) .transform((input): string | undefined => { const res = Array.isArray(input) ? input[0] : input if (!res || typeof res === "string") return res return res.url }) export const JsonLdRecipeSchema = z.object({ "@type": z.union([z.string(), z.tuple([z.string()]).transform((a) => a[0])]), }) export const ExtractNumberSchema = z.coerce.string().transform((val, ctx) => { const numberRegex = /\d+/g const regexResult = numberRegex.exec(val) if (!regexResult) { ctx.addIssue({ message: "No numbers found in servings", code: "custom", }) return z.NEVER } const [first] = regexResult return parseInt(first) }) ================================================ FILE: src/server/api/modules/recipes/service/scraper.ts ================================================ import { TRPCError } from "@trpc/server" import { ExtractNumberSchema, JsonLdRecipeSchema, RecipeImageUrlSchema, StepsToStringSchema, } from "~/server/api/modules/recipes/service/schemas" import { InsertIngredient, InsertRecipe } from "~/server/db/schema" import { JSDOM } from "jsdom" import { logger } from "~/lib/logger" async function getNodeListOfMetadataNodesFromUrl(url: string) { const dom = await JSDOM.fromURL(url) const nodeList: NodeList = dom.window.document.querySelectorAll( "script[type='application/ld+json']" ) if (nodeList.length === 0) { throw new TRPCError({ message: "The linked page contains no metadata", code: "INTERNAL_SERVER_ERROR", }) } return nodeList } function jsonObjectIsRecipe(jsonObject: Record