forked from DebaucheryLibrarian/traxxx
Added rudimentary scene and entity scene remove.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const config = require('config');
|
||||
const inquirer = require('inquirer');
|
||||
|
||||
const logger = require('./logger')(__filename);
|
||||
const argv = require('./argv');
|
||||
const knex = require('./knex');
|
||||
const { deleteScenes } = require('./releases');
|
||||
|
||||
function curateEntity(entity, includeParameters = false) {
|
||||
if (!entity) {
|
||||
@@ -187,11 +190,59 @@ async function searchEntities(query, type, limit) {
|
||||
.groupBy('entities.id', 'entities.name', 'entities.slug', 'entities.type', 'entities.url', 'entities.description', 'parents.id')
|
||||
.limit(limit || 100);
|
||||
|
||||
console.log(entities.toString());
|
||||
|
||||
return curateEntities(await entities);
|
||||
}
|
||||
|
||||
async function flushEntities(networkSlugs = [], channelSlugs = []) {
|
||||
const entitySlugs = networkSlugs.concat(channelSlugs).join(', ');
|
||||
|
||||
const entityQuery = knex
|
||||
.withRecursive('selected_entities', knex.raw(`
|
||||
SELECT entities.*
|
||||
FROM entities
|
||||
WHERE
|
||||
entities.slug = ANY(:networkSlugs)
|
||||
AND entities.type = 'network'
|
||||
OR (entities.slug = ANY(:channelSlugs)
|
||||
AND entities.type = 'channel')
|
||||
UNION ALL
|
||||
SELECT entities.*
|
||||
FROM entities
|
||||
INNER JOIN selected_entities ON selected_entities.id = entities.parent_id
|
||||
`, {
|
||||
networkSlugs,
|
||||
channelSlugs,
|
||||
}));
|
||||
|
||||
const sceneIds = await entityQuery
|
||||
.clone()
|
||||
.select('releases.id')
|
||||
.distinct('releases.id')
|
||||
.whereNotNull('releases.id')
|
||||
.from('selected_entities')
|
||||
.leftJoin('releases', 'releases.entity_id', 'selected_entities.id')
|
||||
.pluck('releases.id');
|
||||
|
||||
if (sceneIds.length === 0) {
|
||||
logger.info(`No scenes or movies found to remove for ${entitySlugs}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const confirmed = await inquirer.prompt([{
|
||||
type: 'confirm',
|
||||
name: 'flushEntities',
|
||||
message: `You are about to remove ${sceneIds.length} scenes for ${entitySlugs}. Are you sure?`,
|
||||
default: false,
|
||||
}]);
|
||||
|
||||
if (!confirmed.flushEntities) {
|
||||
logger.warn(`Confirmation rejected, not flushing scenes for: ${entitySlugs}`);
|
||||
return;
|
||||
}
|
||||
|
||||
await deleteScenes(sceneIds);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
curateEntity,
|
||||
curateEntities,
|
||||
@@ -199,4 +250,5 @@ module.exports = {
|
||||
fetchEntity,
|
||||
fetchEntities,
|
||||
searchEntities,
|
||||
flushEntities,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user