mirror of
https://github.com/mealie-recipes/mealie.git
synced 2024-12-25 13:31:20 -08:00
dfe4942451
* refactored recipe image paths/service * added routes for updating/fetching timeline images * make generate * added event image upload and rendering * switched update to patch to preserve timestamp * added tests * tweaked order of requests * always reload events when opening the timeline * re-arranged elements to make them look nicer * delete files when timeline event is deleted
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import { useContext } from "@nuxtjs/composition-api";
|
|
import { detectServerBaseUrl } from "../use-utils";
|
|
|
|
function UnknownToString(ukn: string | unknown) {
|
|
return typeof ukn === "string" ? ukn : "";
|
|
}
|
|
|
|
export const useStaticRoutes = () => {
|
|
const { $config, req } = useContext();
|
|
const serverBase = detectServerBaseUrl(req);
|
|
|
|
const prefix = `${$config.SUB_PATH as string}/api`.replace("//", "/");
|
|
|
|
const fullBase = serverBase + prefix;
|
|
|
|
// 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)}`;
|
|
}
|
|
|
|
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
|
|
)}`;
|
|
}
|
|
|
|
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
|
|
)}`;
|
|
}
|
|
|
|
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}`;
|
|
}
|
|
|
|
return {
|
|
recipeImage,
|
|
recipeSmallImage,
|
|
recipeTinyImage,
|
|
recipeTimelineEventImage,
|
|
recipeTimelineEventSmallImage,
|
|
recipeTimelineEventTinyImage,
|
|
recipeAssetPath,
|
|
};
|
|
};
|