feat(backend): add TMDB preview endpoint for non-library entries
- Add GET /entries/tmdb/preview/:type/:tmdbId endpoint in entryController.js - Fetch TMDB data via tmdbService.fetchEntryData() without persisting to DB - Return normalized preview object with title, poster, genres, rating, season/episode counts
This commit is contained in:
1 parent
6aa57cbe71
commit
25b645a16f
13 files changed
+199
-10
No files matched your search
@@ -163,6 +163,39 @@ class EntryController {
|
||||
if (!data) return res.status(500).json({ message: 'Failed to fetch upcoming data' });
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
// * GET - TMDB PREVIEW (fetch details without saving to library)
|
||||
getTmdbPreview = asyncWrapper(async (req, res) => {
|
||||
const { type, tmdbId } = req.params;
|
||||
const is_tvserie = type === 'tv';
|
||||
const data = await tmdbService.fetchEntryData(tmdbId, is_tvserie);
|
||||
if (!data) return res.status(404).json({ message: 'Entry not found on TMDB' });
|
||||
|
||||
// Normalize to a shape similar to our Entry model
|
||||
const preview = {
|
||||
tmdb_id: data.id,
|
||||
title: data.title || data.name,
|
||||
original_title: data.original_title || data.original_name || null,
|
||||
release_date: data.release_date || data.first_air_date || null,
|
||||
runtime: data.runtime || (data.episode_run_time?.[0]) || null,
|
||||
storyline: data.overview || null,
|
||||
country: data.origin_country?.[0] || data.production_countries?.[0]?.iso_3166_1 || null,
|
||||
is_tvseries: is_tvserie,
|
||||
status: data.status || null,
|
||||
poster_path: data.poster_path || null,
|
||||
backdrop_path: data.backdrop_path || null,
|
||||
vote_average: data.vote_average || null,
|
||||
genres: data.genres || [],
|
||||
tagline: data.tagline || null,
|
||||
number_of_seasons: data.number_of_seasons || null,
|
||||
number_of_episodes: data.number_of_episodes || null,
|
||||
networks: data.networks || [],
|
||||
homepage: data.homepage || null,
|
||||
imdb_id: data.imdb_id || data.external_ids?.imdb_id || null,
|
||||
};
|
||||
|
||||
res.status(200).json(preview);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = new EntryController();
|
||||
Reference in new issue
Block a user