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

56 lines
2 KiB
TypeScript
Raw Permalink Normal View History

function UnknownToString(ukn: string | unknown) {
return typeof ukn === "string" ? ukn : "";
}
2021-08-09 16:19:23 -08:00
export const useStaticRoutes = () => {
const { $config } = useNuxtApp();
const serverBase = useRequestURL().origin;
2021-08-09 16:19:23 -08:00
const prefix = `${$config.public.SUB_PATH}/api`.replace("//", "/");
2021-08-09 16:19:23 -08:00
const fullBase = serverBase + prefix;
2021-08-09 16:19:23 -08:00
// Methods to Generate reference urls for assets/images *
function recipeImage(recipeId: string, version: string | unknown = "", key: string | number = 1) {
return `${fullBase}/media/recipes/${recipeId}/images/original.webp?rnd=${key}&version=${UnknownToString(version)}`;
2021-08-09 16:19:23 -08:00
}
function recipeSmallImage(recipeId: string, version: string | unknown = "", key: string | number = 1) {
return `${fullBase}/media/recipes/${recipeId}/images/min-original.webp?rnd=${key}&version=${UnknownToString(
version,
)}`;
2021-08-09 16:19:23 -08:00
}
function recipeTinyImage(recipeId: string, version: string | unknown = "", key: string | number = 1) {
return `${fullBase}/media/recipes/${recipeId}/images/tiny-original.webp?rnd=${key}&version=${UnknownToString(
version,
)}`;
2021-08-09 16:19:23 -08:00
}
function recipeTimelineEventImage(recipeId: string, timelineEventId: string) {
return `${fullBase}/media/recipes/${recipeId}/images/timeline/${timelineEventId}/original.webp`;
}
function recipeTimelineEventSmallImage(recipeId: string, timelineEventId: string) {
return `${fullBase}/media/recipes/${recipeId}/images/timeline/${timelineEventId}/min-original.webp`;
}
function recipeTimelineEventTinyImage(recipeId: string, timelineEventId: string) {
return `${fullBase}/media/recipes/${recipeId}/images/timeline/${timelineEventId}/tiny-original.webp`;
}
function recipeAssetPath(recipeId: string, assetName: string) {
return `${fullBase}/media/recipes/${recipeId}/assets/${assetName}`;
2021-08-09 16:19:23 -08:00
}
return {
recipeImage,
recipeSmallImage,
recipeTinyImage,
recipeTimelineEventImage,
recipeTimelineEventSmallImage,
recipeTimelineEventTinyImage,
2021-08-09 16:19:23 -08:00
recipeAssetPath,
};
};