fp/packages/fetchers/src/getPlaylistUrl.ts

23 lines
1016 B
TypeScript

import { configs } from './config.ts'
import { type GenericApiResponse } from '@futureporn/types'
export default async function getPlaylistUrl (url: string): Promise<GenericApiResponse> {
if (!url) throw new Error(`getPlaylistUrl requires a url, but it was undefined.`);
const res = await fetch(`${configs.scoutUrl}/ytdlp/playlist-url?url=${url}`)
if (!res.ok) {
const body = await res.text()
console.error(`failed to getPlaylistUrl res.status=${res.status}, res.statusText=${res.statusText}, body=${body}`)
return {
error: 'PlaylistFailedError',
detail: `failed to getPlaylistUrl. res.status=${res.status}, res.statusText=${res.statusText}, body=${body}`,
data: null,
message: 'something went wrong wile fetching data from @futureporn/scout'
}
} else {
const payload = await res.json() as any
console.log(`>>>>>> getPlaylistUrl data=${payload.data}, error=${payload.error} got a data payload as follows.`)
console.log(payload)
return payload
}
}