1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-20 05:39:40 +02:00
mealie/frontend/composables/api/static-routes.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-08-09 16:19:23 -08:00
import { useContext } from "@nuxtjs/composition-api";
import { detectServerBaseUrl } from "../use-utils";
2021-08-09 16:19:23 -08:00
export const useStaticRoutes = () => {
const { $config, req } = useContext();
const serverBase = detectServerBaseUrl(req);
2021-08-09 16:19:23 -08:00
const prefix = `${$config.SUB_PATH}/api`.replace("//", "/");
const fullBase = serverBase + prefix;
2021-08-09 16:19:23 -08:00
// Methods to Generate reference urls for assets/images *
function recipeImage(recipeSlug: string, version = null, key = null) {
return `${fullBase}/media/recipes/${recipeSlug}/images/original.webp?&rnd=${key}&version=${version}`;
2021-08-09 16:19:23 -08:00
}
function recipeSmallImage(recipeSlug: string, version = null, key = null) {
return `${fullBase}/media/recipes/${recipeSlug}/images/min-original.webp?&rnd=${key}&version=${version}`;
2021-08-09 16:19:23 -08:00
}
function recipeTinyImage(recipeSlug: string, version = null, key = null) {
return `${fullBase}/media/recipes/${recipeSlug}/images/tiny-original.webp?&rnd=${key}&version=${version}`;
2021-08-09 16:19:23 -08:00
}
function recipeAssetPath(recipeSlug: string, assetName: string) {
return `${fullBase}/media/recipes/${recipeSlug}/assets/${assetName}`;
2021-08-09 16:19:23 -08:00
}
return {
recipeImage,
recipeSmallImage,
recipeTinyImage,
recipeAssetPath,
};
};