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
@@ -2,6 +2,7 @@ const People = require("../models/People");
|
||||
const Credit = require("../models/Credit");
|
||||
const Entry = require("../models/Entry");
|
||||
const Media = require("../models/Media");
|
||||
const { Op } = require("sequelize");
|
||||
const { fetchPersonDetails: fetchPersonData } = require("./tmdbService");
|
||||
const mediaDownloaderService = require("./mediaDownloaderService");
|
||||
const { logToFile } = require("./logService");
|
||||
@@ -92,6 +93,20 @@ class PeopleService {
|
||||
return person;
|
||||
}
|
||||
|
||||
async searchPeople(query) {
|
||||
const people = await People.findAll({
|
||||
where: {
|
||||
name: { [Op.like]: `%${query}%` }
|
||||
},
|
||||
order: [["popularity", "DESC"]],
|
||||
limit: 20,
|
||||
include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
});
|
||||
return people;
|
||||
}
|
||||
|
||||
async createPerson(personData) {
|
||||
try {
|
||||
const existingPerson = await People.findOne({
|
||||
@@ -160,7 +175,7 @@ class PeopleService {
|
||||
return { success: true, message: `Person with ID ${id} was deleted` };
|
||||
}
|
||||
|
||||
async fetchAndSavePersonByTmdbId(tmdbId) {
|
||||
async fetchAndSavePersonByTmdbId(tmdbId, options = {}) {
|
||||
if (!tmdbId) {
|
||||
throw new BadRequestError("TMDB ID is required");
|
||||
}
|
||||
@@ -169,6 +184,10 @@ class PeopleService {
|
||||
let person = await this.getPersonByTmdbId(tmdbId);
|
||||
|
||||
if (person) {
|
||||
// If manually added (pinned), mark it
|
||||
if (options.pinned && !person.pinned) {
|
||||
await person.update({ pinned: true });
|
||||
}
|
||||
// If person exists but hasn't been fully fetched, we'll update it
|
||||
if (!person.fully_fetched) {
|
||||
const personData = await fetchPersonData(tmdbId);
|
||||
@@ -199,6 +218,7 @@ class PeopleService {
|
||||
...personData,
|
||||
fully_fetched: true,
|
||||
last_fetch: new Date(),
|
||||
pinned: !!options.pinned,
|
||||
});
|
||||
|
||||
// Download profile image if available
|
||||
|
||||
Reference in new issue
Block a user