Unify entry page for TMDB previews and add artwork section
- Entry details page now also renders entries not in the library, using the TMDB preview mapped to the same entry shape; remove TmdbPreviewPage - Preview endpoint returns an entry-shaped object, TMDB seasons and directors - Artwork section: TMDB posters, backdrops and logos merged with the media table, with in-library badges, language filter and add-to-library - Record tmdb_path on downloaded media so TMDB images can be matched - Recommendations by TMDB id for entries not in the library
This commit is contained in:
1 parent
a9ff2d089a
commit
28eee34548
19 files changed
+1190
-411
No files matched your search
@@ -3,6 +3,12 @@ const collectionManager = require("../services/collectionManager");
|
||||
const entryManager = require("../services/entryManager");
|
||||
const entryService = require("../services/entryService");
|
||||
const tmdbService = require("../services/tmdbService");
|
||||
const artworkService = require("../services/artworkService");
|
||||
const {
|
||||
mapEntryFields,
|
||||
mapEntryIds,
|
||||
mapEntryRatings,
|
||||
} = require("../mappers/entryMapper");
|
||||
const asyncWrapper = require("../utils/asyncWrapper");
|
||||
|
||||
const _collectionManager = collectionManager;
|
||||
@@ -145,6 +151,40 @@ class EntryController {
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
// * GET - TMDB RECOMMENDATIONS BY TMDB ID (entries not in the library)
|
||||
getTmdbRecommendations = asyncWrapper(async (req, res) => {
|
||||
const { type, tmdbId } = req.params;
|
||||
const data = await tmdbService.fetchEntryRecommendations(
|
||||
tmdbId,
|
||||
type === "tv",
|
||||
req.query.page || 1,
|
||||
);
|
||||
if (!data)
|
||||
return res
|
||||
.status(500)
|
||||
.json({ message: "Failed to fetch recommendations" });
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
// * GET - ARTWORK: TMDB images merged with the entry's media table
|
||||
getEntryArtwork = asyncWrapper(async (req, res) => {
|
||||
const artwork = await artworkService.getEntryArtwork(req.params.id);
|
||||
res.status(200).json(artwork);
|
||||
});
|
||||
|
||||
// * POST - ARTWORK: download a TMDB image into the entry's media table
|
||||
addEntryArtwork = asyncWrapper(async (req, res) => {
|
||||
const media = await artworkService.addEntryArtwork(req.params.id, req.body);
|
||||
res.status(201).json(media);
|
||||
});
|
||||
|
||||
// * GET - ARTWORK BY TMDB ID (entries not in the library)
|
||||
getTmdbArtwork = asyncWrapper(async (req, res) => {
|
||||
const { type, tmdbId } = req.params;
|
||||
const artwork = await artworkService.getTmdbArtwork(type, tmdbId);
|
||||
res.status(200).json(artwork);
|
||||
});
|
||||
|
||||
// * PUT - REQUEST COLLECTION REFRECH
|
||||
fetchEntryCollection = asyncWrapper(async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
@@ -242,6 +282,59 @@ class EntryController {
|
||||
}
|
||||
}
|
||||
|
||||
// Directors, so the preview page can show "Directed by"
|
||||
for (const c of creditsData?.crew ?? []) {
|
||||
const jobs = Array.isArray(c.jobs) ? c.jobs.map((j) => j.job) : [c.job];
|
||||
if (!jobs.includes("Director")) continue;
|
||||
credits.push({
|
||||
id: c.credit_id || c.jobs?.[0]?.credit_id || "crew-" + c.id,
|
||||
cast_type: "crew",
|
||||
job: "Director",
|
||||
department: "Directing",
|
||||
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,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Same shape as a library entry, so the details page can render either
|
||||
const entry = {
|
||||
id: 0,
|
||||
...mapEntryFields(data),
|
||||
is_tvseries: is_tvserie,
|
||||
isInLibrary: false,
|
||||
entryIds: { tmdb_id: data.id, ...mapEntryIds(data) },
|
||||
entryRatings: {
|
||||
user_rating: null,
|
||||
imdb_rating: null,
|
||||
rotten_tomatoes_rating: null,
|
||||
...mapEntryRatings(data),
|
||||
},
|
||||
genres: data.genres || [],
|
||||
networks: (data.networks || []).map((n) => ({
|
||||
id: n.id,
|
||||
name: n.name,
|
||||
origin_country: n.origin_country || null,
|
||||
logo_path: n.logo_path || null,
|
||||
homepage: null,
|
||||
})),
|
||||
};
|
||||
const seasons = (data.seasons || []).map((s) => ({
|
||||
id: s.id,
|
||||
name: s.name,
|
||||
season_number: s.season_number,
|
||||
episode_count: s.episode_count,
|
||||
air_date: s.air_date,
|
||||
poster_path: s.poster_path,
|
||||
overview: s.overview,
|
||||
tmdb_rating: s.vote_average,
|
||||
}));
|
||||
|
||||
// Normalize to a shape similar to our Entry model
|
||||
const preview = {
|
||||
tmdb_id: data.id,
|
||||
@@ -267,6 +360,8 @@ class EntryController {
|
||||
homepage: data.homepage || null,
|
||||
imdb_id: data.imdb_id || data.external_ids?.imdb_id || null,
|
||||
credits,
|
||||
entry,
|
||||
seasons,
|
||||
};
|
||||
|
||||
res.status(200).json(preview);
|
||||
|
||||
Reference in new issue
Block a user