Merge branch 'react-frontend' of https://github.com/X4Lo/Showy into react-frontend

This commit is contained in:
X4Lo committed 2026-04-27 04:03:39 +01:00
commit 23bce5a681
31 files changed
+1148 -214

No files matched your search

+38 -3
View File
@@ -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();
+21 -1
View File
@@ -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