Files
saman-andish/app/lib/meshkee.ts
T

57 lines
1.5 KiB
TypeScript

export type StaticImage = {
id: number | string;
url: string;
titleFa?: string | null;
titleEn?: string | null;
subtext?: string | null;
linkUrl?: string | null;
width?: number | null;
height?: number | null;
sortOrder?: number | null;
};
export type StaticImageSlot = {
key: string;
pageKey: string;
kind: "single" | "list";
label: string;
aspectRatio?: string | null;
recommendedWidth?: number | null;
itemCount?: number | null;
images: StaticImage[];
};
type StaticImageSlotsResponse = {
items?: StaticImageSlot[];
};
const API_BASE_URL =
process.env.NEXT_PUBLIC_MESHKEE_API_URL?.replace(/\/$/, "") ??
"https://api.meshkee.com/api/v1";
const WEBSITE_DOMAIN =
process.env.NEXT_PUBLIC_MESHKEE_DOMAIN ?? "samanandish.com";
export async function fetchHomeStaticImageSlots(signal?: AbortSignal) {
const endpoint = `${API_BASE_URL}/tenants/${encodeURIComponent(WEBSITE_DOMAIN)}/website/static-images?pageKey=home`;
const response = await fetch(endpoint, {
headers: { Accept: "application/json" },
signal,
});
if (!response.ok) {
throw new Error(`Static image request failed with ${response.status}`);
}
const payload = (await response.json()) as StaticImageSlotsResponse;
return Array.isArray(payload.items) ? payload.items : [];
}
export function cssAspectRatio(value?: string | null) {
if (!value || !/^\d+(?:\.\d+)?:\d+(?:\.\d+)?$/.test(value)) {
return undefined;
}
return value.replace(":", " / ");
}