import { configs } from "./config" import type { VodResponse } from "@futureporn/types" export default async function getVod(vodId: string) { const url = `${configs.postgrestUrl}/vods?select=*,segments(*)&id=eq.${vodId}` try { const res = await fetch(url) if (!res.ok) { throw new Error(`failed fetching getVod ${vodId}. status=${res.status}, statusText=${res.statusText}`) } const body = await res.json() as VodResponse[] if (!body[0]) throw new Error('body[0] was expected to be Vod data, but it was either null or undefined.'); return body[0]; } catch (e) { console.error(`encountered an error during getVod()`) if (e instanceof Error) { console.error(e.message) } else { console.error(JSON.stringify(e)) } return null } }