2024-09-10 00:47:03 +00:00
|
|
|
import { render, redirect } from 'vike/abort'; /* eslint-disable-line import/extensions */
|
2024-03-19 01:19:23 +00:00
|
|
|
import { fetchScenesById } from '#/src/scenes.js';
|
2024-07-07 19:01:44 +00:00
|
|
|
import { getRandomCampaigns } from '#/src/campaigns.js';
|
2024-09-10 00:47:03 +00:00
|
|
|
import { getIdsBySlug } from '#/src/cache.js';
|
2023-12-30 05:29:53 +00:00
|
|
|
|
2024-03-25 01:08:09 +00:00
|
|
|
function getTitle(scene) {
|
|
|
|
if (scene.title) {
|
|
|
|
return scene.title;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scene.actors.length > 0) {
|
|
|
|
return `Scene with ${scene.actors.map((actor) => actor.name).join(', ')}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Scene';
|
|
|
|
}
|
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
export async function onBeforeRender(pageContext) {
|
2024-09-10 00:47:03 +00:00
|
|
|
if (pageContext._pageId === '/pages/scene/edit' && !pageContext.user) {
|
|
|
|
throw redirect(`/login?r=${encodeURIComponent(pageContext.urlOriginal)}`);
|
|
|
|
}
|
|
|
|
|
2024-03-21 01:54:05 +00:00
|
|
|
const [scene] = await fetchScenesById([Number(pageContext.routeParams.sceneId)], {
|
|
|
|
reqUser: pageContext.user,
|
2024-06-12 15:09:53 +00:00
|
|
|
includeAssets: true,
|
|
|
|
includePartOf: true,
|
2024-03-21 01:54:05 +00:00
|
|
|
actorStashes: true,
|
|
|
|
});
|
2023-12-30 05:29:53 +00:00
|
|
|
|
2024-09-10 00:47:03 +00:00
|
|
|
const [campaigns, tagIds] = await Promise.all([
|
|
|
|
getRandomCampaigns([
|
|
|
|
{
|
|
|
|
minRatio: 1.5,
|
|
|
|
entityIds: [scene.channel.id, scene.network?.id].filter(Boolean),
|
|
|
|
allowRandomFallback: false,
|
|
|
|
},
|
|
|
|
], { tagFilter: pageContext.tagFilter }),
|
|
|
|
getIdsBySlug([
|
|
|
|
'anal',
|
|
|
|
'creampie',
|
|
|
|
'dp',
|
|
|
|
'facial',
|
|
|
|
], 'tags', true),
|
|
|
|
]);
|
2024-07-07 19:01:44 +00:00
|
|
|
|
|
|
|
if (!scene) {
|
|
|
|
throw render(404, `Cannot find scene '${pageContext.routeParams.sceneId}'.`);
|
|
|
|
}
|
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
return {
|
|
|
|
pageContext: {
|
2024-03-25 01:08:09 +00:00
|
|
|
title: getTitle(scene),
|
2023-12-30 05:29:53 +00:00
|
|
|
pageProps: {
|
|
|
|
scene,
|
2024-09-10 00:47:03 +00:00
|
|
|
tagIds,
|
2023-12-30 05:29:53 +00:00
|
|
|
},
|
2024-07-07 19:01:44 +00:00
|
|
|
campaigns: {
|
|
|
|
scene: campaigns[0],
|
|
|
|
},
|
2023-12-30 05:29:53 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|