Merge branch 'react-frontend' of https://github.com/X4Lo/Showy into react-frontend
This commit is contained in:
commit
23bce5a681
31 files changed
+1148
-214
No files matched your search
@@ -1,12 +1,14 @@
|
||||
const { Sequelize } = require("sequelize");
|
||||
const sequelize = require("../config/database");
|
||||
const Collection = require("../models/Collection");
|
||||
const Entry = require("../models/Entry");
|
||||
const Genre = require("../models/Genre");
|
||||
const Media = require("../models/Media");
|
||||
|
||||
|
||||
async function initializeData() {
|
||||
initializeGenres();
|
||||
//markEntriesRequireCreditsSync();
|
||||
// migrateAccuracyField();
|
||||
}
|
||||
|
||||
@@ -31,6 +33,20 @@ async function initializeData() {
|
||||
// console.log(collections);
|
||||
// }
|
||||
|
||||
async function markEntriesRequireCreditsSync() {
|
||||
try {
|
||||
const [affectedCount] = await Entry.update(
|
||||
{ entry_sync_status: 'RequireCreditsSync' },
|
||||
{ where: { entry_sync_status: null } }
|
||||
);
|
||||
if (affectedCount > 0) {
|
||||
console.log(`Marked ${affectedCount} entries as RequireCreditsSync`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error marking entries for credits sync:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function initializeGenres() {
|
||||
try {
|
||||
// * data to insert:
|
||||
@@ -84,8 +100,8 @@ async function initializeGenres() {
|
||||
|
||||
module.exports = {
|
||||
initializeData,
|
||||
|
||||
initializeGenres,
|
||||
markEntriesRequireCreditsSync,
|
||||
}
|
||||
|
||||
// async function migrateAccuracyField() {
|
||||
|
||||
@@ -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();
|
||||
@@ -35,6 +35,16 @@ class MaintenanceController {
|
||||
return res.status(200).json(deleted);
|
||||
}
|
||||
|
||||
async getOrphanPeople(req, res) {
|
||||
const result = await _maintenanceService.deleteOrphanPeople(true);
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
async deleteOrphanPeople(req, res) {
|
||||
const result = await _maintenanceService.deleteOrphanPeople();
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new MaintenanceController();
|
||||
@@ -50,8 +50,8 @@ class PeopleController {
|
||||
}
|
||||
|
||||
async fetchAndSavePersonByTmdbId(req, res) {
|
||||
const { tmdb_id } = req.body;
|
||||
const person = await _peopleService.fetchAndSavePersonByTmdbId(tmdb_id);
|
||||
const { tmdb_id, pinned } = req.body;
|
||||
const person = await _peopleService.fetchAndSavePersonByTmdbId(tmdb_id, { pinned: !!pinned });
|
||||
res.status(201).json(person);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@ const Entry = sequelize.define("entry",
|
||||
date_last_seen: { type: DataTypes.DATEONLY, field: 'date_last_seen' },
|
||||
|
||||
last_fetch: { type: DataTypes.DATEONLY },
|
||||
|
||||
entry_sync_status: { type: DataTypes.STRING(50), field: 'entry_sync_status', allowNull: true },
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = Entry;
|
||||
module.exports = Entry;
|
||||
@@ -27,7 +27,9 @@ const People = sequelize.define("peoples",
|
||||
last_fetch: { type: DataTypes.DATEONLY, field: 'last_fetch' },
|
||||
profile_update: { type: DataTypes.DATEONLY, field: 'profile_update' },
|
||||
fully_fetched: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||
favorite: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||
pinned: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = People;
|
||||
module.exports = People;
|
||||
@@ -17,6 +17,7 @@ entryRouter.get('/tmdb/popular/:type', entryController.getTmdbPopular);
|
||||
entryRouter.get('/tmdb/top-rated/:type', entryController.getTmdbTopRated);
|
||||
entryRouter.get('/tmdb/upcoming/movie', entryController.getTmdbUpcoming);
|
||||
entryRouter.get('/tmdb/search', entryController.getTmdbSearch);
|
||||
entryRouter.get('/tmdb/preview/:type/:tmdbId', entryController.getTmdbPreview);
|
||||
|
||||
entryRouter.get('/sync-series', entryController.syncSeries);
|
||||
|
||||
|
||||
@@ -16,4 +16,10 @@ maintenanceRouter.delete('/orphan-files', maintenanceController.deleteOrpanFiles
|
||||
// * DELETE - Missing files
|
||||
maintenanceRouter.delete('/orphan-media-records', maintenanceController.deleteOrphanMediaRecords);
|
||||
|
||||
// * GET - Orphan people (dry run)
|
||||
maintenanceRouter.get('/orphan-people', maintenanceController.getOrphanPeople);
|
||||
|
||||
// * DELETE - Orphan people
|
||||
maintenanceRouter.delete('/orphan-people', maintenanceController.deleteOrphanPeople);
|
||||
|
||||
module.exports = maintenanceRouter;
|
||||
@@ -3,6 +3,8 @@ const fsPromises = require('fs').promises;
|
||||
const fs = require('fs');
|
||||
|
||||
const Media = require("../models/Media");
|
||||
const People = require("../models/People");
|
||||
const Credit = require("../models/Credit");
|
||||
|
||||
const { logToFile } = require('./logService');
|
||||
const configService = require('./configService');
|
||||
@@ -18,9 +20,9 @@ class MaintenanceService {
|
||||
return MaintenanceService.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete orphan media records from database,
|
||||
* these are media records that exist in the database
|
||||
* these are media records that exist in the database
|
||||
* but do not have a file in the `user data folder`.
|
||||
* @param {boolean} [dry=false] - if true only return the count of the files that are getting deleted, default=`false`
|
||||
*/
|
||||
@@ -71,7 +73,7 @@ class MaintenanceService {
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete orphan files from media folder data,
|
||||
* orphan files are files that exist in the `folder data`
|
||||
* but do not have an instance in the database
|
||||
@@ -142,6 +144,39 @@ class MaintenanceService {
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete orphan people from the database.
|
||||
* Orphan people are those not linked to any entry via credits
|
||||
* AND not manually pinned.
|
||||
* @param {boolean} [dry=false] - if true only return the count
|
||||
*/
|
||||
async deleteOrphanPeople(dry = false) {
|
||||
const { Sequelize } = require('sequelize');
|
||||
|
||||
// Find all people who have no credits and are not pinned
|
||||
const allPeople = await People.findAll({
|
||||
include: [{
|
||||
model: Credit,
|
||||
as: 'roles',
|
||||
required: false,
|
||||
}],
|
||||
});
|
||||
|
||||
const orphans = allPeople.filter(p => (!p.roles || p.roles.length === 0) && !p.pinned);
|
||||
|
||||
if (!dry) {
|
||||
for (const person of orphans) {
|
||||
await person.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
const count = orphans.length;
|
||||
if (dry) logToFile(`Run a dry orphan people check, found: ${count}`);
|
||||
else logToFile(`Run orphan people cleanup, deleted: ${count}`);
|
||||
|
||||
return { count };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new MaintenanceService();
|
||||
@@ -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