| const { fetchTmdbData } = require('../handlers/mainHandle');
|
| const { processVideo } = require ('../utils/ts');
|
|
|
|
|
|
|
|
|
|
|
| const tmdbEndpointMap = {
|
| '/movie/popular': 'movie/popular',
|
| '/tv/popular': 'tv/popular',
|
| '/trending/movie/day': 'trending/movie/day',
|
| '/trending/tv/day': 'trending/tv/day',
|
| '/trending/all/day': 'trending/all/day',
|
| '/trending/movie/week': 'trending/movie/week',
|
| '/trending/tv/week': 'trending/tv/week',
|
| 'tv&movie': 'trending/all/week',
|
| '/genre/movie/list': 'genre/movie/list',
|
| '/discover/movie': 'discover/movie',
|
| '/movie/upcoming': 'movie/upcoming',
|
| '/movie/now_playing': 'movie/now_playing',
|
| '/tv' : 'tv',
|
| '/movie' : 'movie',
|
|
|
| };
|
|
|
|
|
| async function getTmdbContent(req, res) {
|
| try {
|
|
|
|
|
|
|
| const basePath = req.route.path.replace(/\/:tmdbid.*$/, '');
|
| let tmdbEndpoint;
|
|
|
| if (req.params.seasonid) {
|
| tmdbEndpoint = `${tmdbEndpointMap[basePath]}/${req.params.tmdbid}/season/${req.params.seasonid}`;
|
| } else {
|
| tmdbEndpoint = req.params.tmdbid ? `${tmdbEndpointMap[basePath]}/${req.params.tmdbid}` : tmdbEndpointMap[basePath];
|
| }
|
|
|
|
|
| if (!tmdbEndpoint) {
|
| return res.status(404).json({ error: "Endpoint de TMDB no encontrado para esta ruta." });
|
| }
|
|
|
|
|
| const queryParams = req.query;
|
|
|
|
|
| const data = await fetchTmdbData(tmdbEndpoint, queryParams);
|
|
|
| if (data) {
|
| res.json(data);
|
| } else {
|
|
|
|
|
| res.status(500).json({ error: "No se pudieron obtener datos de TMDB." });
|
| }
|
|
|
| } catch (error) {
|
|
|
| console.error("Error en el controlador de TMDB:", error.message);
|
| res.status(500).json({ error: "Error interno del servidor al procesar la solicitud.", details: error.message });
|
| }
|
| }
|
|
|
|
|
| async function getCacheStream (req, res) {
|
| const { locker, id } = req.params;
|
|
|
| if (!contentCache[`${locker}-get${id}`]) {
|
| return res.status(404).json({ error: `No se encontró el contenido para el ID: ${id}` });
|
| }
|
|
|
| try {
|
| const link = contentCache[`${locker}-get${id}`].result;
|
| const request = await processVideo(link);
|
|
|
|
|
| res.json({link: request});
|
| } catch (error) {
|
| console.error(error);
|
| res.status(500).json({ error: 'Error en el formato de respuesta' });
|
| }
|
| };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| module.exports = {
|
| getCacheStream,
|
| getTmdbContent,
|
|
|
|
|
|
|
|
|
|
|
| }; |