mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 07:39:41 +02:00
feat: create recipe from multiple images (#5590)
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com> Co-authored-by: Kuchenpirat <jojow@gmx.net> Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
parent
084f99b0de
commit
95fa0af28a
8 changed files with 149 additions and 131 deletions
|
@ -1,4 +1,4 @@
|
|||
import type { AxiosResponse } from "axios";
|
||||
import type { AxiosRequestConfig, AxiosResponse } from "axios";
|
||||
|
||||
export type NoUndefinedField<T> = { [P in keyof T]-?: NoUndefinedField<NonNullable<T[P]>> };
|
||||
|
||||
|
@ -9,11 +9,11 @@ export interface RequestResponse<T> {
|
|||
}
|
||||
|
||||
export interface ApiRequestInstance {
|
||||
get<T>(url: string, data?: unknown): Promise<RequestResponse<T>>;
|
||||
post<T>(url: string, data: unknown): Promise<RequestResponse<T>>;
|
||||
put<T, U = T>(url: string, data: U): Promise<RequestResponse<T>>;
|
||||
patch<T, U = Partial<T>>(url: string, data: U): Promise<RequestResponse<T>>;
|
||||
delete<T>(url: string): Promise<RequestResponse<T>>;
|
||||
get<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<RequestResponse<T>>;
|
||||
post<T>(url: string, data: unknown, config?: AxiosRequestConfig): Promise<RequestResponse<T>>;
|
||||
put<T, U = T>(url: string, data: U, config?: AxiosRequestConfig): Promise<RequestResponse<T>>;
|
||||
patch<T, U = Partial<T>>(url: string, data: U, config?: AxiosRequestConfig): Promise<RequestResponse<T>>;
|
||||
delete<T>(url: string, config?: AxiosRequestConfig): Promise<RequestResponse<T>>;
|
||||
}
|
||||
|
||||
export interface PaginationData<T> {
|
||||
|
|
|
@ -157,17 +157,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) {
|
||||
async createOneFromImages(fileObjects: (Blob | File)[], translateLanguage: string | null = null) {
|
||||
const formData = new FormData();
|
||||
formData.append("images", fileObject);
|
||||
formData.append("extension", fileName.split(".").pop() ?? "");
|
||||
|
||||
fileObjects.forEach((file) => {
|
||||
formData.append("images", file);
|
||||
});
|
||||
|
||||
let apiRoute = routes.recipesCreateFromImage;
|
||||
if (translateLanguage) {
|
||||
apiRoute = `${apiRoute}?translateLanguage=${translateLanguage}`;
|
||||
}
|
||||
|
||||
return await this.requests.post<string>(apiRoute, formData);
|
||||
return await this.requests.post<string>(apiRoute, formData, { timeout: 120000 });
|
||||
}
|
||||
|
||||
async parseIngredients(parser: Parser, ingredients: Array<string>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue