mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 09:58:50 +05:00
Update 10 files
- /package.json - /package-lock.json - /README.md - /vercel.json - /src/config/tmdb.js - /src/public/api-docs/index.html - /src/utils/date.js - /src/utils/health.js - /src/routes/movies.js - /src/index.js
This commit is contained in:
105
src/config/tmdb.js
Normal file
105
src/config/tmdb.js
Normal file
@@ -0,0 +1,105 @@
|
||||
const axios = require('axios');
|
||||
|
||||
class TMDBClient {
|
||||
constructor(accessToken) {
|
||||
this.client = axios.create({
|
||||
baseURL: 'https://api.themoviedb.org/3',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`,
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async makeRequest(method, endpoint, params = {}) {
|
||||
try {
|
||||
const response = await this.client.request({
|
||||
method,
|
||||
url: endpoint,
|
||||
params: {
|
||||
...params,
|
||||
language: 'ru-RU',
|
||||
region: 'RU'
|
||||
}
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error(`TMDB API Error: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
getImageURL(path, size = 'original') {
|
||||
if (!path) return null;
|
||||
return `https://image.tmdb.org/t/p/${size}${path}`;
|
||||
}
|
||||
|
||||
async searchMovies(query, page = 1) {
|
||||
const data = await this.makeRequest('GET', '/search/movie', {
|
||||
query,
|
||||
page,
|
||||
include_adult: false
|
||||
});
|
||||
|
||||
// Фильтруем результаты
|
||||
data.results = data.results.filter(movie =>
|
||||
movie.poster_path &&
|
||||
movie.overview &&
|
||||
movie.vote_average > 0
|
||||
);
|
||||
|
||||
// Добавляем полные URL для изображений
|
||||
data.results = data.results.map(movie => ({
|
||||
...movie,
|
||||
poster_path: this.getImageURL(movie.poster_path, 'w500'),
|
||||
backdrop_path: this.getImageURL(movie.backdrop_path, 'w1280')
|
||||
}));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
async getMovie(id) {
|
||||
const movie = await this.makeRequest('GET', `/movie/${id}`);
|
||||
return {
|
||||
...movie,
|
||||
poster_path: this.getImageURL(movie.poster_path, 'w500'),
|
||||
backdrop_path: this.getImageURL(movie.backdrop_path, 'w1280')
|
||||
};
|
||||
}
|
||||
|
||||
async getPopularMovies(page = 1) {
|
||||
const data = await this.makeRequest('GET', '/movie/popular', { page });
|
||||
data.results = data.results.map(movie => ({
|
||||
...movie,
|
||||
poster_path: this.getImageURL(movie.poster_path, 'w500'),
|
||||
backdrop_path: this.getImageURL(movie.backdrop_path, 'w1280')
|
||||
}));
|
||||
return data;
|
||||
}
|
||||
|
||||
async getTopRatedMovies(page = 1) {
|
||||
const data = await this.makeRequest('GET', '/movie/top_rated', { page });
|
||||
data.results = data.results.map(movie => ({
|
||||
...movie,
|
||||
poster_path: this.getImageURL(movie.poster_path, 'w500'),
|
||||
backdrop_path: this.getImageURL(movie.backdrop_path, 'w1280')
|
||||
}));
|
||||
return data;
|
||||
}
|
||||
|
||||
async getUpcomingMovies(page = 1) {
|
||||
const data = await this.makeRequest('GET', '/movie/upcoming', { page });
|
||||
data.results = data.results.map(movie => ({
|
||||
...movie,
|
||||
poster_path: this.getImageURL(movie.poster_path, 'w500'),
|
||||
backdrop_path: this.getImageURL(movie.backdrop_path, 'w1280')
|
||||
}));
|
||||
return data;
|
||||
}
|
||||
|
||||
async getMovieExternalIDs(id) {
|
||||
return await this.makeRequest('GET', `/movie/${id}/external_ids`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TMDBClient;
|
||||
Reference in New Issue
Block a user