import { configs } from "../config.ts" import type { VodRecord } from "@futureporn/types" export default async function createVod(payload: Partial): Promise { const vodPayload = { date: new Date().toISOString() } const res = await fetch(`${configs.postgrestUrl}/vods`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Prefer': 'return=headers-only', 'Authorization': `Bearer ${configs.automationUserJwt}`, }, body: JSON.stringify(Object.assign(vodPayload, payload)) }) if (!res.ok) { const status = res.status const statusText = res.statusText const body = await res.text() const msg = `Failed to create vod in database. status=${status}, statusText=${statusText}, body=${body}` console.error(msg) throw new Error(msg) } const id = res.headers.get('location')?.split('.').at(-1) if (!id) throw new Error('id could not be parsed from location header'); return id }