[READ-ONLY] Mirror of https://github.com/flo-bit/skywatched-backend. backend/jetstream consumer for skywatched.app skywatched.app
0

Configure Feed

Select the types of activity you want to include in your feed.

skywatched-backend / src / tmdb.ts
977 B 44 lines
1import { env } from "bun"; 2 3export type Kind = 'movie' | 'tv'; 4 5export async function getDetails(id: number, kind: Kind) { 6 const url = `https://api.themoviedb.org/3/${kind}/${id}?language=en-US`; 7 const options = { 8 method: 'GET', 9 headers: { 10 accept: 'application/json', 11 Authorization: `Bearer ${env.TMDB_API_KEY}` 12 } 13 }; 14 15 const response = await fetch(url, options); 16 const data = await response.json(); 17 18 return data; 19} 20 21export async function getFormattedDetails(value: string, ref: 'tmdb:s' | 'tmdb:m') { 22 const details = await getDetails(parseInt(value), ref === 'tmdb:s' ? 'tv' : 'movie') as { 23 poster_path: string; 24 title?: string; 25 name?: string; 26 release_date?: string; 27 tagline: string; 28 overview: string; 29 genres: { 30 id: number; 31 name: string; 32 }[]; 33 backdrop_path: string; 34 }; 35 36 const title = details.title ?? details.name ?? ''; 37 const genres = details.genres?.map(genre => genre.name) ?? []; 38 39 return { 40 ...details, 41 title, 42 genres, 43 }; 44}