fix(backend): fetch credits in TMDB preview and fix collection fallback
- Add credits fetch to GET /entries/tmdb/preview/:type/:tmdbId endpoint - Map cast/crew to Credit-like shapes in preview response - Fall back to entry backdrops when collection has no backdrop
This commit is contained in:
1 parent
23bce5a681
commit
ea143fb32a
1 file changed
+25
@@ -171,6 +171,30 @@ class EntryController {
|
|||||||
const data = await tmdbService.fetchEntryData(tmdbId, is_tvserie);
|
const data = await tmdbService.fetchEntryData(tmdbId, is_tvserie);
|
||||||
if (!data) return res.status(404).json({ message: 'Entry not found on TMDB' });
|
if (!data) return res.status(404).json({ message: 'Entry not found on TMDB' });
|
||||||
|
|
||||||
|
// Fetch credits in parallel
|
||||||
|
const creditsData = await tmdbService.fetchEntryCredits(tmdbId, is_tvserie);
|
||||||
|
|
||||||
|
// Map credits to a shape similar to our Credit model
|
||||||
|
const credits = [];
|
||||||
|
if (creditsData?.cast) {
|
||||||
|
for (const c of creditsData.cast) {
|
||||||
|
credits.push({
|
||||||
|
id: c.credit_id || c.id,
|
||||||
|
cast_type: 'cast',
|
||||||
|
character: is_tvserie
|
||||||
|
? (c.roles?.[0]?.character || c.character || null)
|
||||||
|
: (c.character || null),
|
||||||
|
people_id: c.id,
|
||||||
|
people: {
|
||||||
|
id: c.id,
|
||||||
|
name: c.name || c.original_name,
|
||||||
|
profile_path: c.profile_path,
|
||||||
|
tmdb_id: c.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Normalize to a shape similar to our Entry model
|
// Normalize to a shape similar to our Entry model
|
||||||
const preview = {
|
const preview = {
|
||||||
tmdb_id: data.id,
|
tmdb_id: data.id,
|
||||||
@@ -192,6 +216,7 @@ class EntryController {
|
|||||||
networks: data.networks || [],
|
networks: data.networks || [],
|
||||||
homepage: data.homepage || null,
|
homepage: data.homepage || null,
|
||||||
imdb_id: data.imdb_id || data.external_ids?.imdb_id || null,
|
imdb_id: data.imdb_id || data.external_ids?.imdb_id || null,
|
||||||
|
credits,
|
||||||
};
|
};
|
||||||
|
|
||||||
res.status(200).json(preview);
|
res.status(200).json(preview);
|
||||||
|
|||||||
Reference in new issue
Block a user