mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-10-27 08:14:30 -04:00
feat: Import + Translate recipe images with OpenAI (#3974)
Co-authored-by: Johan Lindell <johan@lindell.me> Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
This commit is contained in:
@@ -35,6 +35,7 @@ const routes = {
|
||||
recipesCreateUrl: `${prefix}/recipes/create-url`,
|
||||
recipesCreateUrlBulk: `${prefix}/recipes/create-url/bulk`,
|
||||
recipesCreateFromZip: `${prefix}/recipes/create-from-zip`,
|
||||
recipesCreateFromImage: `${prefix}/recipes/create-from-image`,
|
||||
recipesCategory: `${prefix}/recipes/category`,
|
||||
recipesParseIngredient: `${prefix}/parser/ingredient`,
|
||||
recipesParseIngredients: `${prefix}/parser/ingredients`,
|
||||
@@ -140,6 +141,19 @@ export class RecipeAPI extends BaseCRUDAPI<CreateRecipe, Recipe, Recipe> {
|
||||
return await this.requests.post<string>(routes.recipesCreateUrlBulk, payload);
|
||||
}
|
||||
|
||||
async createOneFromImage(fileObject: Blob | File, fileName: string, translateLanguage: string | null = null) {
|
||||
const formData = new FormData();
|
||||
formData.append("images", fileObject);
|
||||
formData.append("extension", fileName.split(".").pop() ?? "");
|
||||
|
||||
let apiRoute = routes.recipesCreateFromImage
|
||||
if (translateLanguage) {
|
||||
apiRoute = `${apiRoute}?translateLanguage=${translateLanguage}`
|
||||
}
|
||||
|
||||
return await this.requests.post<string>(apiRoute, formData);
|
||||
}
|
||||
|
||||
async parseIngredients(parser: Parser, ingredients: Array<string>) {
|
||||
parser = parser || "nlp";
|
||||
return await this.requests.post<ParsedIngredient[]>(routes.recipesParseIngredients, { parser, ingredients });
|
||||
|
||||
Reference in New Issue
Block a user