2024-01-25 02:07:26 +00:00
|
|
|
import { render } from 'vike/abort'; /* eslint-disable-line import/extensions */
|
|
|
|
|
|
|
|
import { fetchEntitiesById } from '#/src/entities.js';
|
|
|
|
import { fetchScenes } from '#/src/scenes.js';
|
2024-08-22 04:23:41 +00:00
|
|
|
import { fetchMovies } from '#/src/movies.js';
|
2024-01-25 02:07:26 +00:00
|
|
|
import { curateScenesQuery } from '#/src/web/scenes.js';
|
2024-08-22 04:23:41 +00:00
|
|
|
import { curateMoviesQuery } from '#/src/web/movies.js';
|
|
|
|
import { getRandomCampaigns, getCampaignIndex } from '#/src/campaigns.js';
|
2024-01-25 02:07:26 +00:00
|
|
|
import redis from '#/src//redis.js';
|
|
|
|
|
2024-08-22 04:23:41 +00:00
|
|
|
async function fetchReleases(pageContext, entityId) {
|
|
|
|
if (pageContext.routeParams.domain === 'movies') {
|
|
|
|
return fetchMovies(await curateMoviesQuery({
|
|
|
|
...pageContext.urlQuery,
|
|
|
|
scope: pageContext.routeParams.scope || 'latest',
|
|
|
|
entityId: Number(entityId),
|
|
|
|
tagFilter: pageContext.tagFilter,
|
|
|
|
}), {
|
|
|
|
page: Number(pageContext.routeParams.page) || 1,
|
|
|
|
limit: Number(pageContext.urlParsed.search.limit) || 30,
|
|
|
|
aggregate: true,
|
|
|
|
}, pageContext.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fetchScenes(await curateScenesQuery({
|
|
|
|
...pageContext.urlQuery,
|
|
|
|
scope: pageContext.routeParams.scope || 'latest',
|
|
|
|
entityId: Number(entityId),
|
|
|
|
tagFilter: pageContext.tagFilter,
|
|
|
|
}), {
|
|
|
|
page: Number(pageContext.routeParams.page) || 1,
|
|
|
|
limit: Number(pageContext.urlParsed.search.limit) || 30,
|
|
|
|
aggregate: true,
|
|
|
|
}, pageContext.user);
|
|
|
|
}
|
|
|
|
|
2024-01-25 02:07:26 +00:00
|
|
|
export async function onBeforeRender(pageContext) {
|
|
|
|
const entityId = await redis.hGet('traxxx:entities:id_by_slug', pageContext.routeParams.entityType === 'network' ? `_${pageContext.routeParams.entitySlug}` : pageContext.routeParams.entitySlug);
|
|
|
|
|
|
|
|
if (!entityId) {
|
|
|
|
throw render(404, `Cannot find ${pageContext.routeParams.entityType} '${pageContext.routeParams.entitySlug}'.`);
|
|
|
|
}
|
|
|
|
|
2024-06-12 15:09:53 +00:00
|
|
|
const [
|
|
|
|
[entity],
|
2024-08-22 04:23:41 +00:00
|
|
|
entityReleases,
|
2024-06-12 15:09:53 +00:00
|
|
|
] = await Promise.all([
|
2024-01-25 02:07:26 +00:00
|
|
|
fetchEntitiesById([Number(entityId)], { includeChildren: true }),
|
2024-08-22 04:23:41 +00:00
|
|
|
fetchReleases(pageContext, entityId),
|
2024-01-25 02:07:26 +00:00
|
|
|
]);
|
|
|
|
|
2024-06-12 15:09:53 +00:00
|
|
|
const campaigns = await getRandomCampaigns([
|
|
|
|
{
|
|
|
|
entityIds: [entity.id, entity.parent?.id].filter(Boolean),
|
|
|
|
minRatio: 1.5,
|
2024-06-16 23:28:20 +00:00
|
|
|
allowRandomFallback: false,
|
2024-06-12 15:09:53 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
entityIds: [entity.id, entity.parent?.id].filter(Boolean),
|
2024-08-22 04:23:41 +00:00
|
|
|
minRatio: 1.5,
|
2024-06-16 23:28:20 +00:00
|
|
|
allowRandomFallback: false,
|
2024-06-12 15:09:53 +00:00
|
|
|
},
|
2024-08-22 04:23:41 +00:00
|
|
|
pageContext.routeParams.domain === 'scenes' ? {
|
2024-06-12 15:09:53 +00:00
|
|
|
entityIds: [entity.id, entity.parent?.id].filter(Boolean),
|
2024-08-22 04:23:41 +00:00
|
|
|
minRatio: 0.75,
|
|
|
|
maxRatio: 1.25,
|
2024-06-16 23:28:20 +00:00
|
|
|
allowRandomFallback: false,
|
2024-08-22 04:23:41 +00:00
|
|
|
} : null,
|
|
|
|
].filter(Boolean), { tagFilter: pageContext.tagFilter });
|
2024-06-12 15:09:53 +00:00
|
|
|
|
2024-08-22 04:23:41 +00:00
|
|
|
const releases = entityReleases.scenes || entityReleases.movies;
|
2024-01-25 02:07:26 +00:00
|
|
|
|
2024-08-22 04:23:41 +00:00
|
|
|
const campaignIndex = getCampaignIndex(releases.length);
|
|
|
|
const [metaCampaign, paginationCampaign, sceneCampaign] = campaigns;
|
2024-06-12 15:09:53 +00:00
|
|
|
|
2024-01-25 02:07:26 +00:00
|
|
|
return {
|
|
|
|
pageContext: {
|
|
|
|
title: entity.name,
|
|
|
|
pageProps: {
|
|
|
|
entity,
|
2024-08-22 04:23:41 +00:00
|
|
|
...entityReleases,
|
2024-01-25 02:07:26 +00:00
|
|
|
},
|
2024-06-12 15:09:53 +00:00
|
|
|
campaigns: {
|
|
|
|
index: campaignIndex,
|
|
|
|
meta: metaCampaign,
|
2024-08-22 04:23:41 +00:00
|
|
|
scenes: releases.length > 5 && sceneCampaign,
|
2024-06-12 15:09:53 +00:00
|
|
|
pagination: paginationCampaign,
|
|
|
|
},
|
2024-01-25 02:07:26 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|