2021-08-09 16:19:23 -08:00
|
|
|
import { useContext } from "@nuxtjs/composition-api";
|
2021-12-06 17:14:14 -09:00
|
|
|
import { detectServerBaseUrl } from "../use-utils";
|
2021-08-09 16:19:23 -08:00
|
|
|
|
2022-08-27 10:44:58 -08:00
|
|
|
function UnknownToString(ukn: string | unknown) {
|
|
|
|
return typeof ukn === "string" ? ukn : "";
|
|
|
|
}
|
|
|
|
|
2021-08-09 16:19:23 -08:00
|
|
|
export const useStaticRoutes = () => {
|
2021-12-06 17:14:14 -09:00
|
|
|
const { $config, req } = useContext();
|
|
|
|
const serverBase = detectServerBaseUrl(req);
|
2021-08-09 16:19:23 -08:00
|
|
|
|
2022-01-09 07:15:23 +01:00
|
|
|
const prefix = `${$config.SUB_PATH as string}/api`.replace("//", "/");
|
2021-08-09 16:19:23 -08:00
|
|
|
|
2021-12-06 17:14:14 -09:00
|
|
|
const fullBase = serverBase + prefix;
|
|
|
|
|
2021-08-09 16:19:23 -08:00
|
|
|
// Methods to Generate reference urls for assets/images *
|
2022-08-27 10:44:58 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-08-27 10:44:58 -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
|
|
|
}
|
|
|
|
|
2022-08-27 10:44:58 -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
|
|
|
}
|
|
|
|
|
2022-02-13 12:23:42 -09:00
|
|
|
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,
|
|
|
|
recipeAssetPath,
|
|
|
|
};
|
|
|
|
};
|