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:
X4Lo committed 2026-06-18 20:09:11 +01:00
1 parent 8671184dc5
commit 5a0328a17f
16 files changed
+1679 -629

No files matched your search

+123 -51
View File
@@ -1,18 +1,18 @@
const path = require('path');
const fsPromises = require('fs').promises;
const fs = require('fs');
const path = require("path");
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 Entry = require("../models/Entry");
const { logToFile } = require('./logService');
const configService = require('./configService');
const { logToFile } = require("./logService");
const configService = require("./configService");
const _configService = configService;
class MaintenanceService {
constructor() {
if (!MaintenanceService.instance) {
MaintenanceService.instance = this;
@@ -21,26 +21,36 @@ class MaintenanceService {
}
/**
* Delete orphan media records from 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`
*/
* Delete orphan media records from 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`
*/
async deleteOrphanMediaRecords(dry = false) {
const allMedia = await Media.findAll();
const dataPath = await _configService.getMediaFolder();
const mediaTypeFolder = {
'entry;poster': path.join(dataPath, 'images', 'entries', 'posters'),
'entry;logo': path.join(dataPath, 'images', 'entries', 'logos'),
'entry;backdrop': path.join(dataPath, 'images', 'entries', 'backdrops'),
"entry;poster": path.join(dataPath, "images", "entries", "posters"),
"entry;logo": path.join(dataPath, "images", "entries", "logos"),
"entry;backdrop": path.join(dataPath, "images", "entries", "backdrops"),
'collection;poster': path.join(dataPath, 'images', 'collections', 'posters'),
'collection;backdrop': path.join(dataPath, 'images', 'collections', 'backdrops'),
"collection;poster": path.join(
dataPath,
"images",
"collections",
"posters",
),
"collection;backdrop": path.join(
dataPath,
"images",
"collections",
"backdrops",
),
'season;poster': path.join(dataPath, 'images', 'seasons', 'posters'),
'episode;still': path.join(dataPath, 'images', 'episodes', 'stills')
"season;poster": path.join(dataPath, "images", "seasons", "posters"),
"episode;still": path.join(dataPath, "images", "episodes", "stills"),
};
let missingFiles = [];
@@ -49,26 +59,32 @@ class MaintenanceService {
if (!mediaTypeFolder[folderType]) continue;
const filePath = path.join(mediaTypeFolder[folderType], allMedia[i].path)
const filePath = path.join(mediaTypeFolder[folderType], allMedia[i].path);
if (!fs.existsSync(filePath)) {
missingFiles.push(allMedia[i]);
}
}
let removed = {
'posters': 0,
'logos': 0,
'backdrops': 0,
'stills': 0,
posters: 0,
logos: 0,
backdrops: 0,
stills: 0,
};
for (let i = 0; i < missingFiles.length; i++) {
removed[missingFiles[i].type + 's'] += 1;
removed[missingFiles[i].type + "s"] += 1;
if (!dry) missingFiles[i].destroy();
}
if (dry) logToFile(`Run a dry missing files check, found: {posters: ${removed.posters}, backdrops: ${removed.backdrops}, logos: ${removed.logos}}`)
else logToFile(`Run an missing files cleanup, deleted: {posters: ${removed.posters}, backdrops: ${removed.backdrops}, logos: ${removed.logos}}`)
if (dry)
logToFile(
`Run a dry missing files check, found: {posters: ${removed.posters}, backdrops: ${removed.backdrops}, logos: ${removed.logos}}`,
);
else
logToFile(
`Run an missing files cleanup, deleted: {posters: ${removed.posters}, backdrops: ${removed.backdrops}, logos: ${removed.logos}}`,
);
return removed;
}
@@ -83,30 +99,40 @@ class MaintenanceService {
const dataPath = _configService.getMediaFolder();
// ? Getting the name (without extention) of all media in database
const allMedia = (await Media.findAll()).map(m => {
return m.path.split('.')[0]
const allMedia = (await Media.findAll()).map((m) => {
return m.path.split(".")[0];
});
// ? Loop trough the files of the images folder and check
// ? if a file doesnt exist in the allMedia array and mark it to delete
const mediaTypeFolder = {
'entry;poster': path.join(dataPath, 'images', 'entries', 'posters'),
'entry;logo': path.join(dataPath, 'images', 'entries', 'logos'),
'entry;backdrop': path.join(dataPath, 'images', 'entries', 'backdrops'),
"entry;poster": path.join(dataPath, "images", "entries", "posters"),
"entry;logo": path.join(dataPath, "images", "entries", "logos"),
"entry;backdrop": path.join(dataPath, "images", "entries", "backdrops"),
'collection;poster': path.join(dataPath, 'images', 'collections', 'posters'),
'collection;backdrop': path.join(dataPath, 'images', 'collections', 'backdrops'),
"collection;poster": path.join(
dataPath,
"images",
"collections",
"posters",
),
"collection;backdrop": path.join(
dataPath,
"images",
"collections",
"backdrops",
),
'season;poster': path.join(dataPath, 'images', 'seasons', 'posters'),
'episode;still': path.join(dataPath, 'images', 'episodes', 'stills')
"season;poster": path.join(dataPath, "images", "seasons", "posters"),
"episode;still": path.join(dataPath, "images", "episodes", "stills"),
};
// * counter
let removed = {
'posters': 0,
'logos': 0,
'backdrops': 0,
'stills': 0,
posters: 0,
logos: 0,
backdrops: 0,
stills: 0,
};
// Iterate over each media type directory and check for orphan files
@@ -119,14 +145,13 @@ class MaintenanceService {
// Check each file in the directory
for (let file of files) {
// preparing the file name
const fileName = file.split('.')[0].replace("_preview", "");
const fileName = file.split(".")[0].replace("_preview", "");
const isInDatabase = allMedia.includes(fileName);
// if the file isn't in database even on other extentions then delete it
if (!isInDatabase) {
removed[folderType.split(';')[1] + 's']++; // Increment the count of removed files
removed[folderType.split(";")[1] + "s"]++; // Increment the count of removed files
if (!dry) {
const filePath = path.join(directory, file);
await fsPromises.unlink(filePath);
@@ -138,8 +163,14 @@ class MaintenanceService {
}
}
if (dry) logToFile(`Run a dry orphan files check, found: {posters: ${removed.posters}, backdrops: ${removed.backdrops}, logos: ${removed.logos}}`)
else logToFile(`Run an orphan files cleanup, deleted: {posters: ${removed.posters}, backdrops: ${removed.backdrops}, logos: ${removed.logos}}`)
if (dry)
logToFile(
`Run a dry orphan files check, found: {posters: ${removed.posters}, backdrops: ${removed.backdrops}, logos: ${removed.logos}}`,
);
else
logToFile(
`Run an orphan files cleanup, deleted: {posters: ${removed.posters}, backdrops: ${removed.backdrops}, logos: ${removed.logos}}`,
);
return removed;
}
@@ -151,18 +182,22 @@ class MaintenanceService {
* @param {boolean} [dry=false] - if true only return the count
*/
async deleteOrphanPeople(dry = false) {
const { Sequelize } = require('sequelize');
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,
}],
include: [
{
model: Credit,
as: "roles",
required: false,
},
],
});
const orphans = allPeople.filter(p => (!p.roles || p.roles.length === 0) && !p.pinned);
const orphans = allPeople.filter(
(p) => (!p.roles || p.roles.length === 0) && !p.pinned,
);
if (!dry) {
for (const person of orphans) {
@@ -177,6 +212,43 @@ class MaintenanceService {
return { count };
}
/**
* Count entries missing a director, and optionally fix them.
* @param {boolean} [dry=false] - if true only count, if false also fix
*/
async fixMissingDirectors(dry = false) {
const entries = await Entry.findAll({
where: { director: null },
include: [
{
model: Credit,
as: "credits",
where: { cast_type: "crew", job: "Director" },
include: [{ model: People, as: "person", attributes: ["name"] }],
required: false,
},
],
});
const count = entries.length;
let fixed = 0;
if (!dry) {
for (const entry of entries) {
const dirName = entry.credits?.[0]?.person?.name || null;
if (dirName) {
entry.director = dirName;
await entry.save();
fixed++;
}
}
}
if (dry) logToFile(`Dry missing directors check: ${count}`);
else logToFile(`Fixed missing directors: ${fixed} of ${count}`);
return { count, fixed };
}
}
module.exports = new MaintenanceService();