fp/packages/fetchers/src/patchVod.ts

29 lines
833 B
TypeScript
Raw Normal View History

2024-09-16 16:31:51 +00:00
import type { StreamRecord } from "@futureporn/types";
import { configs } from "./config.ts";
2024-08-27 07:11:24 +00:00
2024-09-16 16:31:51 +00:00
export default async function patchVod(stream_id: string, payload: Partial<StreamRecord>): Promise<void> {
2024-09-03 16:28:39 +00:00
const url = `${configs.postgrestUrl}/vods?id=eq.${stream_id}`
2024-08-27 07:11:24 +00:00
const fetchOptions = {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${configs.automationUserJwt}`,
'Content-Type': 'application/json',
'Prefer': 'return=headers-only'
},
body: JSON.stringify(payload)
}
try {
const res = await fetch(url, fetchOptions)
if (!res.ok) {
const body = await res.json()
2024-09-16 16:31:51 +00:00
console.error(body)
2024-09-03 16:28:39 +00:00
throw new Error(`Problem during patchVod. res.status=${res.status}, res.statusText=${res.statusText}`)
2024-08-27 07:11:24 +00:00
}
return
} catch (e) {
2024-09-16 16:31:51 +00:00
console.error(e)
2024-08-27 07:11:24 +00:00
throw e
}
}