Initial work on library page

This commit is contained in:
Aleksi Lassila
2023-06-15 02:08:47 +03:00
parent c463bb89e9
commit e41b030d45
15 changed files with 275 additions and 26 deletions

View File

@@ -8,14 +8,37 @@ export const TmdbApi = axios.create({
}
});
export async function fetchMovieDetails(imdbId: string | number) {
export async function fetchMovieDetails(imdbId: string | number): Promise<TmdbMovieFull> {
return {
...(await TmdbApi.get('/movie/' + imdbId).then((res) => res.data)),
videos: await TmdbApi.get('/movie/' + imdbId + '/videos').then((res) => res.data.results),
credits: await TmdbApi.get('/movie/' + imdbId + '/credits').then((res) => res.data.cast)
videos: await TmdbApi.get<VideosResponse>('/movie/' + imdbId + '/videos').then(
(res) => res.data.results
),
images: await TmdbApi.get<ImagesResponse>('/movie/' + imdbId + '/images').then((res) => {
return {
backdrops: res.data.backdrops,
logos: res.data.logos,
posters: res.data.posters
};
}),
credits: await TmdbApi.get<CreditsResponse>('/movie/' + imdbId + '/credits').then(
(res) => res.data.cast
)
};
}
export interface TmdbMovieFull extends TmdbMovie {
videos: Video[];
images: {
backdrops: Backdrop[];
logos: Logo[];
posters: Poster[];
};
credits: CastMember[];
}
export type MovieDetailsResponse = TmdbMovie;
export interface TmdbMovie {
adult: boolean;
backdrop_path: string;
@@ -119,3 +142,40 @@ export interface Video {
published_at: string;
id: string;
}
export interface ImagesResponse {
backdrops: Backdrop[];
id: number;
logos: Logo[];
posters: Poster[];
}
export interface Backdrop {
aspect_ratio: number;
height: number;
iso_639_1?: string;
file_path: string;
vote_average: number;
vote_count: number;
width: number;
}
export interface Logo {
aspect_ratio: number;
height: number;
iso_639_1: string;
file_path: string;
vote_average: number;
vote_count: number;
width: number;
}
export interface Poster {
aspect_ratio: number;
height: number;
iso_639_1?: string;
file_path: string;
vote_average: number;
vote_count: number;
width: number;
}

12
src/lib/utils.ts Normal file
View File

@@ -0,0 +1,12 @@
import type { Genre } from '$lib/tmdb-api';
export function getRuntime(minutes: number) {
const hours = Math.floor(minutes / 60);
const mins = Math.floor(minutes % 60);
return `${hours > 0 ? hours + 'h ' : ''}${mins}min`;
}
export function formatGenres(genres: Genre[]) {
return genres.map((genre) => genre.name.charAt(0).toUpperCase() + genre.name.slice(1)).join(', ');
}