Integrated Manticore sync, assuming responsibility from traxxx core/legacy.
This commit is contained in:
@@ -4,14 +4,18 @@
|
|||||||
@close="emit('close')"
|
@close="emit('close')"
|
||||||
>
|
>
|
||||||
<div class="dialog-body">
|
<div class="dialog-body">
|
||||||
|
<strong class="source">#{{ actor.id }} {{ actor.name }}<span v-if="actor.entity"> ({{ actor.entity.name }})</span></strong>
|
||||||
|
|
||||||
|
<span class="path">merging into</span>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="targetActor"
|
v-if="targetActor"
|
||||||
class="target"
|
class="target"
|
||||||
>
|
>
|
||||||
<span class="target-name">
|
<strong class="target-name">
|
||||||
<span class="target-id">#{{ targetActor.id }}</span>
|
<span class="target-id">#{{ targetActor.id }}</span>
|
||||||
{{ targetActor.name }}
|
{{ targetActor.name }}
|
||||||
</span>
|
</strong>
|
||||||
|
|
||||||
<Icon
|
<Icon
|
||||||
icon="cross2"
|
icon="cross2"
|
||||||
@@ -29,6 +33,7 @@
|
|||||||
ref="actorInput"
|
ref="actorInput"
|
||||||
v-model="actorQuery"
|
v-model="actorQuery"
|
||||||
class="input"
|
class="input"
|
||||||
|
placeholder="Search target actor"
|
||||||
@input="searchActors"
|
@input="searchActors"
|
||||||
>
|
>
|
||||||
|
|
||||||
@@ -89,13 +94,20 @@ async function searchActors() {
|
|||||||
const res = await get('/actors', {
|
const res = await get('/actors', {
|
||||||
q: `${actorQuery.value}*`, // return partial matches
|
q: `${actorQuery.value}*`, // return partial matches
|
||||||
limit: 10,
|
limit: 10,
|
||||||
|
global: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
actorResults.value = res.actors;
|
actorResults.value = res.actors;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function merge() {
|
async function merge() {
|
||||||
console.log('MERGE', props.actor.id, targetActor.value.id);
|
await post(`/actors/${targetActor.value.id}/merge/${props.actor.id}`, null, {
|
||||||
|
successFeedback: `Merged ${props.actor.entity ? `${props.actor.name} (${props.actor.entity.name})` : props.actor.name} into ${targetActor.value.name}`,
|
||||||
|
errorFeedback: `Failed to merge ${props.actor.entity ? `${props.actor.name} (${props.actor.entity.name})` : props.actor.name} into ${targetActor.value.name}`,
|
||||||
|
appendErrorMessage: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
emit('close');
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectActor(actor) {
|
function selectActor(actor) {
|
||||||
@@ -111,19 +123,27 @@ onMounted(() => {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.dialog-body {
|
.dialog-body {
|
||||||
width: 15rem;
|
width: 20rem;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dialog-actions {
|
.dialog-actions {
|
||||||
margin-top: 1rem;
|
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.path {
|
||||||
|
color: var(--glass-strong-20);
|
||||||
|
}
|
||||||
|
|
||||||
.target {
|
.target {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|||||||
@@ -583,7 +583,7 @@ const fields = computed(() => [
|
|||||||
.filter((field) => (actor.value ? true : ['name', 'gender'].includes(field.key)))
|
.filter((field) => (actor.value ? true : ['name', 'gender'].includes(field.key)))
|
||||||
.map((field) => ({
|
.map((field) => ({
|
||||||
...field,
|
...field,
|
||||||
forced: true,
|
forced: actor.value ? field.forced : true,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
const editing = ref(new Set(actor.value ? [] : ['name', 'gender']));
|
const editing = ref(new Set(actor.value ? [] : ['name', 'gender']));
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import slugify from '../utils/slugify.js';
|
|||||||
import { curateRevision } from './revisions.js';
|
import { curateRevision } from './revisions.js';
|
||||||
import { interpolateProfiles, platformsByHostname } from '../common/actors.mjs'; // eslint-disable-line import/namespace
|
import { interpolateProfiles, platformsByHostname } from '../common/actors.mjs'; // eslint-disable-line import/namespace
|
||||||
import { resolvePlace } from '../common/geo.mjs'; // eslint-disable-line import/namespace
|
import { resolvePlace } from '../common/geo.mjs'; // eslint-disable-line import/namespace
|
||||||
|
import { syncScenes, syncActors } from './sync.js';
|
||||||
|
import verifyAbility from '../utils/verify-ability.js';
|
||||||
|
|
||||||
const logger = initLogger();
|
const logger = initLogger();
|
||||||
const mj = new MerkleJson();
|
const mj = new MerkleJson();
|
||||||
@@ -373,6 +375,10 @@ async function queryManticoreSql(filters, options, _reqUser) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filters.isGlobal) {
|
||||||
|
builder.where('entity_id', 0);
|
||||||
|
}
|
||||||
|
|
||||||
// attribute filters
|
// attribute filters
|
||||||
['country'].forEach((attribute) => {
|
['country'].forEach((attribute) => {
|
||||||
if (filters[attribute]) {
|
if (filters[attribute]) {
|
||||||
@@ -540,9 +546,84 @@ export async function createActor(newActor, context, reqUser) {
|
|||||||
const curatedActorEntry = curateActorEntry(newActor, context);
|
const curatedActorEntry = curateActorEntry(newActor, context);
|
||||||
const [actorEntry] = await knex('actors').insert(curatedActorEntry).returning('*');
|
const [actorEntry] = await knex('actors').insert(curatedActorEntry).returning('*');
|
||||||
|
|
||||||
|
await syncActors([actorEntry.id]);
|
||||||
|
|
||||||
return curateActor(actorEntry);
|
return curateActor(actorEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function mergeActors(targetActorId, sourceActorId, reqUser) {
|
||||||
|
if (!verifyAbility(reqUser, 'actor', 'merge')) {
|
||||||
|
throw new HttpError('You are not permitted to merge actors', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [targetActor, sourceActor] = await Promise.all([
|
||||||
|
knex('actors')
|
||||||
|
.where('id', targetActorId)
|
||||||
|
.first(),
|
||||||
|
knex('actors')
|
||||||
|
.where('id', sourceActorId)
|
||||||
|
.first(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!targetActor) {
|
||||||
|
throw new HttpError('Target actor not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sourceActor) {
|
||||||
|
throw new HttpError('Source actor not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetActor.entity_id) {
|
||||||
|
throw new HttpError('Target actor is not global', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetActor.alias_for) {
|
||||||
|
throw new HttpError('Target actor is aliased', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const trx = await knex.transaction();
|
||||||
|
|
||||||
|
await trx('actors')
|
||||||
|
.update('alias_for', targetActorId)
|
||||||
|
.where('id', sourceActorId);
|
||||||
|
|
||||||
|
const mergedProfiles = await trx('actors_profiles')
|
||||||
|
.update('actor_id', targetActorId)
|
||||||
|
.where('actor_id', sourceActorId)
|
||||||
|
.returning('id');
|
||||||
|
|
||||||
|
const mergedScenes = await trx('releases_actors')
|
||||||
|
.update({
|
||||||
|
actor_id: targetActorId,
|
||||||
|
alias_id: sourceActorId,
|
||||||
|
})
|
||||||
|
.where('actor_id', sourceActorId)
|
||||||
|
.returning('release_id');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await trx.commit();
|
||||||
|
} catch (error) {
|
||||||
|
await trx.rollback();
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
await interpolateProfiles([targetActorId, sourceActorId], {
|
||||||
|
knex,
|
||||||
|
logger,
|
||||||
|
moment,
|
||||||
|
slugify,
|
||||||
|
omit,
|
||||||
|
}, { refreshView: false });
|
||||||
|
|
||||||
|
await syncScenes(mergedScenes.map((scene) => scene.release_id));
|
||||||
|
|
||||||
|
return {
|
||||||
|
scenes: mergedScenes.length,
|
||||||
|
profiles: mergedProfiles.length,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchActorRevisions(revisionId, filters = {}, reqUser) {
|
export async function fetchActorRevisions(revisionId, filters = {}, reqUser) {
|
||||||
const limit = filters.limit || 50;
|
const limit = filters.limit || 50;
|
||||||
const page = filters.page || 1;
|
const page = filters.page || 1;
|
||||||
@@ -747,6 +828,8 @@ async function applyActorRevision(revisionIds, reqUser) {
|
|||||||
slugify,
|
slugify,
|
||||||
omit,
|
omit,
|
||||||
}, { refreshView: false });
|
}, { refreshView: false });
|
||||||
|
|
||||||
|
await syncActors(actorIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function reviewActorRevision(revisionId, isApproved, { feedback }, reqUser) {
|
export async function reviewActorRevision(revisionId, isApproved, { feedback }, reqUser) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import initLogger from './logger.js';
|
|||||||
import { curateRevision } from './revisions.js';
|
import { curateRevision } from './revisions.js';
|
||||||
import { getAffiliateSceneUrl } from './affiliates.js';
|
import { getAffiliateSceneUrl } from './affiliates.js';
|
||||||
import { censor } from './censor.js';
|
import { censor } from './censor.js';
|
||||||
|
import { syncScenes } from './sync.js';
|
||||||
|
|
||||||
const logger = initLogger();
|
const logger = initLogger();
|
||||||
const mj = new MerkleJson();
|
const mj = new MerkleJson();
|
||||||
@@ -888,6 +889,10 @@ async function applySceneRevision(revisionIds, reqUser) {
|
|||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
}, Promise.resolve());
|
}, Promise.resolve());
|
||||||
|
|
||||||
|
const sceneIds = Array.from(new Set(revisions.map((revision) => revision.scene_id)));
|
||||||
|
|
||||||
|
await syncScenes(sceneIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function reviewSceneRevision(revisionId, isApproved, { feedback }, reqUser) {
|
export async function reviewSceneRevision(revisionId, isApproved, { feedback }, reqUser) {
|
||||||
|
|||||||
440
src/sync.js
Normal file
440
src/sync.js
Normal file
@@ -0,0 +1,440 @@
|
|||||||
|
import { format } from 'date-fns';
|
||||||
|
|
||||||
|
import initLogger from './logger.js';
|
||||||
|
import { knexOwner as knex } from './knex.js';
|
||||||
|
import { searchApi, indexApi } from './manticore.js';
|
||||||
|
import chunk from '../utils/chunk.js';
|
||||||
|
import filterTitle from '../utils/filter-title.js';
|
||||||
|
|
||||||
|
const logger = initLogger();
|
||||||
|
|
||||||
|
export async function syncStashes(domain = 'scene', ids) {
|
||||||
|
const stashes = await knex(`stashes_${domain}s`)
|
||||||
|
.select(
|
||||||
|
`stashes_${domain}s.id as stashed_id`,
|
||||||
|
`stashes_${domain}s.${domain}_id`,
|
||||||
|
'stashes.id as stash_id',
|
||||||
|
'stashes.user_id as user_id',
|
||||||
|
`stashes_${domain}s.created_at as created_at`,
|
||||||
|
)
|
||||||
|
.modify((builder) => {
|
||||||
|
if (ids) {
|
||||||
|
builder.whereRaw(`stashes_${domain}s.${domain}_id = ANY(?)`, [ids]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.leftJoin('stashes', 'stashes.id', `stashes_${domain}s.stash_id`);
|
||||||
|
|
||||||
|
await chunk(stashes, 1000).reduce(async (chain, stashChunk, index) => {
|
||||||
|
await chain;
|
||||||
|
|
||||||
|
const stashDocs = stashChunk.map((stash) => ({
|
||||||
|
replace: {
|
||||||
|
index: `${domain}s_stashed`,
|
||||||
|
id: stash.stashed_id,
|
||||||
|
doc: {
|
||||||
|
[`${domain}_id`]: stash[`${domain}_id`],
|
||||||
|
stash_id: stash.stash_id,
|
||||||
|
user_id: stash.user_id,
|
||||||
|
created_at: Math.round(stash.created_at.getTime() / 1000),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
await indexApi.bulk(stashDocs.map((doc) => JSON.stringify(doc)).join('\n'));
|
||||||
|
|
||||||
|
logger.verbose(`Seeded ${index * 1000 + stashChunk.length}/${stashes.length} ${domain} stashes`);
|
||||||
|
}, Promise.resolve());
|
||||||
|
|
||||||
|
// purge orphaned docs
|
||||||
|
const itemIds = ids ?? [...new Set(stashes.map((s) => s[`${domain}_id`]))];
|
||||||
|
|
||||||
|
if (itemIds.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const validStashedIds = new Set(stashes.map((stash) => stash.stashed_id));
|
||||||
|
|
||||||
|
await chunk(itemIds, 1000).reduce(async (chain, itemIdChunk) => {
|
||||||
|
await chain;
|
||||||
|
|
||||||
|
const searchResponse = await searchApi.search({
|
||||||
|
index: `${domain}s_stashed`,
|
||||||
|
query: {
|
||||||
|
in: {
|
||||||
|
[`${domain}_id`]: itemIdChunk,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
limit: 1000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const docs = searchResponse?.hits?.hits ?? [];
|
||||||
|
|
||||||
|
const orphanedIds = docs
|
||||||
|
.map((hit) => hit._id)
|
||||||
|
.filter((manticoreId) => !validStashedIds.has(manticoreId));
|
||||||
|
|
||||||
|
if (orphanedIds.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteDocs = orphanedIds.map((orphanId) => ({
|
||||||
|
delete: {
|
||||||
|
index: `${domain}s_stashed`,
|
||||||
|
id: orphanId,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
await indexApi.bulk(deleteDocs.map((doc) => JSON.stringify(doc)).join('\n'));
|
||||||
|
|
||||||
|
logger.verbose(`Purged ${orphanedIds.length} orphaned ${domain} stash documents`);
|
||||||
|
}, Promise.resolve());
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function syncManticoreScenes(sceneIds) {
|
||||||
|
logger.info(`Updating Manticore search documents for ${sceneIds ? sceneIds.length : 'all' } scenes`);
|
||||||
|
|
||||||
|
const scenes = await knex.raw(`
|
||||||
|
SELECT
|
||||||
|
releases.id AS id,
|
||||||
|
releases.title,
|
||||||
|
releases.created_at,
|
||||||
|
releases.date,
|
||||||
|
releases.shoot_id,
|
||||||
|
scenes_meta.stashed,
|
||||||
|
entities.id as channel_id,
|
||||||
|
entities.slug as channel_slug,
|
||||||
|
entities.name as channel_name,
|
||||||
|
parents.id as network_id,
|
||||||
|
parents.slug as network_slug,
|
||||||
|
parents.name as network_name,
|
||||||
|
studios.id as studio_id,
|
||||||
|
studios.slug as studio_slug,
|
||||||
|
studios.name as studio_name,
|
||||||
|
grandparents.id as parent_network_id,
|
||||||
|
COALESCE(JSON_AGG(DISTINCT (actors.id, actors.name)) FILTER (WHERE actors.id IS NOT NULL), '[]') as actors,
|
||||||
|
COALESCE(JSON_AGG(DISTINCT (tags.id, tags.name, tags.priority, tags_aliases.name)) FILTER (WHERE tags.id IS NOT NULL), '[]') as tags,
|
||||||
|
COALESCE(JSON_AGG(DISTINCT (movies.id, movies.title)) FILTER (WHERE movies.id IS NOT NULL), '[]') as movies,
|
||||||
|
COALESCE(JSON_AGG(DISTINCT (series.id, series.title)) FILTER (WHERE series.id IS NOT NULL), '[]') as series,
|
||||||
|
studios.showcased IS NOT false
|
||||||
|
AND (entities.showcased IS NOT false OR COALESCE(studios.showcased, false) = true)
|
||||||
|
AND (parents.showcased IS NOT false OR COALESCE(entities.showcased, false) = true OR COALESCE(studios.showcased, false) = true)
|
||||||
|
AND (releases_summaries.batch_showcased IS NOT false)
|
||||||
|
AS showcased,
|
||||||
|
row_number() OVER (PARTITION BY releases.entry_id, parents.id ORDER BY releases.effective_date DESC) as dupe_index
|
||||||
|
FROM releases
|
||||||
|
LEFT JOIN releases_summaries ON releases_summaries.release_id = releases.id
|
||||||
|
LEFT JOIN scenes_meta ON scenes_meta.scene_id = releases.id
|
||||||
|
LEFT JOIN entities ON releases.entity_id = entities.id
|
||||||
|
LEFT JOIN entities AS parents ON parents.id = entities.parent_id
|
||||||
|
LEFT JOIN entities AS grandparents ON grandparents.id = parents.parent_id
|
||||||
|
LEFT JOIN entities AS studios ON studios.id = releases.studio_id
|
||||||
|
LEFT JOIN releases_actors AS local_actors ON local_actors.release_id = releases.id
|
||||||
|
LEFT JOIN releases_directors AS local_directors ON local_directors.release_id = releases.id
|
||||||
|
LEFT JOIN releases_tags AS local_tags ON local_tags.release_id = releases.id
|
||||||
|
LEFT JOIN actors ON local_actors.actor_id = actors.id
|
||||||
|
LEFT JOIN actors AS directors ON local_directors.director_id = directors.id
|
||||||
|
LEFT JOIN tags ON local_tags.tag_id = tags.id
|
||||||
|
LEFT JOIN tags as tags_aliases ON local_tags.tag_id = tags_aliases.alias_for AND tags_aliases.secondary = true
|
||||||
|
LEFT JOIN movies_scenes ON movies_scenes.scene_id = releases.id
|
||||||
|
LEFT JOIN movies ON movies.id = movies_scenes.movie_id
|
||||||
|
LEFT JOIN series_scenes ON series_scenes.scene_id = releases.id
|
||||||
|
LEFT JOIN series ON series.id = series_scenes.serie_id
|
||||||
|
${sceneIds ? 'WHERE releases.id = ANY(?)' : ''}
|
||||||
|
GROUP BY
|
||||||
|
releases.id,
|
||||||
|
releases.title,
|
||||||
|
releases.created_at,
|
||||||
|
releases.date,
|
||||||
|
releases.shoot_id,
|
||||||
|
scenes_meta.stashed,
|
||||||
|
releases_summaries.batch_showcased,
|
||||||
|
entities.id,
|
||||||
|
entities.name,
|
||||||
|
entities.slug,
|
||||||
|
entities.alias,
|
||||||
|
entities.showcased,
|
||||||
|
parents.id,
|
||||||
|
parents.name,
|
||||||
|
parents.slug,
|
||||||
|
parents.alias,
|
||||||
|
grandparents.id,
|
||||||
|
studios.id,
|
||||||
|
studios.name,
|
||||||
|
studios.slug,
|
||||||
|
parents.showcased,
|
||||||
|
studios.showcased
|
||||||
|
`, sceneIds && [sceneIds]);
|
||||||
|
|
||||||
|
const scenesById = Object.fromEntries(scenes.rows.map((scene) => [scene.id, scene]));
|
||||||
|
|
||||||
|
const docs = (sceneIds || Object.keys(scenesById)).map((sceneId) => {
|
||||||
|
const scene = scenesById[sceneId];
|
||||||
|
|
||||||
|
if (!scene) {
|
||||||
|
return {
|
||||||
|
delete: {
|
||||||
|
index: 'scenes',
|
||||||
|
id: sceneId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const flatActors = scene.actors.flatMap((actor) => actor.f2.split(' '));
|
||||||
|
const flatTags = scene.tags.filter((tag) => tag.f3 > 6).flatMap((tag) => [tag.f2].concat(tag.f4)).filter(Boolean); // only make top tags searchable to minimize cluttered results
|
||||||
|
const filteredTitle = filterTitle(scene.title, [...flatActors, ...flatTags]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
replace: {
|
||||||
|
index: 'scenes',
|
||||||
|
id: scene.id,
|
||||||
|
doc: {
|
||||||
|
title: scene.title || undefined,
|
||||||
|
title_filtered: filteredTitle || undefined,
|
||||||
|
date: scene.date ? Math.round(scene.date.getTime() / 1000) : undefined,
|
||||||
|
created_at: Math.round(scene.created_at.getTime() / 1000),
|
||||||
|
effective_date: Math.round((scene.date || scene.created_at).getTime() / 1000),
|
||||||
|
is_showcased: scene.showcased,
|
||||||
|
shoot_id: scene.shoot_id || undefined,
|
||||||
|
channel_id: scene.channel_id,
|
||||||
|
channel_slug: scene.channel_slug,
|
||||||
|
channel_name: scene.channel_name,
|
||||||
|
network_id: scene.network_id || undefined,
|
||||||
|
network_slug: scene.network_slug || undefined,
|
||||||
|
network_name: scene.network_name || undefined,
|
||||||
|
studio_id: scene.studio_id || undefined,
|
||||||
|
studio_slug: scene.studio_slug || undefined,
|
||||||
|
studio_name: scene.studio_name || undefined,
|
||||||
|
entity_ids: [scene.channel_id, scene.network_id, scene.parent_network_id, scene.studio_id].filter(Boolean), // manticore does not support OR, this allows IN
|
||||||
|
actor_ids: scene.actors.map((actor) => actor.f1),
|
||||||
|
actors: scene.actors.map((actor) => actor.f2).join(),
|
||||||
|
tag_ids: scene.tags.map((tag) => tag.f1),
|
||||||
|
tags: flatTags.join(' '), // only make top tags searchable to minimize cluttered results
|
||||||
|
movie_ids: scene.movies.map((movie) => movie.f1),
|
||||||
|
movies: scene.movies.map((movie) => movie.f2).join(' '),
|
||||||
|
serie_ids: scene.series.map((serie) => serie.f1),
|
||||||
|
series: scene.series.map((serie) => serie.f2).join(' '),
|
||||||
|
meta: scene.date ? format(scene.date, 'y yy M MMM MMMM d') : undefined,
|
||||||
|
stashed: scene.stashed || 0,
|
||||||
|
dupe_index: scene.dupe_index || 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (docs.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [manticoreResult] = await Promise.all([
|
||||||
|
chunk(docs, 10000).reduce(async (chain, docsChunk, index, array) => {
|
||||||
|
const acc = await chain;
|
||||||
|
const data = await indexApi.bulk(docsChunk.map((doc) => JSON.stringify(doc)).join('\n'));
|
||||||
|
|
||||||
|
logger.verbose(`Seeded ${index + 1}/${array.length}, errors: ${data.errors} ${data.error}`);
|
||||||
|
|
||||||
|
return acc.concat(data.items);
|
||||||
|
}, Promise.resolve([])),
|
||||||
|
syncStashes('scene', sceneIds),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return manticoreResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function syncScenes(releaseIds) {
|
||||||
|
await knex.raw('REFRESH MATERIALIZED VIEW scenes_meta;');
|
||||||
|
|
||||||
|
await syncManticoreScenes(releaseIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function syncManticoreMovies(movieIds) {
|
||||||
|
logger.info(`Updating Manticore search documents for ${movieIds ? movieIds.length : 'all' } movies`);
|
||||||
|
|
||||||
|
const movies = await knex.raw(`
|
||||||
|
SELECT
|
||||||
|
movies.id AS id,
|
||||||
|
movies.title,
|
||||||
|
movies.created_at,
|
||||||
|
movies.date,
|
||||||
|
movies_meta.stashed,
|
||||||
|
entities.id as channel_id,
|
||||||
|
entities.slug as channel_slug,
|
||||||
|
entities.name as channel_name,
|
||||||
|
parents.id as network_id,
|
||||||
|
parents.slug as network_slug,
|
||||||
|
parents.name as network_name,
|
||||||
|
movies_covers IS NOT NULL as has_cover,
|
||||||
|
COALESCE(JSON_AGG(DISTINCT (actors.id, actors.name)) FILTER (WHERE actors.id IS NOT NULL), '[]') as actors,
|
||||||
|
COALESCE(JSON_AGG(DISTINCT (tags.id, tags.name, tags.priority, tags_aliases.name)) FILTER (WHERE tags.id IS NOT NULL), '[]') as tags,
|
||||||
|
COALESCE(JSON_AGG(DISTINCT (movie_tags.id, movie_tags.name, movie_tags.priority, movie_tags_aliases.name)) FILTER (WHERE movie_tags.id IS NOT NULL), '[]') as movie_tags,
|
||||||
|
row_number() OVER (PARTITION BY movies.entry_id, parents.id ORDER BY movies.effective_date DESC) as dupe_index
|
||||||
|
FROM movies
|
||||||
|
LEFT JOIN movies_meta ON movies_meta.movie_id = movies.id
|
||||||
|
LEFT JOIN movies_scenes ON movies_scenes.movie_id = movies.id
|
||||||
|
LEFT JOIN movies_tags ON movies_tags.movie_id = movies.id
|
||||||
|
LEFT JOIN entities ON movies.entity_id = entities.id
|
||||||
|
LEFT JOIN entities AS parents ON parents.id = entities.parent_id
|
||||||
|
LEFT JOIN releases_actors AS local_actors ON local_actors.release_id = movies_scenes.scene_id
|
||||||
|
LEFT JOIN releases_directors AS local_directors ON local_directors.release_id = movies_scenes.scene_id
|
||||||
|
LEFT JOIN releases_tags AS local_tags ON local_tags.release_id = movies_scenes.scene_id
|
||||||
|
LEFT JOIN actors ON local_actors.actor_id = actors.id
|
||||||
|
LEFT JOIN actors AS directors ON local_directors.director_id = directors.id
|
||||||
|
LEFT JOIN tags ON local_tags.tag_id = tags.id
|
||||||
|
LEFT JOIN tags as tags_aliases ON local_tags.tag_id = tags_aliases.alias_for AND tags_aliases.secondary = true
|
||||||
|
LEFT JOIN tags as movie_tags ON movies_tags.tag_id = movie_tags.id
|
||||||
|
LEFT JOIN tags as movie_tags_aliases ON movies_tags.tag_id = movie_tags_aliases.alias_for AND movie_tags_aliases.secondary = true
|
||||||
|
LEFT JOIN movies_covers ON movies_covers.movie_id = movies.id
|
||||||
|
${movieIds ? 'WHERE movies.id = ANY(?)' : ''}
|
||||||
|
GROUP BY
|
||||||
|
movies.id,
|
||||||
|
movies.title,
|
||||||
|
movies.created_at,
|
||||||
|
movies.date,
|
||||||
|
movies_meta.stashed,
|
||||||
|
movies_meta.stashed_scenes,
|
||||||
|
movies_meta.stashed_total,
|
||||||
|
entities.id,
|
||||||
|
entities.name,
|
||||||
|
entities.slug,
|
||||||
|
entities.alias,
|
||||||
|
parents.id,
|
||||||
|
parents.name,
|
||||||
|
parents.slug,
|
||||||
|
parents.alias,
|
||||||
|
movies_covers.*
|
||||||
|
`, movieIds && [movieIds]);
|
||||||
|
|
||||||
|
const moviesById = Object.fromEntries(movies.rows.map((movie) => [movie.id, movie]));
|
||||||
|
|
||||||
|
const docs = (movieIds || Object.keys(moviesById)).map((movieId) => {
|
||||||
|
const movie = moviesById[movieId];
|
||||||
|
|
||||||
|
if (!movie) {
|
||||||
|
return {
|
||||||
|
delete: {
|
||||||
|
index: 'movies',
|
||||||
|
id: movieId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const combinedTags = Object.values(Object.fromEntries(movie.tags.concat(movie.movie_tags).map((tag) => [tag.f1, {
|
||||||
|
id: tag.f1,
|
||||||
|
name: tag.f2,
|
||||||
|
priority: tag.f3,
|
||||||
|
alias: tag.f4,
|
||||||
|
}])));
|
||||||
|
|
||||||
|
const flatActors = movie.actors.flatMap((actor) => actor.f2.match(/[\w']+/g)); // match word characters to filter out brackets etc.
|
||||||
|
const flatTags = combinedTags.filter((tag) => tag.priority > 6).flatMap((tag) => (tag.alias ? `${tag.name} ${tag.alias}` : tag.name).match(/[\w']+/g)); // only make top tags searchable to minimize cluttered results
|
||||||
|
const filteredTitle = movie.title && [...flatActors, ...flatTags].reduce((accTitle, tag) => accTitle.replace(new RegExp(tag.replace(/[^\w\s]+/g, ''), 'gi'), ''), movie.title).trim().replace(/\s{2,}/g, ' ');
|
||||||
|
|
||||||
|
return {
|
||||||
|
replace: {
|
||||||
|
index: 'movies',
|
||||||
|
id: movie.id,
|
||||||
|
doc: {
|
||||||
|
title: movie.title || undefined,
|
||||||
|
title_filtered: filteredTitle || undefined,
|
||||||
|
date: movie.date ? Math.round(movie.date.getTime() / 1000) : undefined,
|
||||||
|
created_at: Math.round(movie.created_at.getTime() / 1000),
|
||||||
|
effective_date: Math.round((movie.date || movie.created_at).getTime() / 1000),
|
||||||
|
channel_id: movie.channel_id,
|
||||||
|
channel_slug: movie.channel_slug,
|
||||||
|
channel_name: movie.channel_name,
|
||||||
|
network_id: movie.network_id || undefined,
|
||||||
|
network_slug: movie.network_slug || undefined,
|
||||||
|
network_name: movie.network_name || undefined,
|
||||||
|
entity_ids: [movie.channel_id, movie.network_id].filter(Boolean), // manticore does not support OR, this allows IN
|
||||||
|
actor_ids: movie.actors.map((actor) => actor.f1),
|
||||||
|
actors: movie.actors.map((actor) => actor.f2).join(),
|
||||||
|
tag_ids: combinedTags.map((tag) => tag.id),
|
||||||
|
tags: flatTags.join(' '),
|
||||||
|
has_cover: movie.has_cover,
|
||||||
|
meta: movie.date ? format(movie.date, 'y yy M MMM MMMM d') : undefined,
|
||||||
|
stashed: movie.stashed || 0,
|
||||||
|
stashed_scenes: movie.stashed_scenes || 0,
|
||||||
|
stashed_total: movie.stashed_total || 0,
|
||||||
|
dupe_index: movie.dupe_index || 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (docs.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexApi.bulk(docs.map((doc) => JSON.stringify(doc)).join('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function syncMovies(releaseIds) {
|
||||||
|
await knex.raw('REFRESH MATERIALIZED VIEW movies_meta;');
|
||||||
|
|
||||||
|
await syncManticoreMovies(releaseIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function syncManticoreActors(actorIds) {
|
||||||
|
logger.info(`Updating Manticore search documents for ${actorIds ? actorIds.length : 'all' } actors`);
|
||||||
|
|
||||||
|
// manually select date of birth, otherwise it is retrieved in local timezone but interpreted as UTC...
|
||||||
|
const actors = await knex.raw(`
|
||||||
|
SELECT
|
||||||
|
actors.*,
|
||||||
|
actors_meta.*,
|
||||||
|
date_of_birth AT TIME ZONE 'Europe/Amsterdam' AT TIME ZONE 'UTC' as dob
|
||||||
|
FROM actors
|
||||||
|
LEFT JOIN actors_meta ON actors_meta.actor_id = actors.id
|
||||||
|
${actorIds ? 'WHERE actors.id = ANY(?)' : ''}
|
||||||
|
`, actorIds && [actorIds]);
|
||||||
|
|
||||||
|
const actorsById = Object.fromEntries(actors.rows.map((actor) => [actor.id, actor]));
|
||||||
|
|
||||||
|
const docs = (actorIds || Object.keys(actorsById)).map((actorId) => {
|
||||||
|
const actor = actorsById[actorId];
|
||||||
|
|
||||||
|
if (!actor) {
|
||||||
|
return {
|
||||||
|
delete: {
|
||||||
|
index: 'actors',
|
||||||
|
id: actorId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
replace: {
|
||||||
|
index: 'actors',
|
||||||
|
id: actor.id,
|
||||||
|
doc: {
|
||||||
|
entity_id: actor.entity_id,
|
||||||
|
name: actor.name,
|
||||||
|
slug: actor.slug,
|
||||||
|
gender: actor.gender || undefined,
|
||||||
|
date_of_birth: actor.dob ? Math.round(actor.dob.getTime() / 1000) : undefined,
|
||||||
|
has_avatar: !!actor.avatar_media_id,
|
||||||
|
country: actor.birth_country_alpha2 || undefined,
|
||||||
|
height: actor.height || undefined,
|
||||||
|
mass: actor.weight || undefined, // weight is a reserved keyword in manticore
|
||||||
|
cup: actor.cup || undefined,
|
||||||
|
natural_boobs: actor.natural_boobs === null ? 0 : Number(actor.natural_boobs) + 1, // manticore bool does not seem to support null, and we need three states for natural_boobs: yes, no and unknown
|
||||||
|
penis_length: actor.penis_length || undefined,
|
||||||
|
penis_girth: actor.penis_girth || undefined,
|
||||||
|
stashed: actor.stashed || 0,
|
||||||
|
scenes: actor.scenes || 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (docs.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexApi.bulk(docs.map((doc) => JSON.stringify(doc)).join('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function syncActors(actorIds) {
|
||||||
|
await knex.raw('REFRESH MATERIALIZED VIEW actors_meta;');
|
||||||
|
|
||||||
|
await syncManticoreActors(actorIds);
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
fetchActors,
|
fetchActors,
|
||||||
fetchActorsById,
|
fetchActorsById,
|
||||||
createActor,
|
createActor,
|
||||||
|
mergeActors,
|
||||||
fetchActorRevisions,
|
fetchActorRevisions,
|
||||||
createActorRevision,
|
createActorRevision,
|
||||||
reviewActorRevision,
|
reviewActorRevision,
|
||||||
@@ -26,6 +27,7 @@ export function curateActorsQuery(query) {
|
|||||||
weight: query.weight?.split(',').map((weight) => Number(weight)),
|
weight: query.weight?.split(',').map((weight) => Number(weight)),
|
||||||
requireAvatar: query.avatar,
|
requireAvatar: query.avatar,
|
||||||
stashId: Number(query.stashId) || null,
|
stashId: Number(query.stashId) || null,
|
||||||
|
isGlobal: !!query.global,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +179,12 @@ export async function createActorApi(req, res) {
|
|||||||
res.send({ actor });
|
res.send({ actor });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function mergeActorsApi(req, res) {
|
||||||
|
const result = await mergeActors(Number(req.params.targetActorId), Number(req.params.sourceActorId), req.user);
|
||||||
|
|
||||||
|
res.send(result);
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchActorRevisionsApi(req, res) {
|
async function fetchActorRevisionsApi(req, res) {
|
||||||
const revisions = await fetchActorRevisions(Number(req.params.revisionId) || null, req.query, req.user);
|
const revisions = await fetchActorRevisions(Number(req.params.revisionId) || null, req.query, req.user);
|
||||||
|
|
||||||
@@ -200,6 +208,8 @@ export const actorsRouter = Router();
|
|||||||
actorsRouter.get('/api/actors', fetchActorsApi);
|
actorsRouter.get('/api/actors', fetchActorsApi);
|
||||||
actorsRouter.post('/api/actors', createActorApi);
|
actorsRouter.post('/api/actors', createActorApi);
|
||||||
|
|
||||||
|
actorsRouter.post('/api/actors/:targetActorId/merge/:sourceActorId', mergeActorsApi);
|
||||||
|
|
||||||
actorsRouter.get('/api/revisions/actors', fetchActorRevisionsApi);
|
actorsRouter.get('/api/revisions/actors', fetchActorRevisionsApi);
|
||||||
actorsRouter.get('/api/revisions/actors/:revisionId', fetchActorRevisionsApi);
|
actorsRouter.get('/api/revisions/actors/:revisionId', fetchActorRevisionsApi);
|
||||||
actorsRouter.post('/api/revisions/actors', createActorRevisionApi);
|
actorsRouter.post('/api/revisions/actors', createActorRevisionApi);
|
||||||
|
|||||||
43
tools/manticore-actors.js
Normal file
43
tools/manticore-actors.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import argv from '../src/argv.js';
|
||||||
|
|
||||||
|
import { knexOwner as knex } from '../src/knex.js';
|
||||||
|
import { utilsApi } from '../src/manticore.js';
|
||||||
|
import { syncManticoreActors } from '../src/sync.js';
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
if (argv.update) {
|
||||||
|
await utilsApi.sql('drop table if exists actors');
|
||||||
|
await utilsApi.sql(`create table actors(
|
||||||
|
id int,
|
||||||
|
name text,
|
||||||
|
slug string,
|
||||||
|
entity_id int,
|
||||||
|
gender string,
|
||||||
|
date_of_birth timestamp,
|
||||||
|
country string,
|
||||||
|
has_avatar bool,
|
||||||
|
mass int,
|
||||||
|
height int,
|
||||||
|
cup string,
|
||||||
|
natural_boobs int,
|
||||||
|
penis_length int,
|
||||||
|
penis_girth int,
|
||||||
|
stashed int,
|
||||||
|
scenes int
|
||||||
|
) min_prefix_len = '3'`);
|
||||||
|
|
||||||
|
console.log('Recreated actors table, syncing actors...');
|
||||||
|
|
||||||
|
const data = await syncManticoreActors();
|
||||||
|
|
||||||
|
console.log('data', data);
|
||||||
|
|
||||||
|
knex.destroy();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
knex.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
45
tools/manticore-movies.js
Normal file
45
tools/manticore-movies.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import argv from '../src/argv.js';
|
||||||
|
import { knexOwner as knex } from '../src/knex.js';
|
||||||
|
import { utilsApi } from '../src/manticore.js';
|
||||||
|
import { syncManticoreMovies } from '../src/sync.js';
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
if (argv.update) {
|
||||||
|
await utilsApi.sql('drop table if exists movies');
|
||||||
|
await utilsApi.sql(`create table movies (
|
||||||
|
id int,
|
||||||
|
title text,
|
||||||
|
title_filtered text,
|
||||||
|
channel_id int,
|
||||||
|
channel_name text,
|
||||||
|
channel_slug text,
|
||||||
|
network_id int,
|
||||||
|
network_name text,
|
||||||
|
network_slug text,
|
||||||
|
entity_ids multi,
|
||||||
|
actor_ids multi,
|
||||||
|
actors text,
|
||||||
|
tag_ids multi,
|
||||||
|
tags text,
|
||||||
|
meta text,
|
||||||
|
date timestamp,
|
||||||
|
has_cover bool,
|
||||||
|
created_at timestamp,
|
||||||
|
effective_date timestamp,
|
||||||
|
stashed int,
|
||||||
|
stashed_scenes int,
|
||||||
|
stashed_total int,
|
||||||
|
dupe_index int
|
||||||
|
)`);
|
||||||
|
|
||||||
|
console.log('Recreated movies tables, syncing movies...');
|
||||||
|
|
||||||
|
const data = await syncManticoreMovies();
|
||||||
|
|
||||||
|
console.log('data', data);
|
||||||
|
}
|
||||||
|
|
||||||
|
knex.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
59
tools/manticore-scenes.js
Normal file
59
tools/manticore-scenes.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import argv from '../src/argv.js';
|
||||||
|
import { knexOwner as knex } from '../src/knex.js';
|
||||||
|
import { utilsApi } from '../src/manticore.js';
|
||||||
|
import { syncManticoreScenes } from '../src/sync.js';
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
if (argv.update) {
|
||||||
|
await utilsApi.sql('drop table if exists scenes');
|
||||||
|
await utilsApi.sql(`create table scenes (
|
||||||
|
id int,
|
||||||
|
title text,
|
||||||
|
title_filtered text,
|
||||||
|
entry_id text,
|
||||||
|
shoot_id text,
|
||||||
|
channel_id int,
|
||||||
|
channel_name text,
|
||||||
|
channel_slug text,
|
||||||
|
network_id int,
|
||||||
|
network_name text,
|
||||||
|
network_slug text,
|
||||||
|
studio_id int,
|
||||||
|
studio_name text,
|
||||||
|
studio_slug text,
|
||||||
|
entity_ids multi,
|
||||||
|
actor_ids multi,
|
||||||
|
actors text,
|
||||||
|
tag_ids multi,
|
||||||
|
tags text,
|
||||||
|
movie_ids multi,
|
||||||
|
movies text,
|
||||||
|
serie_ids multi,
|
||||||
|
series text,
|
||||||
|
meta text,
|
||||||
|
date timestamp,
|
||||||
|
fingerprints text,
|
||||||
|
is_showcased bool,
|
||||||
|
created_at timestamp,
|
||||||
|
effective_date timestamp,
|
||||||
|
stashed int,
|
||||||
|
dupe_index int
|
||||||
|
)`);
|
||||||
|
|
||||||
|
await utilsApi.sql('drop table if exists scenes_tags');
|
||||||
|
await utilsApi.sql(`create table scenes_tags (
|
||||||
|
id int,
|
||||||
|
scene_id int,
|
||||||
|
tag_id int,
|
||||||
|
actor_id int
|
||||||
|
)`);
|
||||||
|
|
||||||
|
console.log('Recreated scenes tables, syncing scenes...');
|
||||||
|
|
||||||
|
await syncManticoreScenes();
|
||||||
|
}
|
||||||
|
|
||||||
|
knex.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
42
tools/manticore-stashes.js
Normal file
42
tools/manticore-stashes.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { knexOwner as knex } from '../src/knex.js';
|
||||||
|
import { utilsApi } from '../src/manticore.js';
|
||||||
|
import { syncStashes } from '../src/sync.js';
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
await utilsApi.sql('drop table if exists scenes_stashed');
|
||||||
|
|
||||||
|
await utilsApi.sql(`create table if not exists scenes_stashed (
|
||||||
|
scene_id int,
|
||||||
|
stash_id int,
|
||||||
|
user_id int,
|
||||||
|
created_at timestamp
|
||||||
|
)`);
|
||||||
|
|
||||||
|
await utilsApi.sql('drop table if exists movies_stashed');
|
||||||
|
|
||||||
|
await utilsApi.sql(`create table if not exists movies_stashed (
|
||||||
|
movie_id int,
|
||||||
|
stash_id int,
|
||||||
|
user_id int,
|
||||||
|
created_at timestamp
|
||||||
|
)`);
|
||||||
|
|
||||||
|
await utilsApi.sql('drop table if exists actors_stashed');
|
||||||
|
|
||||||
|
await utilsApi.sql(`create table if not exists actors_stashed (
|
||||||
|
actor_id int,
|
||||||
|
stash_id int,
|
||||||
|
user_id int,
|
||||||
|
created_at timestamp
|
||||||
|
)`);
|
||||||
|
|
||||||
|
console.log('Recreated stash tables, syncing stashes...');
|
||||||
|
|
||||||
|
await syncStashes('scene');
|
||||||
|
await syncStashes('actor');
|
||||||
|
await syncStashes('movie');
|
||||||
|
|
||||||
|
knex.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
7
utils/filter-title.js
Normal file
7
utils/filter-title.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export default function filterTitle(title, keys) {
|
||||||
|
if (!title) {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys.reduce((accTitle, tag) => accTitle.replace(new RegExp(`\\b${tag.replace(/[^\w\s]+/g, '')}\\b`, 'gi'), ''), title).trim().replace(/\s{2,}/, ' ');
|
||||||
|
}
|
||||||
15
utils/verify-ability.js
Normal file
15
utils/verify-ability.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export default function verifyAbility(user, subject, action) {
|
||||||
|
if (!user?.abilities) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subject && action) {
|
||||||
|
return user.abilities.some((ability) => ability.subject === subject && ability.action === action);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subject) {
|
||||||
|
return user.abilities.some((ability) => ability[subject] === true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user