import type { VodResponse } from "@futureporn/types"; import { bot } from "../bot.ts"; import { configs } from "../config.ts"; export default async function findVod({ vod_id, discord_message_id }: { vod_id?: string, discord_message_id?: string }): Promise { const fetchUrl = (!!vod_id) ? `${configs.postgrestUrl}/vods?id=eq.${vod_id}&select=*,segments(bytes,updated_at,created_at)` : `${configs.postgrestUrl}/vods?discord_message_id=eq.${discord_message_id}&select=*,segments(bytes,updated_at,created_at)` bot.logger.info(fetchUrl) const fetchOptions = { method: 'GET', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Prefer': 'return=representation' } } const res = await fetch(fetchUrl, fetchOptions) if (!res.ok) { const msg = `request failed. status=${res.status}, statusText=${res.statusText}` bot.logger.error(msg) throw new Error(msg) } const json = await res.json() as VodResponse[] // bot.logger.info(`vod results as follows.`) // bot.logger.info(json) return json?.at(0) || null }