import { configs } from "../config" import type { Vod, Stream } from '@futureporn/types' export default async function createVod(stream?: Stream): Promise { if (!stream) throw new Error(`first argument passed to createVod must be a {Stream}`); console.log(stream) const url = `${configs.postgrestUrl}/vods` const payload: any = { stream_id: stream.id, date: stream.date, vtuber: stream.vtuber, } const fetchOptions = { method: 'POST', headers: { 'Authorization': `Bearer ${configs.automationUserJwt}`, 'Content-Type': 'application/json', 'Accept': 'application/json', 'Prefer': 'return=representation' }, body: JSON.stringify(payload) } const res = await fetch (url, fetchOptions) if (!res.ok) { const body = await res.json() throw new Error(`Problem during createVod. res.status=${res.status}, res.statusText=${res.statusText}, body=${JSON.stringify(body)}`) } const json = await res.json() as Vod[] const vod = json[0] if (!vod) return null else return vod }