mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 05:25:26 +02:00
feat: public recipe access (#1610)
* initial public explorer API endpoint * public API endpoint * cleanup recipe page * wip: init explorer page * use public URLs for shared recipes * refactor private share tokens to use shared page
This commit is contained in:
parent
9ea5e6584f
commit
18b2c92a76
24 changed files with 361 additions and 437 deletions
|
@ -2,7 +2,15 @@ import { CommentsApi } from "./recipe-comments";
|
|||
import { RecipeShareApi } from "./recipe-share";
|
||||
import { BaseCRUDAPI } from "~/api/_base";
|
||||
|
||||
import { Recipe, CreateRecipe, RecipeAsset, CreateRecipeByUrlBulk, ParsedIngredient, UpdateImageResponse, RecipeZipTokenResponse } from "~/types/api-types/recipe";
|
||||
import {
|
||||
Recipe,
|
||||
CreateRecipe,
|
||||
RecipeAsset,
|
||||
CreateRecipeByUrlBulk,
|
||||
ParsedIngredient,
|
||||
UpdateImageResponse,
|
||||
RecipeZipTokenResponse,
|
||||
} from "~/types/api-types/recipe";
|
||||
import { ApiRequestInstance } from "~/types/api";
|
||||
|
||||
export type Parser = "nlp" | "brute";
|
||||
|
@ -35,8 +43,6 @@ const routes = {
|
|||
|
||||
recipesSlugComments: (slug: string) => `${prefix}/recipes/${slug}/comments`,
|
||||
recipesSlugCommentsId: (slug: string, id: number) => `${prefix}/recipes/${slug}/comments/${id}`,
|
||||
|
||||
recipeShareToken: (token: string) => `${prefix}/recipes/shared/${token}`,
|
||||
};
|
||||
|
||||
export class RecipeAPI extends BaseCRUDAPI<CreateRecipe, Recipe, Recipe> {
|
||||
|
@ -110,8 +116,4 @@ export class RecipeAPI extends BaseCRUDAPI<CreateRecipe, Recipe, Recipe> {
|
|||
getZipRedirectUrl(recipeSlug: string, token: string) {
|
||||
return `${routes.recipesRecipeSlugExportZip(recipeSlug)}?token=${token}`;
|
||||
}
|
||||
|
||||
async getShared(item_id: string) {
|
||||
return await this.requests.get<Recipe>(routes.recipeShareToken(item_id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
import { ValidatorsApi } from "./public/validators";
|
||||
import { ExploreApi } from "./public/explore";
|
||||
import { SharedApi } from "./public/shared";
|
||||
import { ApiRequestInstance } from "~/types/api";
|
||||
|
||||
export class PublicApi {
|
||||
public validators: ValidatorsApi;
|
||||
public explore: ExploreApi;
|
||||
public shared: SharedApi;
|
||||
|
||||
constructor(requests: ApiRequestInstance) {
|
||||
this.validators = new ValidatorsApi(requests);
|
||||
this.explore = new ExploreApi(requests);
|
||||
this.shared = new SharedApi(requests);
|
||||
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
|
14
frontend/api/public/explore.ts
Normal file
14
frontend/api/public/explore.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { BaseAPI } from "../_base";
|
||||
import { Recipe } from "~/types/api-types/recipe";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
recipe: (groupId: string, recipeSlug: string) => `${prefix}/explore/recipes/${groupId}/${recipeSlug}`,
|
||||
};
|
||||
|
||||
export class ExploreApi extends BaseAPI {
|
||||
async recipe(groupId: string, recipeSlug: string) {
|
||||
return await this.requests.get<Recipe>(routes.recipe(groupId, recipeSlug));
|
||||
}
|
||||
}
|
14
frontend/api/public/shared.ts
Normal file
14
frontend/api/public/shared.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { BaseAPI } from "../_base";
|
||||
import { Recipe } from "~/types/api-types/recipe";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
recipeShareToken: (token: string) => `${prefix}/recipes/shared/${token}`,
|
||||
};
|
||||
|
||||
export class SharedApi extends BaseAPI {
|
||||
async getShared(item_id: string) {
|
||||
return await this.requests.get<Recipe>(routes.recipeShareToken(item_id));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue