diff --git a/docs/docs/overrides/api.html b/docs/docs/overrides/api.html index 5c6749702..39aa3d36a 100644 --- a/docs/docs/overrides/api.html +++ b/docs/docs/overrides/api.html @@ -14,7 +14,7 @@
diff --git a/frontend/composables/use-validators.ts b/frontend/composables/use-validators.ts index 3f03d331f..803caf088 100644 --- a/frontend/composables/use-validators.ts +++ b/frontend/composables/use-validators.ts @@ -1,12 +1,13 @@ import type { RequestResponse } from "~/lib/api/types/non-generated"; import type { ValidationResponse } from "~/lib/api/types/response"; -import { required, email, whitespace, url, minLength, maxLength } from "~/lib/validators"; +import { required, email, whitespace, url, urlOptional, minLength, maxLength } from "~/lib/validators"; export const validators = { required, email, whitespace, url, + urlOptional, minLength, maxLength, }; diff --git a/frontend/lang/messages/en-US.json b/frontend/lang/messages/en-US.json index 4454d1419..bbf6ac50e 100644 --- a/frontend/lang/messages/en-US.json +++ b/frontend/lang/messages/en-US.json @@ -445,6 +445,7 @@ "upload-a-recipe": "Upload a Recipe", "upload-individual-zip-file": "Upload an individual .zip file exported from another Mealie instance.", "url-form-hint": "Copy and paste a link from your favorite recipe website", + "copy-and-paste-the-source-url-of-your-data-optional": "Copy and paste the source URL of your data (optional)", "view-scraped-data": "View Scraped Data", "trim-whitespace-description": "Trim leading and trailing whitespace as well as blank lines", "trim-prefix-description": "Trim first character from each line", diff --git a/frontend/lib/api/types/recipe.ts b/frontend/lib/api/types/recipe.ts index cc045cdbc..77858e3d6 100644 --- a/frontend/lib/api/types/recipe.ts +++ b/frontend/lib/api/types/recipe.ts @@ -510,6 +510,7 @@ export interface ScrapeRecipeBase { export interface ScrapeRecipeData { includeTags?: boolean; data: string; + url?: string | null; } export interface ScrapeRecipeTest { url: string; diff --git a/frontend/lib/api/user/recipes/recipe.ts b/frontend/lib/api/user/recipes/recipe.ts index de2056635..bc56a9591 100644 --- a/frontend/lib/api/user/recipes/recipe.ts +++ b/frontend/lib/api/user/recipes/recipe.ts @@ -146,8 +146,8 @@ export class RecipeAPI extends BaseCRUDAPI { return await this.requests.post(routes.recipesTestScrapeUrl, { url, useOpenAI }); } - async createOneByHtmlOrJson(data: string, includeTags: boolean) { - return await this.requests.post(routes.recipesCreateFromHtmlOrJson, { data, includeTags }); + async createOneByHtmlOrJson(data: string, includeTags: boolean, url: string | null = null) { + return await this.requests.post(routes.recipesCreateFromHtmlOrJson, { data, includeTags, url }); } async createOneByUrl(url: string, includeTags: boolean) { diff --git a/frontend/lib/validators/index.ts b/frontend/lib/validators/index.ts index f384f9c20..3d3ed546a 100644 --- a/frontend/lib/validators/index.ts +++ b/frontend/lib/validators/index.ts @@ -1,2 +1,2 @@ export { scorePassword } from "./password"; -export { required, email, whitespace, url, minLength, maxLength } from "./inputs"; +export { required, email, whitespace, url, urlOptional, minLength, maxLength } from "./inputs"; diff --git a/frontend/lib/validators/inputs.ts b/frontend/lib/validators/inputs.ts index 96a03866c..cffb92b59 100644 --- a/frontend/lib/validators/inputs.ts +++ b/frontend/lib/validators/inputs.ts @@ -1,7 +1,7 @@ const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@(([[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; -const URL_REGEX = /[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/; +const URL_REGEX = /[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/; export function required(v: string | undefined | null) { return !!v || "This Field is Required"; @@ -19,6 +19,10 @@ export function url(v: string | undefined | null) { return (!!v && URL_REGEX.test(v)) || "Must Be A Valid URL"; } +export function urlOptional(v: string | undefined | null) { + return v ? url(v) : true; +} + export function minLength(min: number) { return (v: string | undefined | null) => (!!v && v.length >= min) || `Must Be At Least ${min} Characters`; } diff --git a/frontend/pages/g/[groupSlug]/r/create/html.vue b/frontend/pages/g/[groupSlug]/r/create/html.vue index c788e4d6e..5e0eccc5c 100644 --- a/frontend/pages/g/[groupSlug]/r/create/html.vue +++ b/frontend/pages/g/[groupSlug]/r/create/html.vue @@ -1,7 +1,7 @@