fp/services/bot/src/fetchers/createVod.ts
CJ_Clippy fdd295e2b8
Some checks failed
ci / build (push) Failing after 0s
change scout to a service
2024-08-26 23:11:24 -08:00

28 lines
980 B
TypeScript

import { configs } from "../config.ts"
import type { VodRecord } from "@futureporn/types"
export default async function createVod(payload: Partial<VodRecord>): Promise<string> {
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
}