From 80b8fe36542400f36c3520cfc7223a6c24b36b05 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Fri, 5 Feb 2021 04:23:13 +0100 Subject: [PATCH] Added actor flush, renamed inconsistent actor flush to actor delete. --- src/actors.js | 26 +++++++++++++++++++++++++- src/app.js | 6 +++++- src/argv.js | 7 ++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/actors.js b/src/actors.js index ad3d1611..16c3263f 100644 --- a/src/actors.js +++ b/src/actors.js @@ -8,6 +8,7 @@ const blake2 = require('blake2'); const DOMPurify = require('dompurify'); const { JSDOM } = require('jsdom'); const omit = require('object.omit'); +const inquirer = require('inquirer'); const { window } = new JSDOM(''); const domPurify = DOMPurify(window); @@ -973,7 +974,7 @@ async function flushProfiles(actorIdsOrNames) { logger.info(`Removed ${deleteCount} profiles`); } -async function flushActors(actorIdsOrNames) { +async function deleteActors(actorIdsOrNames) { const actors = await knex('actors') .whereIn('id', actorIdsOrNames.filter(idOrName => typeof idOrName === 'number')) .orWhere((builder) => { @@ -1002,8 +1003,31 @@ async function flushActors(actorIdsOrNames) { logger.info(`Removed ${deletedActorsCount} actors with ${deletedScenesCount} scenes`); } +async function flushActors() { + const actorIds = await knex('actors').select('id').pluck('id'); + + const confirmed = await inquirer.prompt([{ + type: 'confirm', + name: 'flushActors', + message: `You are about to remove ${actorIds.length} actors. Are you sure?`, + default: false, + }]); + + if (!confirmed.flushActors) { + logger.warn('Confirmation rejected, not flushing actors'); + return; + } + + const deleteCount = await deleteActors(actorIds); + + await flushOrphanedMedia(); + + logger.info(`Removed ${deleteCount}/${actorIds.length} actors`); +} + module.exports = { associateActors, + deleteActors, fetchActor, flushActors, flushProfiles, diff --git a/src/app.js b/src/app.js index df72a503..f44be31a 100644 --- a/src/app.js +++ b/src/app.js @@ -9,7 +9,7 @@ const knex = require('./knex'); const fetchUpdates = require('./updates'); const { fetchScenes, fetchMovies } = require('./deep'); const { storeScenes, storeMovies, updateReleasesSearch, associateMovieScenes } = require('./store-releases'); -const { scrapeActors, flushActors, flushProfiles, interpolateProfiles } = require('./actors'); +const { scrapeActors, deleteActors, flushActors, flushProfiles, interpolateProfiles } = require('./actors'); const { flushEntities } = require('./entities'); const { deleteScenes, deleteMovies, flushScenes, flushMovies, flushBatches } = require('./releases'); const { flushOrphanedMedia } = require('./media'); @@ -53,6 +53,10 @@ async function init() { await flushMovies(); } + if (argv.deleteActors) { + await deleteActors(argv.deleteActors); + } + if (argv.deleteScenes) { await deleteScenes(argv.deleteScenes); } diff --git a/src/argv.js b/src/argv.js index 528b4e75..1dda020f 100644 --- a/src/argv.js +++ b/src/argv.js @@ -269,7 +269,7 @@ const { argv } = yargs alias: 'flush-network', }) .option('flush-actors', { - describe: 'Delete actors with profiles and scenes.', + describe: 'Flush all actors and their scenes.', type: 'array', alias: 'flush-actor', }) @@ -291,6 +291,11 @@ const { argv } = yargs describe: 'Remove all movies.', type: 'boolean', }) + .option('delete-actors', { + describe: 'Remove actors by ID.', + type: 'array', + alias: ['delete-actor', 'remove-actors', 'remove-actor'], + }) .option('delete-scenes', { describe: 'Remove scenes by ID.', type: 'array',