mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 01:48:51 +05:00
Update file tmdb.js
This commit is contained in:
@@ -2,16 +2,19 @@ const axios = require('axios');
|
|||||||
|
|
||||||
class TMDBClient {
|
class TMDBClient {
|
||||||
constructor(accessToken) {
|
constructor(accessToken) {
|
||||||
|
if (!accessToken) {
|
||||||
|
throw new Error('TMDB access token is required');
|
||||||
|
}
|
||||||
|
|
||||||
this.client = axios.create({
|
this.client = axios.create({
|
||||||
baseURL: 'https://api.themoviedb.org/3',
|
baseURL: 'https://api.themoviedb.org/3',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
},
|
},
|
||||||
timeout: 10000 // 10 секунд таймаут
|
timeout: 10000
|
||||||
});
|
});
|
||||||
|
|
||||||
// Добавляем интерцептор для обработки ошибок
|
|
||||||
this.client.interceptors.response.use(
|
this.client.interceptors.response.use(
|
||||||
response => response,
|
response => response,
|
||||||
error => {
|
error => {
|
||||||
@@ -58,17 +61,13 @@ class TMDBClient {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
|
data.results = data.results
|
||||||
// Фильтруем результаты
|
.filter(movie => movie.poster_path && movie.overview && movie.vote_average > 0)
|
||||||
data.results = data.results.filter(movie =>
|
.map(movie => ({
|
||||||
movie.poster_path &&
|
...movie,
|
||||||
movie.overview &&
|
poster_path: this.getImageURL(movie.poster_path, 'w500'),
|
||||||
movie.vote_average > 0
|
backdrop_path: this.getImageURL(movie.backdrop_path, 'original')
|
||||||
).map(movie => ({
|
}));
|
||||||
...movie,
|
|
||||||
poster_path: this.getImageURL(movie.poster_path, 'w500'),
|
|
||||||
backdrop_path: this.getImageURL(movie.backdrop_path, 'original')
|
|
||||||
}));
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -103,3 +102,23 @@ class TMDBClient {
|
|||||||
backdrop_path: this.getImageURL(movie.backdrop_path, 'original')
|
backdrop_path: this.getImageURL(movie.backdrop_path, 'original')
|
||||||
}));
|
}));
|
||||||
return response;
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getUpcomingMovies(page = 1) {
|
||||||
|
const response = await this.makeRequest('GET', '/movie/upcoming', { page });
|
||||||
|
const data = response.data;
|
||||||
|
data.results = data.results.map(movie => ({
|
||||||
|
...movie,
|
||||||
|
poster_path: this.getImageURL(movie.poster_path, 'w500'),
|
||||||
|
backdrop_path: this.getImageURL(movie.backdrop_path, 'original')
|
||||||
|
}));
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getMovieExternalIDs(id) {
|
||||||
|
const response = await this.makeRequest('GET', `/movie/${id}/external_ids`);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TMDBClient;
|
||||||
|
|||||||
Reference in New Issue
Block a user