24 lines
884 B
TypeScript
24 lines
884 B
TypeScript
import { configs } from "../config"
|
|
import { Helpers } from "graphile-worker"
|
|
import { Stream } from "@futureporn/types"
|
|
|
|
export default async function getVod(vodId: string, helpers: Helpers) {
|
|
const url = `${configs.postgrestUrl}/streams?select=*,segments(*)&id=eq.${vodId}`
|
|
try {
|
|
const res = await fetch(url)
|
|
if (!res.ok) {
|
|
throw new Error(`failed fetching stream ${vodId}. status=${res.status}, statusText=${res.statusText}`)
|
|
}
|
|
const body = await res.json() as Stream[]
|
|
if (!body[0]) throw new Error('body[0] was expected to be Stream data, but it was either null or undefined.');
|
|
return body[0];
|
|
} catch (e) {
|
|
helpers.logger.error(`encountered an error during getStreamFromDatabase()`)
|
|
if (e instanceof Error) {
|
|
helpers.logger.error(e.message)
|
|
} else {
|
|
helpers.logger.error(JSON.stringify(e))
|
|
}
|
|
return null
|
|
}
|
|
} |