From 80fa953f607589d80396e9343d17de6893fcdfbe Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Fri, 5 Feb 2021 04:14:13 +0100 Subject: [PATCH] Added movie flush. --- src/argv.js | 4 ++++ src/releases.js | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/argv.js b/src/argv.js index ac04f296..528b4e75 100644 --- a/src/argv.js +++ b/src/argv.js @@ -287,6 +287,10 @@ const { argv } = yargs describe: 'Remove all scenes.', type: 'boolean', }) + .option('flush-movies', { + describe: 'Remove all movies.', + type: 'boolean', + }) .option('delete-scenes', { describe: 'Remove scenes by ID.', type: 'array', diff --git a/src/releases.js b/src/releases.js index e92dfaf0..ec5ea8de 100644 --- a/src/releases.js +++ b/src/releases.js @@ -159,6 +159,24 @@ async function deleteScenes(sceneIds) { return deleteCount; } +async function deleteMovies(movieIds) { + if (movieIds.length === 0) { + return 0; + } + + await knex('movies_scenes') + .whereIn('movie_id', movieIds) + .delete(); + + const deleteCount = await knex('movies') + .whereIn('id', movieIds) + .delete(); + + logger.info(`Removed ${deleteCount}/${movieIds.length} movies`); + + return deleteCount; +} + async function flushScenes() { const sceneIds = await knex('releases').select('id').pluck('id'); @@ -180,18 +198,25 @@ async function flushScenes() { logger.info(`Removed ${deleteCount}/${sceneIds.length} scenes`); } -async function deleteMovies(movieIds) { - if (movieIds.length === 0) { - return 0; - } +async function flushMovies() { + const movieIds = await knex('movies').select('id').pluck('id'); - const deleteCount = await knex('movies') - .whereIn('id', movieIds) - .delete(); + const confirmed = await inquirer.prompt([{ + type: 'confirm', + name: 'flushMovies', + message: `You are about to remove ${movieIds.length} movies. Are you sure?`, + default: false, + }]); + + if (!confirmed.flushScenes) { + logger.warn('Confirmation rejected, not flushing scenes'); + return; + } + const deleteCount = await deleteMovies(movieIds); + + await flushOrphanedMedia(); logger.info(`Removed ${deleteCount}/${movieIds.length} movies`); - - return deleteCount; } async function flushBatches(batchIds) { @@ -233,6 +258,7 @@ module.exports = { fetchScene, fetchScenes, flushBatches, + flushMovies, flushScenes, searchScenes, deleteScenes,