fp/services/factory/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

33 lines
1.0 KiB
TypeScript

import { configs } from "../config"
import type { Vod, Stream } from '@futureporn/types'
export default async function createVod(stream?: Stream): Promise<Vod|null> {
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
}