Added actor and tag copying to scene relations.
This commit is contained in:
@@ -62,9 +62,29 @@ function toEdit(relation) {
|
|||||||
type: relation.type,
|
type: relation.type,
|
||||||
direction: relation.direction,
|
direction: relation.direction,
|
||||||
comment: relation.comment || null,
|
comment: relation.comment || null,
|
||||||
|
share: relation.share || null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shareModeLabels = {
|
||||||
|
from: 'from',
|
||||||
|
to: 'to',
|
||||||
|
both: 'both ways',
|
||||||
|
};
|
||||||
|
|
||||||
|
// e.g. 'Copies tags both ways, actors from'
|
||||||
|
function getShareSummary(relation) {
|
||||||
|
const share = getEditRelation(relation)?.share;
|
||||||
|
|
||||||
|
if (!share) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const summary = Object.entries(share).map(([field, mode]) => `${field} ${shareModeLabels[mode] || mode}`).join(', ');
|
||||||
|
|
||||||
|
return `Copies ${summary} the related scene`.replace(/ both ways the related scene$/, ' both ways');
|
||||||
|
}
|
||||||
|
|
||||||
// adding an existing relation again replaces its comment
|
// adding an existing relation again replaces its comment
|
||||||
function addRelation(relation) {
|
function addRelation(relation) {
|
||||||
showDialog.value = false;
|
showDialog.value = false;
|
||||||
@@ -116,6 +136,13 @@ watch(() => props.scene, () => {
|
|||||||
> ({{ getComment(relation) }})</span>
|
> ({{ getComment(relation) }})</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
<Icon
|
||||||
|
v-if="getShareSummary(relation)"
|
||||||
|
v-tooltip="getShareSummary(relation)"
|
||||||
|
icon="copy"
|
||||||
|
class="shared"
|
||||||
|
/>
|
||||||
|
|
||||||
<Icon
|
<Icon
|
||||||
v-if="edits.relations && !isIncluded(relation)"
|
v-if="edits.relations && !isIncluded(relation)"
|
||||||
icon="checkmark"
|
icon="checkmark"
|
||||||
@@ -251,6 +278,12 @@ watch(() => props.scene, () => {
|
|||||||
text-decoration: inherit;
|
text-decoration: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.shared {
|
||||||
|
height: auto;
|
||||||
|
padding: .25rem .3rem;
|
||||||
|
fill: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
.relation-comment {
|
.relation-comment {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
max-width: 15rem;
|
max-width: 15rem;
|
||||||
|
|||||||
@@ -254,7 +254,16 @@ async function reviewRevision(revision, isApproved) {
|
|||||||
revisionId: revision.id,
|
revisionId: revision.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
revisions.value = revisions.value.map((rev) => (rev.id === updatedRevision.revision.id ? updatedRevision.revision : rev));
|
// revisions generated by sharing a relation were reviewed along with this one
|
||||||
|
const childIds = new Set(updatedRevision.revision.childRevisions?.map((child) => child.id) || []);
|
||||||
|
const updatedChildren = await Promise.all(revisions.value
|
||||||
|
.filter((rev) => childIds.has(rev.id))
|
||||||
|
.map(async (rev) => (await get(`/revisions/${domain}/${rev.id}`, { revisionId: rev.id })).revision));
|
||||||
|
|
||||||
|
const updatedById = Object.fromEntries([updatedRevision.revision, ...updatedChildren].map((rev) => [rev.id, rev]));
|
||||||
|
|
||||||
|
childIds.forEach((childId) => reviewedRevisions.value.add(childId));
|
||||||
|
revisions.value = revisions.value.map((rev) => updatedById[rev.id] || rev);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
reviewedRevisions.value.delete(revision.id);
|
reviewedRevisions.value.delete(revision.id);
|
||||||
@@ -351,6 +360,11 @@ async function banEditor(revision) {
|
|||||||
class="nolink"
|
class="nolink"
|
||||||
>{{ rev.review.username }}</a> {{ format(rev.review.reviewedAt, 'yyyy-MM-dd hh:mm') }}</span>
|
>{{ rev.review.username }}</a> {{ format(rev.review.reviewedAt, 'yyyy-MM-dd hh:mm') }}</span>
|
||||||
|
|
||||||
|
<span
|
||||||
|
v-else-if="rev.parentRevisionId && context === 'admin'"
|
||||||
|
class="rev-parent"
|
||||||
|
>Reviewed with #{{ rev.parentRevisionId }}</span>
|
||||||
|
|
||||||
<template v-else-if="context === 'admin'">
|
<template v-else-if="context === 'admin'">
|
||||||
<Icon
|
<Icon
|
||||||
v-tooltip="{ content: 'Ban user from submitting revisions', ariaId: `rev-ban-${rev.id}` }"
|
v-tooltip="{ content: 'Ban user from submitting revisions', ariaId: `rev-ban-${rev.id}` }"
|
||||||
@@ -462,6 +476,26 @@ async function banEditor(revision) {
|
|||||||
>
|
>
|
||||||
{{ rev.comment }}
|
{{ rev.comment }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="rev.parentRevisionId || rev.childRevisions?.length > 0"
|
||||||
|
class="rev-shared"
|
||||||
|
>
|
||||||
|
<template v-if="rev.parentRevisionId">Generated by sharing a relation in revision #{{ rev.parentRevisionId }}, reviewed and applied with it.</template>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
Also applies
|
||||||
|
<template
|
||||||
|
v-for="(child, index) in rev.childRevisions"
|
||||||
|
:key="`rev-${rev.id}-child-${child.id}`"
|
||||||
|
>{{ index > 0 ? ', ' : '' }}<a
|
||||||
|
:href="`/${domain.slice(0, -1)}/${child.sceneId}`"
|
||||||
|
target="_blank"
|
||||||
|
class="link"
|
||||||
|
>#{{ child.id }} to scene {{ child.sceneId }}</a></template>
|
||||||
|
for sharing a relation.
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -751,6 +785,18 @@ async function banEditor(revision) {
|
|||||||
border-top: solid 1px var(--glass-weak-30);
|
border-top: solid 1px var(--glass-weak-30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rev-shared {
|
||||||
|
padding: .5rem;
|
||||||
|
border-top: solid 1px var(--glass-weak-30);
|
||||||
|
color: var(--glass-strong-10);
|
||||||
|
font-size: .9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rev-parent {
|
||||||
|
color: var(--glass-strong-10);
|
||||||
|
font-size: .9rem;
|
||||||
|
}
|
||||||
|
|
||||||
.rev-compact {
|
.rev-compact {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { format, startOfDay, startOfMonth, startOfYear } from 'date-fns';
|
import { format, startOfDay, startOfMonth, startOfYear } from 'date-fns';
|
||||||
import { computed, onMounted, ref, useId } from 'vue';
|
import { computed, onMounted, ref, useId, watch } from 'vue';
|
||||||
|
|
||||||
import Dialog from '#/components/dialog/dialog.vue';
|
import Dialog from '#/components/dialog/dialog.vue';
|
||||||
|
import Ellipsis from '#/components/loading/ellipsis.vue';
|
||||||
|
|
||||||
import { get } from '#/src/api.js';
|
import { get, post } from '#/src/api.js';
|
||||||
import getPath from '#/src/get-path.js';
|
import getPath from '#/src/get-path.js';
|
||||||
import { getRelationLabel, sortRelationTypes } from '#/utils/relation-labels.js';
|
import { getRelationLabel, sortRelationTypes } from '#/utils/relation-labels.js';
|
||||||
|
|
||||||
@@ -37,6 +38,34 @@ const searchCompleted = ref(false); // only show 'no results' once a search for
|
|||||||
let searchTimeout = null;
|
let searchTimeout = null;
|
||||||
let searchCount = 0;
|
let searchCount = 0;
|
||||||
|
|
||||||
|
// copy actors or tags between the scenes once when the revision is applied, relative to this scene
|
||||||
|
const share = ref({});
|
||||||
|
const shareOptions = ref(null); // what each scene would get from the other if everything were copied both ways
|
||||||
|
const previewing = ref(false);
|
||||||
|
|
||||||
|
const shareFieldLabels = {
|
||||||
|
actors: 'Copy actors',
|
||||||
|
tags: 'Copy tags',
|
||||||
|
duration: 'Duration',
|
||||||
|
};
|
||||||
|
|
||||||
|
const sceneTitle = computed(() => props.scene.title || `scene #${props.scene.id}`);
|
||||||
|
const relatedTitle = computed(() => (selectedScene.value ? selectedScene.value.title || `scene #${selectedScene.value.id}` : 'the related scene'));
|
||||||
|
|
||||||
|
// the same modes for every field, with titles naming the field they apply to
|
||||||
|
function getShareModes(field) {
|
||||||
|
const fieldName = (shareFieldLabels[field] || field).toLowerCase();
|
||||||
|
|
||||||
|
return [
|
||||||
|
{ mode: 'from', label: 'From related', title: `Copy ${fieldName} from "${relatedTitle.value}" to "${sceneTitle.value}"` },
|
||||||
|
{ mode: 'both', label: 'Both ways', title: `Copy ${fieldName} between both scenes` },
|
||||||
|
{ mode: 'to', label: 'To related', title: `Copy ${fieldName} from "${sceneTitle.value}" to "${relatedTitle.value}"` },
|
||||||
|
{ mode: 'none', label: 'None', title: `Do not share any ${fieldName}` },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
let previewCount = 0;
|
||||||
|
|
||||||
// each type can be read from either side, e.g. this scene is a 'Remaster of' or 'Remastered as' the selected scene
|
// each type can be read from either side, e.g. this scene is a 'Remaster of' or 'Remastered as' the selected scene
|
||||||
// symmetric types like variants read the same both ways
|
// symmetric types like variants read the same both ways
|
||||||
const options = computed(() => sortRelationTypes(props.types, ({ type }) => type).flatMap(({ type, symmetric }) => (symmetric ? ['both'] : ['target', 'source']).map((direction) => ({
|
const options = computed(() => sortRelationTypes(props.types, ({ type }) => type).flatMap(({ type, symmetric }) => (symmetric ? ['both'] : ['target', 'source']).map((direction) => ({
|
||||||
@@ -86,6 +115,100 @@ const inversion = computed(() => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const selectedType = computed(() => props.types.find((type) => type.type === selectedOption.value?.type));
|
||||||
|
// every type has the same shareable fields, so they can be shown before a type is selected
|
||||||
|
const shareFields = computed(() => selectedType.value?.shareFields || props.types[0]?.shareFields || []);
|
||||||
|
const isSharing = computed(() => Object.values(share.value).some((mode) => mode && mode !== 'none'));
|
||||||
|
|
||||||
|
// defaults are stored by which side of the relation receives, translate them to this scene's point of view
|
||||||
|
function getDefaultShare(type, direction) {
|
||||||
|
const ownSide = direction === 'target' ? 'source' : 'target'; // direction is the related scene's side
|
||||||
|
|
||||||
|
return Object.fromEntries((type?.shareFields || []).map((field) => {
|
||||||
|
const receiver = type.shareDefaults?.[field];
|
||||||
|
|
||||||
|
if (!receiver) {
|
||||||
|
return [field, 'none'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (receiver === 'both' || direction === 'both') {
|
||||||
|
return [field, 'both'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [field, receiver === ownSide ? 'from' : 'to'];
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(selectedOption, (option) => {
|
||||||
|
share.value = getDefaultShare(selectedType.value, option?.direction);
|
||||||
|
});
|
||||||
|
|
||||||
|
// what can be copied only depends on the two scenes, so it's fetched once per selected scene and filtered by the share modes locally
|
||||||
|
async function fetchShareOptions() {
|
||||||
|
const previewId = ++previewCount;
|
||||||
|
|
||||||
|
shareOptions.value = null;
|
||||||
|
|
||||||
|
if (!selectedScene.value) {
|
||||||
|
previewing.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
previewing.value = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await post(`/scenes/${props.scene.id}/relations/share-preview`, {
|
||||||
|
sceneId: selectedScene.value.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (previewId === previewCount) {
|
||||||
|
shareOptions.value = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (_error) {
|
||||||
|
// the preview is only informative
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (previewId === previewCount) {
|
||||||
|
previewing.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(selectedScene, fetchShareOptions);
|
||||||
|
|
||||||
|
// what a scene gets with the selected share modes, out of everything it could get
|
||||||
|
const emptyShareOption = { actors: [], tags: [], duration: null };
|
||||||
|
|
||||||
|
// shown before a scene is selected, with nothing to copy yet
|
||||||
|
function getPreviewScene(key, title, option = emptyShareOption, receives) {
|
||||||
|
const fields = new Set(Object.entries(share.value).filter(([, mode]) => mode === 'both' || mode === receives).map(([field]) => field));
|
||||||
|
|
||||||
|
const actors = fields.has('actors') ? option.actors : [];
|
||||||
|
const tags = fields.has('tags') ? option.tags : [];
|
||||||
|
const duration = fields.has('duration') ? option.duration : null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
key,
|
||||||
|
title,
|
||||||
|
actors,
|
||||||
|
tags,
|
||||||
|
duration,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const preview = computed(() => [
|
||||||
|
getPreviewScene('scene', sceneTitle.value, shareOptions.value?.scene, 'from'),
|
||||||
|
getPreviewScene('related', selectedScene.value ? relatedTitle.value : 'Related scene', shareOptions.value?.relatedScene, 'to'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
function formatDuration(seconds) {
|
||||||
|
const hours = Math.floor(seconds / 3600);
|
||||||
|
const minutes = Math.floor((seconds % 3600) / 60);
|
||||||
|
|
||||||
|
return [hours, minutes, seconds % 60].map((unit, index) => (index === 0 ? unit : String(unit).padStart(2, '0'))).join(':').replace(/^0:/, '');
|
||||||
|
}
|
||||||
|
|
||||||
const canSubmit = computed(() => !!selectedScene.value && !!selectedOption.value);
|
const canSubmit = computed(() => !!selectedScene.value && !!selectedOption.value);
|
||||||
const hasChanges = computed(() => !!selectedScene.value || !!selectedOption.value || comment.value.trim().length > 0);
|
const hasChanges = computed(() => !!selectedScene.value || !!selectedOption.value || comment.value.trim().length > 0);
|
||||||
|
|
||||||
@@ -169,6 +292,9 @@ function addRelation() {
|
|||||||
type: selectedOption.value.type,
|
type: selectedOption.value.type,
|
||||||
direction: selectedOption.value.direction,
|
direction: selectedOption.value.direction,
|
||||||
comment: comment.value.trim() || null,
|
comment: comment.value.trim() || null,
|
||||||
|
share: isSharing.value
|
||||||
|
? Object.fromEntries(Object.entries(share.value).filter(([, mode]) => mode !== 'none'))
|
||||||
|
: null,
|
||||||
scene: selectedScene.value,
|
scene: selectedScene.value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -194,7 +320,7 @@ onMounted(() => focusInput());
|
|||||||
>
|
>
|
||||||
|
|
||||||
<span class="info">
|
<span class="info">
|
||||||
<span class="title ellipsis">{{ scene.title || `Scene #${scene.id}` }}</span>
|
<h4 class="title ellipsis">{{ scene.title || `Scene #${scene.id}` }}</h4>
|
||||||
<span class="meta ellipsis">{{ formatSceneMeta(scene) }}</span>
|
<span class="meta ellipsis">{{ formatSceneMeta(scene) }}</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -226,7 +352,7 @@ onMounted(() => focusInput());
|
|||||||
>
|
>
|
||||||
|
|
||||||
<span class="info">
|
<span class="info">
|
||||||
<span class="title ellipsis">{{ selectedScene.title || `Scene #${selectedScene.id}` }}</span>
|
<h4 class="title ellipsis">{{ selectedScene.title || `Scene #${selectedScene.id}` }}</h4>
|
||||||
<span class="meta ellipsis">{{ formatSceneMeta(selectedScene) }}</span>
|
<span class="meta ellipsis">{{ formatSceneMeta(selectedScene) }}</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -278,7 +404,7 @@ onMounted(() => focusInput());
|
|||||||
>
|
>
|
||||||
|
|
||||||
<span class="info">
|
<span class="info">
|
||||||
<span class="title ellipsis">{{ result.title || `Scene #${result.id}` }}</span>
|
<h4 class="title ellipsis">{{ result.title || `Scene #${result.id}` }}</h4>
|
||||||
<span class="meta ellipsis">{{ formatSceneMeta(result) }}</span>
|
<span class="meta ellipsis">{{ formatSceneMeta(result) }}</span>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
@@ -291,12 +417,85 @@ onMounted(() => focusInput());
|
|||||||
</template>
|
</template>
|
||||||
</VDropdown>
|
</VDropdown>
|
||||||
|
|
||||||
<input
|
<div
|
||||||
|
class="share"
|
||||||
|
:class="{ disabled: !selectedOption && !selectedScene }"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="field in shareFields"
|
||||||
|
:key="`share-${field}`"
|
||||||
|
class="share-field"
|
||||||
|
>
|
||||||
|
<strong class="share-label">{{ shareFieldLabels[field] || field }}</strong>
|
||||||
|
|
||||||
|
<div class="share-modes">
|
||||||
|
<label
|
||||||
|
v-for="shareMode in getShareModes(field)"
|
||||||
|
:key="`share-${field}-${shareMode.mode}`"
|
||||||
|
v-tooltip="shareMode.title"
|
||||||
|
class="share-mode"
|
||||||
|
:class="{ active: (share[field] || 'none') === shareMode.mode }"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
v-model="share[field]"
|
||||||
|
type="radio"
|
||||||
|
:name="`share-${field}`"
|
||||||
|
:value="shareMode.mode"
|
||||||
|
class="share-radio"
|
||||||
|
>{{ shareMode.label }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="share-preview"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="previewScene in preview"
|
||||||
|
:key="`preview-${previewScene.key}`"
|
||||||
|
class="preview-scene"
|
||||||
|
>
|
||||||
|
<h4 class="heading preview-title">{{ previewScene.title }}</h4>
|
||||||
|
|
||||||
|
<span class="preview-row"><strong class="preview-label">New actors</strong>:
|
||||||
|
<Ellipsis
|
||||||
|
v-if="previewing"
|
||||||
|
class="preview-loading"
|
||||||
|
/>
|
||||||
|
<span v-else-if="previewScene.actors.length > 0">{{ previewScene.actors.map((actor) => actor.name).join(', ') }}</span>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="preview-none"
|
||||||
|
>None</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span class="preview-row"><strong class="preview-label">New tags</strong>:
|
||||||
|
<Ellipsis
|
||||||
|
v-if="previewing"
|
||||||
|
class="preview-loading"
|
||||||
|
/>
|
||||||
|
<span v-else-if="previewScene.tags.length > 0">{{ previewScene.tags.map((tag) => tag.name).join(', ') }}</span>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="preview-none"
|
||||||
|
>None</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span
|
||||||
|
v-if="previewScene.duration"
|
||||||
|
class="preview-row"
|
||||||
|
><strong class="preview-label">Duration</strong>: {{ formatDuration(previewScene.duration) }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<textarea
|
||||||
v-model="comment"
|
v-model="comment"
|
||||||
:maxlength="commentLimit"
|
:maxlength="commentLimit"
|
||||||
|
rows="2"
|
||||||
placeholder="Optional comment"
|
placeholder="Optional comment"
|
||||||
class="comment input"
|
class="comment input"
|
||||||
>
|
/>
|
||||||
|
|
||||||
<p
|
<p
|
||||||
v-if="inversion"
|
v-if="inversion"
|
||||||
@@ -331,6 +530,7 @@ onMounted(() => focusInput());
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
gap: .75rem;
|
gap: .75rem;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
overflow-y: auto;
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -338,6 +538,10 @@ onMounted(() => focusInput());
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dialog-heading {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.inversion {
|
.inversion {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -367,6 +571,121 @@ onMounted(() => focusInput());
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.share {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: .5rem;
|
||||||
|
margin-top: .5rem;
|
||||||
|
|
||||||
|
&.disabled {
|
||||||
|
opacity: .5;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-legend {
|
||||||
|
padding: 0 .25rem;
|
||||||
|
color: var(--glass-strong-10);
|
||||||
|
font-size: .9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-field {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: .25rem .75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-label {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 4.5rem;
|
||||||
|
font-size: .9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-modes {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: .25rem;
|
||||||
|
box-shadow: 0 0 3px var(--shadow-weak-30);
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-mode {
|
||||||
|
padding: .5rem .75rem;
|
||||||
|
font-size: .85rem;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
|
||||||
|
&:not(:last-child) {
|
||||||
|
border-right: solid 1px var(--glass-weak-40);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background: var(--primary);
|
||||||
|
color: var(--text-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:has(:focus-visible) {
|
||||||
|
outline: solid 2px var(--primary);
|
||||||
|
outline-offset: -2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-radio {
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-preview {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: .25rem;
|
||||||
|
margin: .5rem 0 0 0;
|
||||||
|
font-size: .9rem;
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.share-note {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--glass-strong-10);
|
||||||
|
font-size: .8rem;
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-title {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-row {
|
||||||
|
display: block;
|
||||||
|
margin: .25rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* the loader is sized for a page, keep it within a line of text */
|
||||||
|
.preview-loading {
|
||||||
|
width: 2.5rem;
|
||||||
|
height: 1em;
|
||||||
|
padding: 0;
|
||||||
|
align-items: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
|
||||||
|
:deep(.load-ellipsis) {
|
||||||
|
flex-shrink: 0;
|
||||||
|
transform: scale(.5);
|
||||||
|
transform-origin: left center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-none {
|
||||||
|
color: var(--glass-strong-10);
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
.dialog-actions {
|
.dialog-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -382,17 +701,20 @@ onMounted(() => focusInput());
|
|||||||
max-width: calc(100vw - 2rem);
|
max-width: calc(100vw - 2rem);
|
||||||
max-height: 18rem;
|
max-height: 18rem;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
padding: .25rem 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.scene {
|
.scene {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-shrink: 0;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: .5rem;
|
gap: .5rem;
|
||||||
padding: .25rem .5rem;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.result:not(:last-child) {
|
||||||
|
border-bottom: solid 1px var(--shadow-weak-40);
|
||||||
|
}
|
||||||
|
|
||||||
.result:hover {
|
.result:hover {
|
||||||
background: var(--glass-weak-50);
|
background: var(--glass-weak-50);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -431,7 +753,13 @@ onMounted(() => focusInput());
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
|
gap: .15rem;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: .9rem;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.meta,
|
.meta,
|
||||||
@@ -446,6 +774,9 @@ onMounted(() => focusInput());
|
|||||||
}
|
}
|
||||||
|
|
||||||
.comment {
|
.comment {
|
||||||
|
/* .input has flex-basis: 0, which collapses a textarea in the column layout, size it by its rows instead */
|
||||||
|
flex: 0 0 auto;
|
||||||
margin: .5rem 0 0 0;
|
margin: .5rem 0 0 0;
|
||||||
|
resize: vertical;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -497,6 +497,7 @@ function setView(newView) {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
scroll-margin-top: 3rem; /* ensure scroll into view includes meta bar */
|
scroll-margin-top: 3rem; /* ensure scroll into view includes meta bar */
|
||||||
|
padding-top: .5rem; /* clear campaign banner */
|
||||||
}
|
}
|
||||||
|
|
||||||
.meta {
|
.meta {
|
||||||
|
|||||||
@@ -174,6 +174,9 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
revisions: {
|
revisions: {
|
||||||
unapprovedLimit: 3,
|
unapprovedLimit: 3,
|
||||||
|
// scene properties that can be copied between related scenes, out of actors, tags and duration
|
||||||
|
// duration is off because intro and outro cards rarely make a rerelease match its original exactly
|
||||||
|
shareFields: ['actors', 'tags'],
|
||||||
},
|
},
|
||||||
psa: {
|
psa: {
|
||||||
text: 'Welcome to traxxx!', // html enabled
|
text: 'Welcome to traxxx!', // html enabled
|
||||||
|
|||||||
@@ -98,8 +98,9 @@ const fields = computed(() => [
|
|||||||
type: relation.type,
|
type: relation.type,
|
||||||
direction: relation.direction,
|
direction: relation.direction,
|
||||||
comment: relation.comment || null,
|
comment: relation.comment || null,
|
||||||
|
...(relation.share && { share: relation.share }), // copied once when the revision is applied
|
||||||
})),
|
})),
|
||||||
note: 'Relations point from a rerelease, remaster or compilation to the original scene. Each relation is shown on both scenes. Pick the closest type and use the comment to clarify how the scene was changed. Add a relation again to change its comment.',
|
note: 'Relations point from a rerelease, remaster or compilation to the original scene. Each relation is shown on both scenes. Pick the closest type and use the comment to clarify how the scene was changed. Actors and tags can be copied between the scenes when adding a relation. Add a relation again to change its comment or copy again.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'comment',
|
key: 'comment',
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ export function curateRevision(revision) {
|
|||||||
id: revision.id,
|
id: revision.id,
|
||||||
sceneId: revision.scene_id,
|
sceneId: revision.scene_id,
|
||||||
affectedSceneIds: revision.affected_scene_ids || [], // actor revisions have none
|
affectedSceneIds: revision.affected_scene_ids || [], // actor revisions have none
|
||||||
|
parentRevisionId: revision.parent_revision_id || null, // generated by sharing a relation, reviewed with the parent
|
||||||
actorId: revision.actor_id,
|
actorId: revision.actor_id,
|
||||||
base: revision.base,
|
base: revision.base,
|
||||||
deltas: revision.deltas,
|
deltas: revision.deltas,
|
||||||
|
|||||||
+429
-69
@@ -492,10 +492,23 @@ export async function fetchSceneRelations(sceneId, { reqUser, ...context } = {})
|
|||||||
}).filter(Boolean).reverse())).reverse(); // keep the oldest of any duplicates
|
}).filter(Boolean).reverse())).reverse(); // keep the oldest of any duplicates
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sharing copies actors, tags or duration between related scenes once, relative to the revised scene:
|
||||||
|
// 'from' the related scene into the revised scene, 'to' the related scene, or 'both' ways
|
||||||
|
const shareFields = (config.revisions.shareFields || []).filter((field) => ['actors', 'tags', 'duration'].includes(field));
|
||||||
|
const shareModes = ['none', 'from', 'to', 'both'];
|
||||||
|
|
||||||
export async function fetchRelationTypes() {
|
export async function fetchRelationTypes() {
|
||||||
return knex('relations_types')
|
const types = await knex('relations_types')
|
||||||
.select('type', 'symmetric')
|
.select('type', 'symmetric', 'share_defaults')
|
||||||
.orderBy('type');
|
.orderBy('type');
|
||||||
|
|
||||||
|
return types.map((type) => ({
|
||||||
|
type: type.type,
|
||||||
|
symmetric: type.symmetric,
|
||||||
|
// which side receives each field: source, target or both, limited to the fields that can be shared
|
||||||
|
shareDefaults: Object.fromEntries(Object.entries(type.share_defaults || {}).filter(([field]) => shareFields.includes(field))),
|
||||||
|
shareFields,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// relations in revisions are stored relative to the revised scene: { sceneId, type, direction, comment }
|
// relations in revisions are stored relative to the revised scene: { sceneId, type, direction, comment }
|
||||||
@@ -543,6 +556,26 @@ export async function fetchRevisionRelations(sceneId, trx) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function curateShare(share) {
|
||||||
|
if (!share) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof share !== 'object' || Array.isArray(share)) {
|
||||||
|
throw new HttpError('Relation share must be an object', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const curatedShare = Object.fromEntries(Object.entries(share).filter(([field]) => shareFields.includes(field)).map(([field, mode]) => {
|
||||||
|
if (!shareModes.includes(mode)) {
|
||||||
|
throw new HttpError(`Invalid share mode for ${field}: ${mode}`, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [field, mode];
|
||||||
|
}).filter(([, mode]) => mode !== 'none'));
|
||||||
|
|
||||||
|
return Object.keys(curatedShare).length > 0 ? curatedShare : null;
|
||||||
|
}
|
||||||
|
|
||||||
async function curateRelationsEdit(sceneId, relations) {
|
async function curateRelationsEdit(sceneId, relations) {
|
||||||
if (!Array.isArray(relations)) {
|
if (!Array.isArray(relations)) {
|
||||||
throw new HttpError('Relations must be a list', 400);
|
throw new HttpError('Relations must be a list', 400);
|
||||||
@@ -565,6 +598,7 @@ async function curateRelationsEdit(sceneId, relations) {
|
|||||||
comment: typeof relation.comment === 'string' && relation.comment.trim().length > 0
|
comment: typeof relation.comment === 'string' && relation.comment.trim().length > 0
|
||||||
? relation.comment.trim()
|
? relation.comment.trim()
|
||||||
: null,
|
: null,
|
||||||
|
share: curateShare(relation.share), // not part of the relation, stripped from the relations delta
|
||||||
};
|
};
|
||||||
|
|
||||||
return [getRelationKey(curatedRelation), curatedRelation];
|
return [getRelationKey(curatedRelation), curatedRelation];
|
||||||
@@ -597,6 +631,227 @@ async function curateRelationsEdit(sceneId, relations) {
|
|||||||
return curatedRelations;
|
return curatedRelations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getTagKey = (tag) => `${tag.id}:${tag.actorId || null}`;
|
||||||
|
|
||||||
|
// current actors, tags and duration of the scenes involved in sharing, and which tags may never be shared
|
||||||
|
async function fetchShareData(sceneIds) {
|
||||||
|
const [scenes, actors, tags, metaTagIds] = await Promise.all([
|
||||||
|
knexOwner('releases').select('id', 'duration', 'entity_id').whereIn('id', sceneIds),
|
||||||
|
knexOwner('releases_actors').select('id', 'release_id', 'actor_id', 'gender').whereIn('release_id', sceneIds),
|
||||||
|
knexOwner('releases_tags').select('release_id', 'tag_id', 'actor_id', 'source').whereIn('release_id', sceneIds).whereNotNull('tag_id'),
|
||||||
|
knexOwner('tags')
|
||||||
|
.leftJoin('tags_groups', 'tags_groups.id', 'tags.group_id')
|
||||||
|
.where('tags_groups.slug', 'meta') // describe the release rather than the scene, e.g. 4K or compilation
|
||||||
|
.pluck('tags.id'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// tags every scene of a channel gets, they belong to that channel's scenes
|
||||||
|
const entityTags = await knexOwner('entities_tags')
|
||||||
|
.select('entity_id', 'tag_id')
|
||||||
|
.whereIn('entity_id', Array.from(new Set(scenes.map((scene) => scene.entity_id))));
|
||||||
|
|
||||||
|
return {
|
||||||
|
metaTagIds: new Set(metaTagIds),
|
||||||
|
scenes: Object.fromEntries(scenes.map((scene) => {
|
||||||
|
const entityTagIds = new Set(entityTags.filter((entityTag) => entityTag.entity_id === scene.entity_id).map((entityTag) => entityTag.tag_id));
|
||||||
|
const sceneTags = tags.filter((tag) => tag.release_id === scene.id);
|
||||||
|
const sceneActors = actors.filter((actor) => actor.release_id === scene.id);
|
||||||
|
|
||||||
|
return [scene.id, {
|
||||||
|
id: scene.id,
|
||||||
|
duration: scene.duration,
|
||||||
|
// unidentified actors use the same IDs as for editing, so a child revision keeps them
|
||||||
|
actors: sceneActors.map((actor) => actor.actor_id || `${actor.gender || 'other'}_${actor.id}`),
|
||||||
|
actorIds: sceneActors.map((actor) => actor.actor_id).filter(Boolean), // only identified actors are shared
|
||||||
|
tags: sceneTags.map((tag) => ({ id: tag.tag_id, actorId: tag.actor_id })),
|
||||||
|
// implied tags are derived again on the receiving scene, channel tags only apply to their own channel
|
||||||
|
unshareableTagKeys: new Set(sceneTags
|
||||||
|
.filter((tag) => tag.source === 'implied' || (tag.source !== 'editor' && entityTagIds.has(tag.tag_id)))
|
||||||
|
.map((tag) => getTagKey({ id: tag.tag_id, actorId: tag.actor_id }))),
|
||||||
|
}];
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getShareableTags(state, metaTagIds) {
|
||||||
|
return state.tags.filter((tag) => !metaTagIds.has(tag.id) && !state.unshareableTagKeys.has(getTagKey(tag)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge what the giving scene has into the receiving scene, never removing or overwriting anything
|
||||||
|
function receiveShare(receiver, giver, fields, metaTagIds) {
|
||||||
|
const received = {};
|
||||||
|
|
||||||
|
if (fields.includes('actors')) {
|
||||||
|
const actorIds = Array.from(new Set([...receiver.actors, ...giver.actorIds]));
|
||||||
|
|
||||||
|
if (actorIds.length > receiver.actors.length) {
|
||||||
|
received.actors = actorIds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fields.includes('tags')) {
|
||||||
|
const finalActorIds = new Set(received.actors || receiver.actors);
|
||||||
|
const tagsByKey = new Map(receiver.tags.map((tag) => [getTagKey(tag), tag]));
|
||||||
|
const receiverTagIds = new Set(receiver.tags.map((tag) => tag.id));
|
||||||
|
|
||||||
|
getShareableTags(giver, metaTagIds).forEach((tag) => {
|
||||||
|
// an actor-specific tag only keeps its actor if the actor is in the receiving scene
|
||||||
|
const keepsActor = !tag.actorId || finalActorIds.has(tag.actorId);
|
||||||
|
const sharedTag = { id: tag.id, actorId: keepsActor ? tag.actorId : null };
|
||||||
|
|
||||||
|
// a tag that lost its actor adds nothing if the receiving scene already has the tag in any form
|
||||||
|
if (!keepsActor && receiverTagIds.has(tag.id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tagsByKey.has(getTagKey(sharedTag))) {
|
||||||
|
tagsByKey.set(getTagKey(sharedTag), sharedTag);
|
||||||
|
receiverTagIds.add(tag.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tagsByKey.size > receiver.tags.length) {
|
||||||
|
received.tags = Array.from(tagsByKey.values());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// duration can't be merged, only fill it in
|
||||||
|
if (fields.includes('duration') && !receiver.duration && giver.duration) {
|
||||||
|
received.duration = giver.duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
return received;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getShareFields(share, receives) {
|
||||||
|
return Object.entries(share || {})
|
||||||
|
.filter(([, mode]) => mode === 'both' || mode === receives)
|
||||||
|
.map(([field]) => field);
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolve relation shares into edits for the revised scene, and edits for each related scene that become child revisions
|
||||||
|
// shares are resolved against the state before sharing, so what one related scene gives isn't passed on to another
|
||||||
|
async function resolveShares(baseScene, edits, relations) {
|
||||||
|
const sharedRelations = relations.filter((relation) => relation.share);
|
||||||
|
|
||||||
|
if (sharedRelations.length === 0) {
|
||||||
|
return { edits, children: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const shareData = await fetchShareData([baseScene.id, ...sharedRelations.map((relation) => relation.sceneId)]);
|
||||||
|
const ownData = shareData.scenes[baseScene.id];
|
||||||
|
|
||||||
|
// the revised scene gives what it will have after this revision's own edits
|
||||||
|
const ownTags = edits.tags?.map((tag) => ({ id: tag.id, actorId: tag.actorId || null })) || ownData.tags;
|
||||||
|
|
||||||
|
const ownGiver = {
|
||||||
|
...ownData,
|
||||||
|
actorIds: (edits.actors || baseScene.actors).filter((actorId) => typeof actorId === 'number'), // unidentified actors aren't shared
|
||||||
|
tags: ownTags,
|
||||||
|
duration: edits.duration ?? baseScene.duration,
|
||||||
|
};
|
||||||
|
|
||||||
|
const ownReceiver = {
|
||||||
|
actors: edits.actors || baseScene.actors,
|
||||||
|
tags: ownTags,
|
||||||
|
duration: edits.duration ?? baseScene.duration,
|
||||||
|
};
|
||||||
|
|
||||||
|
const sharedEdits = { ...edits };
|
||||||
|
const children = [];
|
||||||
|
|
||||||
|
sharedRelations.forEach((relation) => {
|
||||||
|
const related = shareData.scenes[relation.sceneId];
|
||||||
|
|
||||||
|
if (!related) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ownFields = getShareFields(relation.share, 'from');
|
||||||
|
const relatedFields = getShareFields(relation.share, 'to');
|
||||||
|
|
||||||
|
if (ownFields.length > 0) {
|
||||||
|
const received = receiveShare({
|
||||||
|
actors: sharedEdits.actors || ownReceiver.actors,
|
||||||
|
tags: sharedEdits.tags || ownReceiver.tags,
|
||||||
|
duration: sharedEdits.duration ?? ownReceiver.duration,
|
||||||
|
}, related, ownFields, shareData.metaTagIds);
|
||||||
|
|
||||||
|
Object.assign(sharedEdits, received);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relatedFields.length > 0) {
|
||||||
|
const received = receiveShare({
|
||||||
|
actors: related.actors,
|
||||||
|
tags: related.tags,
|
||||||
|
duration: related.duration,
|
||||||
|
}, ownGiver, relatedFields, shareData.metaTagIds);
|
||||||
|
|
||||||
|
if (Object.keys(received).length > 0) {
|
||||||
|
children.push({
|
||||||
|
sceneId: relation.sceneId,
|
||||||
|
relation,
|
||||||
|
edits: received,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return { edits: sharedEdits, children };
|
||||||
|
}
|
||||||
|
|
||||||
|
// what each of two scenes would get from the other if every shareable field were copied both ways, for the relation dialog
|
||||||
|
// the dialog filters this by the selected share modes, so it doesn't depend on the relation type or the modes
|
||||||
|
export async function previewRelationShare(sceneId, { sceneId: rawRelatedSceneId }, reqUser) {
|
||||||
|
if (!reqUser) {
|
||||||
|
throw new HttpError('Must be authenticated to preview sharing', 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
const relatedSceneId = Number(rawRelatedSceneId);
|
||||||
|
|
||||||
|
if (!Number.isInteger(relatedSceneId) || relatedSceneId === sceneId) {
|
||||||
|
throw new HttpError('Sharing requires a different scene', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { scenes } = await fetchShareData([sceneId, relatedSceneId]);
|
||||||
|
const own = scenes[sceneId];
|
||||||
|
const related = scenes[relatedSceneId];
|
||||||
|
|
||||||
|
if (!own || !related) {
|
||||||
|
throw new HttpError(`No scene with ID ${own ? relatedSceneId : sceneId} found`, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const share = Object.fromEntries(shareFields.map((field) => [field, 'both']));
|
||||||
|
const { edits, children: [child] } = await resolveShares({ id: sceneId, actors: own.actors, duration: own.duration }, {}, [{ sceneId: relatedSceneId, type: null, share }]);
|
||||||
|
|
||||||
|
const getAdded = (received = {}, current) => ({
|
||||||
|
actorIds: (received.actors || []).filter((actorId) => typeof actorId === 'number' && !current.actorIds.includes(actorId)),
|
||||||
|
tagIds: Array.from(new Set((received.tags || [])
|
||||||
|
.filter((tag) => !current.tags.some((currentTag) => currentTag.id === tag.id))
|
||||||
|
.map((tag) => tag.id))),
|
||||||
|
duration: received.duration || null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const ownAdded = getAdded(edits, own);
|
||||||
|
const relatedAdded = getAdded(child?.edits, related);
|
||||||
|
|
||||||
|
const [actors, tags] = await Promise.all([
|
||||||
|
knexOwner('actors').select('id', 'name', 'slug').whereIn('id', [...ownAdded.actorIds, ...relatedAdded.actorIds]),
|
||||||
|
knexOwner('tags').select('id', 'name', 'slug').whereIn('id', [...ownAdded.tagIds, ...relatedAdded.tagIds]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const curateAdded = (added) => ({
|
||||||
|
actors: added.actorIds.map((actorId) => actors.find((actor) => actor.id === actorId)).filter(Boolean),
|
||||||
|
tags: added.tagIds.map((tagId) => tags.find((tag) => tag.id === tagId)).filter(Boolean),
|
||||||
|
duration: added.duration,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
scene: curateAdded(ownAdded),
|
||||||
|
relatedScene: curateAdded(relatedAdded),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const sqlImplied = ['scenes_stashed'];
|
const sqlImplied = ['scenes_stashed'];
|
||||||
|
|
||||||
function curateOptions(options) {
|
function curateOptions(options) {
|
||||||
@@ -1098,7 +1353,20 @@ export async function fetchSceneRevisions(revisionId, filters = {}, reqUser) {
|
|||||||
: [],
|
: [],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const curatedRevisions = revisions.map((revision) => curateRevision(revision));
|
// revisions generated for related scenes by sharing a relation, reviewed and applied with their parent
|
||||||
|
const childRevisions = revisions.length > 0
|
||||||
|
? await knexOwner('scenes_revisions')
|
||||||
|
.select('id', 'scene_id', 'parent_revision_id')
|
||||||
|
.whereIn('parent_revision_id', revisions.map((revision) => revision.id))
|
||||||
|
.orderBy('id')
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const curatedRevisions = revisions.map((revision) => ({
|
||||||
|
...curateRevision(revision),
|
||||||
|
childRevisions: childRevisions
|
||||||
|
.filter((child) => child.parent_revision_id === revision.id)
|
||||||
|
.map((child) => ({ id: child.id, sceneId: child.scene_id })),
|
||||||
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
revisions: curatedRevisions,
|
revisions: curatedRevisions,
|
||||||
@@ -1300,61 +1568,77 @@ async function applySceneDeleteDelta(sceneId, _delta, trx, reqUser) {
|
|||||||
.transacting(trx);
|
.transacting(trx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function applySceneRevisionDeltas(revision, trx, reqUser) {
|
||||||
|
await Promise.all(revision.deltas.map(async (delta) => {
|
||||||
|
if (delta.key === 'delete') {
|
||||||
|
return applySceneDeleteDelta(revision.scene_id, delta, trx, reqUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([
|
||||||
|
'title',
|
||||||
|
'description',
|
||||||
|
'date',
|
||||||
|
'url',
|
||||||
|
'datePrecision',
|
||||||
|
'duration',
|
||||||
|
'productionDate',
|
||||||
|
'productionLocation',
|
||||||
|
'productionCity',
|
||||||
|
'productionState',
|
||||||
|
].includes(delta.key)) {
|
||||||
|
return applySceneValueDelta(revision.scene_id, delta, trx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delta.key === 'actors') {
|
||||||
|
return applySceneActorsDelta(revision.scene_id, delta, trx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delta.key === 'tags') {
|
||||||
|
return applySceneTagsDelta(revision.scene_id, delta, trx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delta.key === 'movies') {
|
||||||
|
return applySceneMoviesDelta(revision.scene_id, delta, trx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delta.key === 'relations') {
|
||||||
|
return applySceneRelationsDelta(revision, delta, trx);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}));
|
||||||
|
|
||||||
|
await knexOwner('scenes_revisions')
|
||||||
|
.where('id', revision.id)
|
||||||
|
.update('applied_at', knexOwner.fn.now())
|
||||||
|
.transacting(trx);
|
||||||
|
}
|
||||||
|
|
||||||
// sync: false leaves syncing to the caller, i.e. to sync once after applying revisions in bulk
|
// sync: false leaves syncing to the caller, i.e. to sync once after applying revisions in bulk
|
||||||
async function applySceneRevision(revisionIds, reqUser, { sync = true } = {}) {
|
async function applySceneRevision(revisionIds, reqUser, { sync = true } = {}) {
|
||||||
const revisions = await knexOwner('scenes_revisions')
|
const revisions = await knexOwner('scenes_revisions')
|
||||||
.whereIn('id', revisionIds)
|
.whereIn('id', revisionIds)
|
||||||
.whereNull('applied_at'); // should not re-apply revision that was already applied
|
.whereNull('applied_at'); // should not re-apply revision that was already applied
|
||||||
|
|
||||||
|
// revisions generated by sharing a relation are applied together with their parent
|
||||||
|
const children = await knexOwner('scenes_revisions')
|
||||||
|
.whereIn('parent_revision_id', revisions.map((revision) => revision.id))
|
||||||
|
.whereNotIn('id', revisions.map((revision) => revision.id))
|
||||||
|
.whereNull('applied_at')
|
||||||
|
.orderBy('id');
|
||||||
|
|
||||||
await revisions.reduce(async (chain, revision) => {
|
await revisions.reduce(async (chain, revision) => {
|
||||||
await chain;
|
await chain;
|
||||||
|
|
||||||
await knexOwner.transaction(async (trx) => {
|
await knexOwner.transaction(async (trx) => {
|
||||||
await Promise.all(revision.deltas.map(async (delta) => {
|
await applySceneRevisionDeltas(revision, trx, reqUser);
|
||||||
if (delta.key === 'delete') {
|
|
||||||
return applySceneDeleteDelta(revision.scene_id, delta, trx, reqUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([
|
await children
|
||||||
'title',
|
.filter((child) => child.parent_revision_id === revision.id)
|
||||||
'description',
|
.reduce(async (childChain, child) => {
|
||||||
'date',
|
await childChain;
|
||||||
'url',
|
await applySceneRevisionDeltas(child, trx, reqUser);
|
||||||
'datePrecision',
|
}, Promise.resolve());
|
||||||
'duration',
|
|
||||||
'productionDate',
|
|
||||||
'productionLocation',
|
|
||||||
'productionCity',
|
|
||||||
'productionState',
|
|
||||||
].includes(delta.key)) {
|
|
||||||
return applySceneValueDelta(revision.scene_id, delta, trx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (delta.key === 'actors') {
|
|
||||||
return applySceneActorsDelta(revision.scene_id, delta, trx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (delta.key === 'tags') {
|
|
||||||
return applySceneTagsDelta(revision.scene_id, delta, trx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (delta.key === 'movies') {
|
|
||||||
return applySceneMoviesDelta(revision.scene_id, delta, trx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (delta.key === 'relations') {
|
|
||||||
return applySceneRelationsDelta(revision, delta, trx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}));
|
|
||||||
|
|
||||||
await knexOwner('scenes_revisions')
|
|
||||||
.where('id', revision.id)
|
|
||||||
.update('applied_at', knexOwner.fn.now())
|
|
||||||
.transacting(trx);
|
|
||||||
|
|
||||||
// await trx.commit();
|
|
||||||
}).catch(async (error) => {
|
}).catch(async (error) => {
|
||||||
logger.error(`Failed to apply revision ${revision.id} on scene ${revision.scene_id}: ${error.message}`);
|
logger.error(`Failed to apply revision ${revision.id} on scene ${revision.scene_id}: ${error.message}`);
|
||||||
throw error;
|
throw error;
|
||||||
@@ -1362,7 +1646,7 @@ async function applySceneRevision(revisionIds, reqUser, { sync = true } = {}) {
|
|||||||
}, Promise.resolve());
|
}, Promise.resolve());
|
||||||
|
|
||||||
if (sync) {
|
if (sync) {
|
||||||
const sceneIds = Array.from(new Set(revisions.map((revision) => revision.scene_id)));
|
const sceneIds = Array.from(new Set([...revisions, ...children].map((revision) => revision.scene_id)));
|
||||||
|
|
||||||
await syncScenes(sceneIds);
|
await syncScenes(sceneIds);
|
||||||
}
|
}
|
||||||
@@ -1377,6 +1661,15 @@ export async function reviewSceneRevision(revisionId, isApproved, { feedback },
|
|||||||
throw new HttpError('You must either approve or reject the revision', 400);
|
throw new HttpError('You must either approve or reject the revision', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const revision = await knexOwner('scenes_revisions')
|
||||||
|
.select('id', 'parent_revision_id')
|
||||||
|
.where('id', revisionId)
|
||||||
|
.first();
|
||||||
|
|
||||||
|
if (revision?.parent_revision_id) {
|
||||||
|
throw new HttpError(`This revision was generated by sharing a relation, review revision #${revision.parent_revision_id} instead`, 400);
|
||||||
|
}
|
||||||
|
|
||||||
const updated = await knexOwner('scenes_revisions')
|
const updated = await knexOwner('scenes_revisions')
|
||||||
.where('id', revisionId)
|
.where('id', revisionId)
|
||||||
.whereNull('approved') // don't rerun reviewed revision, must be forked into new revision instead
|
.whereNull('approved') // don't rerun reviewed revision, must be forked into new revision instead
|
||||||
@@ -1392,6 +1685,16 @@ export async function reviewSceneRevision(revisionId, isApproved, { feedback },
|
|||||||
throw new HttpError('This revision was already reviewed', 409);
|
throw new HttpError('This revision was already reviewed', 409);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// revisions generated by sharing a relation share their parent's review
|
||||||
|
await knexOwner('scenes_revisions')
|
||||||
|
.where('parent_revision_id', revisionId)
|
||||||
|
.whereNull('approved')
|
||||||
|
.update({
|
||||||
|
approved: isApproved,
|
||||||
|
reviewed_at: knex.fn.now(),
|
||||||
|
reviewed_by: reqUser.id,
|
||||||
|
});
|
||||||
|
|
||||||
if (isApproved) {
|
if (isApproved) {
|
||||||
try {
|
try {
|
||||||
await applySceneRevision([revisionId], reqUser, options);
|
await applySceneRevision([revisionId], reqUser, options);
|
||||||
@@ -1399,6 +1702,7 @@ export async function reviewSceneRevision(revisionId, isApproved, { feedback },
|
|||||||
catch (error) {
|
catch (error) {
|
||||||
await knexOwner('scenes_revisions')
|
await knexOwner('scenes_revisions')
|
||||||
.where('id', revisionId)
|
.where('id', revisionId)
|
||||||
|
.orWhere('parent_revision_id', revisionId)
|
||||||
.update({
|
.update({
|
||||||
approved: null,
|
approved: null,
|
||||||
reviewed_at: null,
|
reviewed_at: null,
|
||||||
@@ -1411,7 +1715,8 @@ export async function reviewSceneRevision(revisionId, isApproved, { feedback },
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dryRun validates the edits and returns the deltas without storing a revision
|
// dryRun validates the edits and returns the deltas without storing a revision
|
||||||
export async function createSceneRevision(sceneId, { edits, comment, apply }, reqUser, { dryRun = false } = {}) {
|
// isChild is used internally for revisions generated by sharing a relation, they return their entry instead of storing it
|
||||||
|
export async function createSceneRevision(sceneId, { edits, comment, apply }, reqUser, { dryRun = false, isChild = false } = {}) {
|
||||||
if (!reqUser) {
|
if (!reqUser) {
|
||||||
throw new HttpError('Must be authenticated to create scene revision', 401);
|
throw new HttpError('Must be authenticated to create scene revision', 401);
|
||||||
}
|
}
|
||||||
@@ -1430,7 +1735,8 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
|
|||||||
}),
|
}),
|
||||||
knexOwner('scenes_revisions')
|
knexOwner('scenes_revisions')
|
||||||
.where('user_id', reqUser.id)
|
.where('user_id', reqUser.id)
|
||||||
.whereNull('approved'),
|
.whereNull('approved')
|
||||||
|
.whereNull('parent_revision_id'), // revisions generated by sharing are reviewed with their parent
|
||||||
fetchRevisionRelations(sceneId),
|
fetchRevisionRelations(sceneId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -1438,7 +1744,7 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
|
|||||||
throw new HttpError(`No scene with ID ${sceneId} found to update`, 404);
|
throw new HttpError(`No scene with ID ${sceneId} found to update`, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openRevisions.length >= config.revisions.unapprovedLimit && reqUser.role !== 'admin') {
|
if (!isChild && openRevisions.length >= config.revisions.unapprovedLimit && reqUser.role !== 'admin') {
|
||||||
throw new HttpError(`You have ${config.revisions.unapprovedLimit} unapproved revisions, please wait for approval before submitting another revision.`, 429);
|
throw new HttpError(`You have ${config.revisions.unapprovedLimit} unapproved revisions, please wait for approval before submitting another revision.`, 429);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1487,7 +1793,27 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
|
|||||||
? await curateRelationsEdit(scene.id, edits.relations)
|
? await curateRelationsEdit(scene.id, edits.relations)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const deltas = Object.entries(edits).map(([key, value]) => {
|
// what this scene receives from related scenes is merged into its own edits, what it gives becomes revisions for the related scenes
|
||||||
|
const { edits: sharedEdits, children: sharedScenes } = curatedRelations && !isChild
|
||||||
|
? await resolveShares(baseScene, edits, curatedRelations)
|
||||||
|
: { edits, children: [] };
|
||||||
|
|
||||||
|
const children = (await Promise.all(sharedScenes.map(async (child) => createSceneRevision(child.sceneId, {
|
||||||
|
edits: child.edits,
|
||||||
|
comment: `Shared ${Object.keys(child.edits).join(', ')} from #${scene.id} through ${child.relation.type} relation`,
|
||||||
|
}, reqUser, {
|
||||||
|
dryRun: true,
|
||||||
|
isChild: true,
|
||||||
|
}).catch((error) => {
|
||||||
|
// the related scene already has everything shared with it
|
||||||
|
if (error instanceof HttpError && error.httpCode === 400 && /No effective changes/.test(error.message)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
})))).filter(Boolean);
|
||||||
|
|
||||||
|
const deltas = Object.entries(sharedEdits).map(([key, value]) => {
|
||||||
if (key === 'delete') {
|
if (key === 'delete') {
|
||||||
return { key: 'delete' };
|
return { key: 'delete' };
|
||||||
}
|
}
|
||||||
@@ -1503,7 +1829,7 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { key, value: curatedRelations };
|
return { key, value: curatedRelations.map(({ share: _share, ...relation }) => relation) };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baseScene[key] === value || typeof value === 'undefined') {
|
if (baseScene[key] === value || typeof value === 'undefined') {
|
||||||
@@ -1534,11 +1860,35 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
|
|||||||
return { key, value };
|
return { key, value };
|
||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
|
|
||||||
if (deltas.length === 0) {
|
// a revision that only shares with related scenes has no deltas of its own
|
||||||
|
if (deltas.length === 0 && children.length === 0) {
|
||||||
throw new HttpError('No effective changes provided', 400);
|
throw new HttpError('No effective changes provided', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
const affectedSceneIds = getAffectedSceneIds(baseScene, deltas);
|
const affectedSceneIds = Array.from(new Set([
|
||||||
|
...getAffectedSceneIds(baseScene, deltas),
|
||||||
|
...children.map((child) => child.sceneId),
|
||||||
|
]));
|
||||||
|
|
||||||
|
const entry = {
|
||||||
|
user_id: reqUser.id,
|
||||||
|
scene_id: scene.id,
|
||||||
|
affected_scene_ids: affectedSceneIds,
|
||||||
|
base: JSON.stringify(baseScene),
|
||||||
|
deltas: JSON.stringify(deltas),
|
||||||
|
hash: mj.hash({
|
||||||
|
base: baseScene,
|
||||||
|
deltas,
|
||||||
|
}),
|
||||||
|
comment,
|
||||||
|
};
|
||||||
|
|
||||||
|
const curatedChildren = children.map((child) => ({
|
||||||
|
id: child.id,
|
||||||
|
sceneId: child.sceneId,
|
||||||
|
deltas: child.deltas,
|
||||||
|
comment: child.comment,
|
||||||
|
}));
|
||||||
|
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
return {
|
return {
|
||||||
@@ -1546,23 +1896,32 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
|
|||||||
sceneId: scene.id,
|
sceneId: scene.id,
|
||||||
deltas,
|
deltas,
|
||||||
affectedSceneIds,
|
affectedSceneIds,
|
||||||
|
children: curatedChildren,
|
||||||
|
comment,
|
||||||
|
...(isChild && { entry }),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const [revisionEntry] = await knexOwner('scenes_revisions')
|
const revisionEntry = await knexOwner.transaction(async (trx) => {
|
||||||
.insert({
|
const [parentEntry] = await trx('scenes_revisions')
|
||||||
user_id: reqUser.id,
|
.insert(entry)
|
||||||
scene_id: scene.id,
|
.returning('id');
|
||||||
affected_scene_ids: affectedSceneIds,
|
|
||||||
base: JSON.stringify(baseScene),
|
if (children.length > 0) {
|
||||||
deltas: JSON.stringify(deltas),
|
const childEntries = await trx('scenes_revisions')
|
||||||
hash: mj.hash({
|
.insert(children.map((child) => ({
|
||||||
base: baseScene,
|
...child.entry,
|
||||||
deltas,
|
parent_revision_id: parentEntry.id,
|
||||||
}),
|
})))
|
||||||
comment,
|
.returning(['id', 'scene_id']);
|
||||||
})
|
|
||||||
.returning('id');
|
children.forEach((child, index) => {
|
||||||
|
curatedChildren[index].id = childEntries[index].id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return parentEntry;
|
||||||
|
});
|
||||||
|
|
||||||
if (['admin', 'editor'].includes(reqUser.role) && apply) {
|
if (['admin', 'editor'].includes(reqUser.role) && apply) {
|
||||||
// don't keep the editor waiting for the revision to apply
|
// don't keep the editor waiting for the revision to apply
|
||||||
@@ -1574,5 +1933,6 @@ export async function createSceneRevision(sceneId, { edits, comment, apply }, re
|
|||||||
sceneId: scene.id,
|
sceneId: scene.id,
|
||||||
deltas,
|
deltas,
|
||||||
affectedSceneIds,
|
affectedSceneIds,
|
||||||
|
children: curatedChildren,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
fetchSceneRevisions,
|
fetchSceneRevisions,
|
||||||
fetchScenes,
|
fetchScenes,
|
||||||
fetchScenesById,
|
fetchScenesById,
|
||||||
|
previewRelationShare,
|
||||||
reviewSceneRevision,
|
reviewSceneRevision,
|
||||||
} from '../scenes.js';
|
} from '../scenes.js';
|
||||||
import { fetchStashByUsernameAndSlug } from '../stashes.js';
|
import { fetchStashByUsernameAndSlug } from '../stashes.js';
|
||||||
@@ -311,6 +312,12 @@ async function createSceneRevisionApi(req, res) {
|
|||||||
res.status(204).send();
|
res.status(204).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function previewRelationShareApi(req, res) {
|
||||||
|
const preview = await previewRelationShare(Number(req.params.sceneId), req.body, req.user);
|
||||||
|
|
||||||
|
res.send(preview);
|
||||||
|
}
|
||||||
|
|
||||||
async function reviewSceneRevisionApi(req, res) {
|
async function reviewSceneRevisionApi(req, res) {
|
||||||
await reviewSceneRevision(Number(req.params.revisionId), req.body.isApproved, req.body, req.user);
|
await reviewSceneRevision(Number(req.params.revisionId), req.body.isApproved, req.body, req.user);
|
||||||
|
|
||||||
@@ -321,6 +328,7 @@ export const scenesRouter = Router();
|
|||||||
|
|
||||||
scenesRouter.get('/api/scenes', fetchScenesApi);
|
scenesRouter.get('/api/scenes', fetchScenesApi);
|
||||||
scenesRouter.get('/api/scenes/:sceneId', fetchSceneApi);
|
scenesRouter.get('/api/scenes/:sceneId', fetchSceneApi);
|
||||||
|
scenesRouter.post('/api/scenes/:sceneId/relations/share-preview', previewRelationShareApi);
|
||||||
|
|
||||||
scenesRouter.get('/api/revisions/scenes', fetchSceneRevisionsApi);
|
scenesRouter.get('/api/revisions/scenes', fetchSceneRevisionsApi);
|
||||||
scenesRouter.get('/api/revisions/scenes/:revisionId', fetchSceneRevisionsApi);
|
scenesRouter.get('/api/revisions/scenes/:revisionId', fetchSceneRevisionsApi);
|
||||||
|
|||||||
Reference in New Issue
Block a user