Added affiliate parameters to scene URL.

This commit is contained in:
DebaucheryLibrarian 2024-06-22 22:51:57 +02:00
parent c2edf72081
commit 9ce9cfbb0c
8 changed files with 97 additions and 13 deletions

View File

@ -210,6 +210,7 @@
</li>
<li
v-if="user"
class="menu-button menu-item logout"
@click="logout"
><Icon icon="exit2" />Log out</li>

View File

@ -63,7 +63,7 @@
</div>
<Link
:href="scene.url"
:href="scene.watchUrl"
:title="scene.date ? format(scene.date.toISOString(), 'y-MM-dd hh:mm') : `Release date unknown, added ${format(scene.createdAt, 'y-MM-dd')}`"
target="_blank"
class="date-link nolink"

View File

@ -2,10 +2,13 @@
<div class="page">
<div class="header">
<a
:href="entity.url"
:href="entityUrl"
target="_blank"
rel="noopener"
class="link link-child"
:data-umami-event="entity.affiliate ? 'entity-click-aff' : 'entity-click'"
:data-umami-event-aff-id="entity.affiliate?.id"
:data-umami-event-entity="entity.slug"
>
<template v-if="entity.hasLogo">
<img
@ -113,6 +116,23 @@ const children = ref(null);
const expanded = ref(false);
const scrollable = computed(() => children.value?.scrollWidth > children.value?.clientWidth);
const entityUrl = (() => {
if (!entity.url) {
return null;
}
if (!entity.affiliate?.parameters) {
return entity.url;
}
const newParams = new URLSearchParams({
...Object.fromEntries(new URL(entity.url).searchParams),
...Object.fromEntries(new URLSearchParams(entity.affiliate.parameters)),
});
return `${entity.url}?${newParams}`;
})();
</script>
<style scoped>

View File

@ -92,7 +92,7 @@
</div>
<Link
:href="scene.url"
:href="scene.watchUrl"
:title="scene.date ? formatDate(scene.date.toISOString(), 'y-MM-dd hh:mm') : `Release date unknown, added ${formatDate(scene.createdAt, 'y-MM-dd')}`"
target="_blank"
class="date nolink"
@ -142,10 +142,13 @@
-->
<Link
v-if="scene.url"
:href="scene.url"
v-if="scene.watchUrl"
:href="scene.watchUrl"
target="_blank"
class="button button-primary watch nolink"
:data-umami-event="scene.affiliate ? 'watch-click-aff' : 'watch-click'"
:data-umami-event-aff-id="scene.affiliate?.id"
:data-umami-event-scene-id="scene.id"
>Watch full video</Link>
</div>
</div>

View File

@ -19,6 +19,11 @@ export function curateEntity(entity, context) {
hasLogo: entity.has_logo,
parent: curateEntity(entity.parent, context),
children: context?.children?.filter((child) => child.parent_id === entity.id).map((child) => curateEntity({ ...child, parent: entity }, { parent: entity })) || [],
affiliate: entity.affiliate ? {
id: entity.affiliate.id,
url: entity.affiliate.url,
parameters: entity.affiliate.parameters,
} : null,
...context?.append?.[entity.id],
};
}
@ -66,15 +71,20 @@ export async function fetchEntities(options) {
export async function fetchEntitiesById(entityIds, options = {}) {
const [entities, children] = await Promise.all([
knex('entities')
.select('entities.*', knex.raw('row_to_json(parents) as parent'))
.select(
'entities.*',
knex.raw('row_to_json(parents) as parent'),
knex.raw('row_to_json(affiliates) as affiliate'),
)
.whereIn('entities.id', entityIds)
.leftJoin('entities as parents', 'parents.id', 'entities.parent_id')
.leftJoin('affiliates', knex.raw('affiliates.entity_id in (entities.id, parents.id)'))
.modify((builder) => {
if (options.order) {
builder.orderBy(...options.order);
}
})
.groupBy('entities.id', 'parents.id'),
.groupBy('entities.id', 'parents.id', 'affiliates.id'),
options.includeChildren ? knex('entities')
.whereIn('entities.parent_id', entityIds)
.orderBy('slug') : [],

View File

@ -12,12 +12,47 @@ import { curateMedia } from './media.js';
import escape from '../utils/escape-manticore.js';
import promiseProps from '../utils/promise-props.js';
function getWatchUrl(scene) {
if (scene.url) {
return scene.url;
}
if (scene.channel && (scene.channel.isIndependent || scene.channel.type === 'network')) {
return scene.channel.url;
}
if (scene.network) {
return scene.network.url;
}
return null;
}
function getAffiliateUrl(scene) {
const watchUrl = getWatchUrl(scene);
if (!watchUrl) {
return null;
}
if (!scene.affiliate?.parameters) {
return scene.url;
}
const newParams = new URLSearchParams({
...Object.fromEntries(new URL(watchUrl).searchParams),
...Object.fromEntries(new URLSearchParams(scene.affiliate.parameters)),
});
return `${watchUrl}?${newParams.toString()}`;
}
function curateScene(rawScene, assets) {
if (!rawScene) {
return null;
}
return {
const curatedScene = {
id: rawScene.id,
title: rawScene.title,
slug: rawScene.slug,
@ -43,6 +78,11 @@ function curateScene(rawScene, assets) {
type: assets.channel.network_type,
hasLogo: assets.channel.has_logo,
} : null,
affiliate: assets.channel.affiliate ? {
id: assets.channel.affiliate.id,
url: assets.channel.affiliate.url,
parameters: assets.channel.affiliate.parameters,
} : null,
actors: sortActorsByGender(assets.actors.map((actor) => curateActor(actor, {
sceneDate: rawScene.effective_date,
stashes: assets.actorStashes.filter((actorStash) => actorStash.actor_id === actor.id),
@ -80,6 +120,10 @@ function curateScene(rawScene, assets) {
updatedBatchId: rawScene.updated_batch_id,
isNew: assets.lastBatchId === rawScene.created_batch_id,
};
curatedScene.watchUrl = getAffiliateUrl(curatedScene);
return curatedScene;
}
export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
@ -101,11 +145,19 @@ export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
} = await promiseProps({
scenes: knex('releases').whereIn('releases.id', sceneIds),
channels: knex('releases')
.select('channels.*', 'networks.id as network_id', 'networks.slug as network_slug', 'networks.name as network_name', 'networks.type as network_type')
.select(
'channels.*',
'networks.id as network_id',
'networks.slug as network_slug',
'networks.name as network_name',
'networks.type as network_type',
knex.raw('row_to_json(affiliates) as affiliate'),
)
.whereIn('releases.id', sceneIds)
.leftJoin('entities as channels', 'channels.id', 'releases.entity_id')
.leftJoin('entities as networks', 'networks.id', 'channels.parent_id')
.groupBy('channels.id', 'networks.id'),
.leftJoin('affiliates', knex.raw('affiliates.entity_id in (channels.id, networks.id)'))
.groupBy('channels.id', 'networks.id', 'affiliates.id'),
actors: knex('releases_actors')
.select(
'actors.*',

View File

@ -24,8 +24,6 @@ export async function curateScenesQuery(query) {
notEntityIds: await getIdsBySlug(splitEntities.filter((entity) => entity.charAt(0) === '!').map((entity) => entity.slice(1)), 'entities'),
});
console.log('QUERY', query);
return {
scope: query.scope || 'latest',
query: query.q,

2
static

@ -1 +1 @@
Subproject commit 76242feb7b3e75bcc581d9b19ee509c6e01a87aa
Subproject commit 39f91b96b2bfa176a02d10c9051dd1d2f9c62b64