Director field, search, and collection improvements
Backend: Added director column to Entry model, set during creation and refresh. Maintenance endpoint to scan/fix missing directors. Reverted expensive credit JOIN in getAllEntries. Frontend: @director: search prefix for Library and Watchlist. Director rendered on EntryDetailsPage via useEntryCredits. Fixed home page cards to link directly to EntryDetailsPage when entry is in library. Added TmdbCastsPage for TMDB cast browsing. Persisted collection sort order and gray-out-unseen toggle. Tooltip component now theme-aware.
This commit is contained in:
1 parent
8671184dc5
commit
5a0328a17f
16 files changed
+1679
-629
No files matched your search
@@ -26,7 +26,6 @@ const _mediaOptimizerService = mediaOptimizerService;
|
||||
const _networkService = networkService;
|
||||
|
||||
class EntryService {
|
||||
|
||||
constructor() {
|
||||
if (!EntryService.instance) {
|
||||
EntryService.instance = this;
|
||||
@@ -37,26 +36,23 @@ class EntryService {
|
||||
async getAllEntries() {
|
||||
const entries = await Entry.findAll({
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Network, as: 'networks' },
|
||||
{ model: EntryId, as: "entryId" },
|
||||
{ model: EntryRating, as: "entryRating" },
|
||||
{ model: Media, as: "medias" },
|
||||
{ model: Season, as: "seasons" },
|
||||
{ model: Network, as: "networks" },
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['name'], // Only fetch the genre name
|
||||
through: {
|
||||
attributes: [] // Do not fetch any attributes from the join table
|
||||
}
|
||||
}
|
||||
]
|
||||
as: "genres",
|
||||
attributes: ["name"],
|
||||
through: { attributes: [] },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// converting genres from object list to string list
|
||||
const entriesWithGenreNames = entries.map(entry => ({
|
||||
const entriesWithGenreNames = entries.map((entry) => ({
|
||||
...entry.get({ plain: true }),
|
||||
genres: entry.genres.map(genre => genre.name) // Convert genre objects to string array
|
||||
genres: entry.genres.map((genre) => genre.name),
|
||||
}));
|
||||
|
||||
return entriesWithGenreNames;
|
||||
@@ -78,31 +74,35 @@ class EntryService {
|
||||
|
||||
let entry = await Entry.findByPk(id, {
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{ model: Network, as: 'networks' },
|
||||
{ model: EntryId, as: "entryId" },
|
||||
{ model: EntryRating, as: "entryRating" },
|
||||
{ model: EntrySeen, as: "entrySeen" },
|
||||
{ model: Season, as: "seasons" },
|
||||
{ model: Media, as: "medias" },
|
||||
{ model: Network, as: "networks" },
|
||||
{
|
||||
model: Cast, as: 'credits',
|
||||
where: { cast_type: 'cast' },
|
||||
order: [['episode_count', 'DESC']],
|
||||
model: Cast,
|
||||
as: "credits",
|
||||
order: [
|
||||
["cast_type", "ASC"],
|
||||
["order", "ASC"],
|
||||
],
|
||||
limit: 10,
|
||||
include: [{ model: People, as: 'person' }]
|
||||
include: [{ model: People, as: "person" }],
|
||||
},
|
||||
{
|
||||
model: Collection, as: 'collections',
|
||||
include: [{ model: Media, as: 'medias' }]
|
||||
model: Collection,
|
||||
as: "collections",
|
||||
include: [{ model: Media, as: "medias" }],
|
||||
},
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['name', 'id'],
|
||||
through: { attributes: [] }
|
||||
}
|
||||
as: "genres",
|
||||
attributes: ["name", "id"],
|
||||
through: { attributes: [] },
|
||||
},
|
||||
],
|
||||
order: [[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC']]
|
||||
order: [[{ model: EntrySeen, as: "entrySeen" }, "date_seen", "DESC"]],
|
||||
});
|
||||
|
||||
if (!entry) {
|
||||
@@ -111,7 +111,7 @@ class EntryService {
|
||||
|
||||
if (plain) {
|
||||
const plainEntry = entry.get({ plain: true });
|
||||
plainEntry.genres = plainEntry.genres.map(g => g.name);
|
||||
plainEntry.genres = plainEntry.genres.map((g) => g.name);
|
||||
return plainEntry;
|
||||
}
|
||||
|
||||
@@ -130,28 +130,28 @@ class EntryService {
|
||||
throw new BadRequestError("Entry id not provided");
|
||||
}
|
||||
|
||||
const entry = await Entry.findByPk(id, { attributes: ['id'] });
|
||||
const entry = await Entry.findByPk(id, { attributes: ["id"] });
|
||||
if (!entry) {
|
||||
throw new NotFoundError("Entry with the provided id was not found");
|
||||
}
|
||||
|
||||
const credits = await Credit.findAll({
|
||||
where: { entry_id: id },
|
||||
include: [{ model: People, as: 'person' }],
|
||||
include: [{ model: People, as: "person" }],
|
||||
order: [
|
||||
['cast_type', 'ASC'],
|
||||
['order', 'ASC'],
|
||||
['episode_count', 'DESC'],
|
||||
["cast_type", "ASC"],
|
||||
["order", "ASC"],
|
||||
["episode_count", "DESC"],
|
||||
],
|
||||
});
|
||||
|
||||
return credits.map(c => c.get({ plain: true }));
|
||||
return credits.map((c) => c.get({ plain: true }));
|
||||
}
|
||||
|
||||
async createEntry(data, plain = true) {
|
||||
// creating the object
|
||||
var is_tvseries = data.release_date == null ? true : false;
|
||||
console.log('entryService > createEntry > is_tvseries: ', is_tvseries);
|
||||
console.log("entryService > createEntry > is_tvseries: ", is_tvseries);
|
||||
|
||||
let movie = Entry.build({
|
||||
title: data.title || data.name,
|
||||
@@ -162,7 +162,10 @@ class EntryService {
|
||||
|
||||
tagline: data.tagline || null,
|
||||
storyline: data.overview,
|
||||
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
|
||||
country:
|
||||
data.production_countries.length > 0
|
||||
? data.production_countries[0].name
|
||||
: null,
|
||||
|
||||
is_tvseries: is_tvseries,
|
||||
watchlist: true,
|
||||
@@ -173,12 +176,12 @@ class EntryService {
|
||||
poster_path: data.poster_path,
|
||||
banner_path: data.backdrop_path,
|
||||
|
||||
last_fetch: new Date()
|
||||
last_fetch: new Date(),
|
||||
});
|
||||
|
||||
let savedEntry = await movie.save();
|
||||
|
||||
console.log('entryService > createEntry > savedEntry: ', savedEntry);
|
||||
console.log("entryService > createEntry > savedEntry: ", savedEntry);
|
||||
|
||||
// ? ids
|
||||
await EntryId.create({
|
||||
@@ -191,15 +194,16 @@ class EntryService {
|
||||
data.genres.forEach(async (genre) => {
|
||||
await EntryGenre.create({
|
||||
genre_id: genre.id,
|
||||
entry_id: savedEntry.id
|
||||
})
|
||||
entry_id: savedEntry.id,
|
||||
});
|
||||
});
|
||||
|
||||
// ? networks
|
||||
if (data.networks) {
|
||||
for (const networkData of data.networks) {
|
||||
// Create or update the network
|
||||
const [oldNetwork, newNetwork] = await _networkService.createOrUpdateNetwork(networkData);
|
||||
const [oldNetwork, newNetwork] =
|
||||
await _networkService.createOrUpdateNetwork(networkData);
|
||||
let network = oldNetwork || newNetwork;
|
||||
if (!network) {
|
||||
throw new NotFoundError("Network not found");
|
||||
@@ -239,7 +243,7 @@ class EntryService {
|
||||
|
||||
poster_path: seasonData.poster_path,
|
||||
banner_path: null,
|
||||
})
|
||||
});
|
||||
|
||||
_mediaManager.getSeasonMedia(savedSeason);
|
||||
|
||||
@@ -269,10 +273,10 @@ class EntryService {
|
||||
|
||||
// TODO fetch cast
|
||||
|
||||
savedSeason.setDataValue('episodes', episodes);
|
||||
seasons.push(savedSeason)
|
||||
savedSeason.setDataValue("episodes", episodes);
|
||||
seasons.push(savedSeason);
|
||||
}
|
||||
savedEntry.setDataValue('seasons', seasons);
|
||||
savedEntry.setDataValue("seasons", seasons);
|
||||
}
|
||||
// + end of: seasons & episodes for tv series
|
||||
|
||||
@@ -283,21 +287,23 @@ class EntryService {
|
||||
}
|
||||
|
||||
const allCredits = [
|
||||
...creditData.cast.map(c => ({ ...c, cast_type: 'cast' })),
|
||||
...creditData.crew.map(c => ({ ...c, cast_type: 'crew' })),
|
||||
...creditData.cast.map((c) => ({ ...c, cast_type: "cast" })),
|
||||
...creditData.crew.map((c) => ({ ...c, cast_type: "crew" })),
|
||||
];
|
||||
|
||||
const tmdbIds = [...new Set(allCredits.map(c => c.id))];
|
||||
const tmdbIds = [...new Set(allCredits.map((c) => c.id))];
|
||||
|
||||
const existingPeopleList = await People.findAll({
|
||||
where: { tmdb_id: tmdbIds },
|
||||
});
|
||||
const existingPeopleMap = Object.fromEntries(existingPeopleList.map(p => [p.tmdb_id, p]));
|
||||
const existingPeopleMap = Object.fromEntries(
|
||||
existingPeopleList.map((p) => [p.tmdb_id, p]),
|
||||
);
|
||||
|
||||
const newPeopleData = tmdbIds
|
||||
.filter(id => !existingPeopleMap[id])
|
||||
.map(id => {
|
||||
const credit = allCredits.find(c => c.id === id);
|
||||
.filter((id) => !existingPeopleMap[id])
|
||||
.map((id) => {
|
||||
const credit = allCredits.find((c) => c.id === id);
|
||||
return {
|
||||
tmdb_id: credit.id,
|
||||
name: credit.name,
|
||||
@@ -306,7 +312,7 @@ class EntryService {
|
||||
known_for_department: credit.known_for_department || null,
|
||||
profile_path: credit.profile_path,
|
||||
adult: credit.adult || false,
|
||||
last_fetch: new Date()
|
||||
last_fetch: new Date(),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -315,41 +321,55 @@ class EntryService {
|
||||
existingPeopleMap[person.tmdb_id] = person;
|
||||
}
|
||||
|
||||
const newCredits = allCredits.map(c => {
|
||||
const newCredits = allCredits.map((c) => {
|
||||
const person = existingPeopleMap[c.id];
|
||||
return {
|
||||
entry_id: savedEntry.id,
|
||||
people_id: person.id,
|
||||
tmdb_credit_id: c.credit_id,
|
||||
character: c.cast_type === 'cast' ? c.character : null,
|
||||
order: c.cast_type === 'cast' ? c.order : null,
|
||||
character: c.cast_type === "cast" ? c.character : null,
|
||||
order: c.cast_type === "cast" ? c.order : null,
|
||||
profile_path: person.profile_path || null,
|
||||
adult: person.adult || false,
|
||||
cast_type: c.cast_type,
|
||||
department: c.cast_type === 'crew' ? c.department || null : null,
|
||||
job: c.cast_type === 'crew' ? c.job || null : null,
|
||||
department: c.cast_type === "crew" ? c.department || null : null,
|
||||
job: c.cast_type === "crew" ? c.job || null : null,
|
||||
};
|
||||
});
|
||||
|
||||
await Credit.bulkCreate(newCredits);
|
||||
|
||||
savedEntry.credit_fetched = true;
|
||||
|
||||
// Extract director name from credits
|
||||
const directorData = allCredits.find(
|
||||
(c) => c.cast_type === "crew" && c.job === "Director",
|
||||
);
|
||||
savedEntry.director = directorData?.name || null;
|
||||
|
||||
await savedEntry.save();
|
||||
|
||||
// ? media
|
||||
const downloadedImages = await _mediaManager.getEntryMedia(data.id, is_tvseries);
|
||||
const downloadedImages = await _mediaManager.getEntryMedia(
|
||||
data.id,
|
||||
is_tvseries,
|
||||
);
|
||||
// console.log(`entry service, downloaded images: `, downloadedImages)
|
||||
for (const image of downloadedImages) {
|
||||
await Media.create({
|
||||
mediaable: 'entry',
|
||||
mediaable: "entry",
|
||||
mediaableId: savedEntry.id,
|
||||
type: image.type,
|
||||
path: image.path,
|
||||
isLocal: true,
|
||||
isSelected: true
|
||||
isSelected: true,
|
||||
});
|
||||
|
||||
_mediaOptimizerService.doGeneratePreview('entries', image.type + 's', image.path);
|
||||
_mediaOptimizerService.doGeneratePreview(
|
||||
"entries",
|
||||
image.type + "s",
|
||||
image.path,
|
||||
);
|
||||
}
|
||||
|
||||
// const currentGenresNames = await data.genres.map(genre => genre.name);
|
||||
@@ -372,7 +392,7 @@ class EntryService {
|
||||
const oldEntry = await Entry.findByPk(id);
|
||||
|
||||
if (!oldEntry) {
|
||||
throw new NotFoundError("Entry with the provided id was not found")
|
||||
throw new NotFoundError("Entry with the provided id was not found");
|
||||
}
|
||||
|
||||
await oldEntry.update(entryData);
|
||||
@@ -388,23 +408,26 @@ class EntryService {
|
||||
}
|
||||
|
||||
let entry = await Entry.findByPk(id, {
|
||||
include: [
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
]
|
||||
include: [{ model: EntryRating, as: "entryRating" }],
|
||||
});
|
||||
|
||||
if (!entry) {
|
||||
throw new NotFoundError("Entry with the provided id was not found")
|
||||
throw new NotFoundError("Entry with the provided id was not found");
|
||||
}
|
||||
|
||||
if (entry.entryRating.id != entryRatingsData.id) {
|
||||
throw new BadRequestError("EntryRatings id does not match");
|
||||
}
|
||||
|
||||
entry.entryRating.user_rating = entryRatingsData.user_rating ?? entry.entryRating.user_rating;
|
||||
entry.entryRating.tmdb_rating = entryRatingsData.tmdb_rating ?? entry.entryRating.tmdb_rating;
|
||||
entry.entryRating.imdb_rating = entryRatingsData.imdb_rating ?? entry.entryRating.imdb_rating;
|
||||
entry.entryRating.rotten_tomatoes_rating = entryRatingsData.rotten_tomatoes_rating ?? entry.entryRating.rotten_tomatoes_rating;
|
||||
entry.entryRating.user_rating =
|
||||
entryRatingsData.user_rating ?? entry.entryRating.user_rating;
|
||||
entry.entryRating.tmdb_rating =
|
||||
entryRatingsData.tmdb_rating ?? entry.entryRating.tmdb_rating;
|
||||
entry.entryRating.imdb_rating =
|
||||
entryRatingsData.imdb_rating ?? entry.entryRating.imdb_rating;
|
||||
entry.entryRating.rotten_tomatoes_rating =
|
||||
entryRatingsData.rotten_tomatoes_rating ??
|
||||
entry.entryRating.rotten_tomatoes_rating;
|
||||
|
||||
return await entry.entryRating.save();
|
||||
}
|
||||
@@ -415,13 +438,11 @@ class EntryService {
|
||||
}
|
||||
|
||||
let entry = await Entry.findByPk(id, {
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
]
|
||||
include: [{ model: EntryId, as: "entryId" }],
|
||||
});
|
||||
|
||||
if (!entry) {
|
||||
throw new NotFoundError("Entry with the provided id was not found")
|
||||
throw new NotFoundError("Entry with the provided id was not found");
|
||||
}
|
||||
|
||||
if (entry.entryRating.id != entryRatingsData.id) {
|
||||
@@ -441,11 +462,11 @@ class EntryService {
|
||||
}
|
||||
|
||||
const deletedCount = await Entry.destroy({
|
||||
where: { id: id }
|
||||
where: { id: id },
|
||||
});
|
||||
|
||||
if (deletedCount == 0) {
|
||||
throw new NotFoundError("Entry with the provided id was not found")
|
||||
throw new NotFoundError("Entry with the provided id was not found");
|
||||
}
|
||||
|
||||
return deletedCount;
|
||||
@@ -458,30 +479,29 @@ class EntryService {
|
||||
|
||||
const entry = await Entry.findByPk(id);
|
||||
if (!entry) {
|
||||
throw new NotFoundError("Entry with the provided id was not found")
|
||||
throw new NotFoundError("Entry with the provided id was not found");
|
||||
}
|
||||
|
||||
const seasons = await Season.findAll({
|
||||
where: {
|
||||
entry_id: id
|
||||
entry_id: id,
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Episode, as: 'episodes', include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
model: Episode,
|
||||
as: "episodes",
|
||||
include: [{ model: Media, as: "medias" }],
|
||||
},
|
||||
{ model: Media, as: 'medias' }
|
||||
{ model: Media, as: "medias" },
|
||||
],
|
||||
order: [
|
||||
['season_number', 'ASC'],
|
||||
[{ model: Episode, as: 'episodes' }, 'episode_number', 'ASC'],
|
||||
]
|
||||
})
|
||||
["season_number", "ASC"],
|
||||
[{ model: Episode, as: "episodes" }, "episode_number", "ASC"],
|
||||
],
|
||||
});
|
||||
|
||||
return seasons;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new EntryService();
|
||||
Reference in new issue
Block a user