49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
import { render } from 'vike/abort'; /* eslint-disable-line import/extensions */
|
|
import { fetchScenesById } from '#/src/scenes.js';
|
|
import { getRandomCampaigns } from '#/src/campaigns.js';
|
|
|
|
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';
|
|
}
|
|
|
|
export async function onBeforeRender(pageContext) {
|
|
const [scene] = await fetchScenesById([Number(pageContext.routeParams.sceneId)], {
|
|
reqUser: pageContext.user,
|
|
includeAssets: true,
|
|
includePartOf: true,
|
|
actorStashes: true,
|
|
});
|
|
|
|
const campaigns = await getRandomCampaigns([
|
|
{
|
|
minRatio: 1.5,
|
|
entityIds: [scene.channel.id, scene.network?.id].filter(Boolean),
|
|
allowRandomFallback: false,
|
|
},
|
|
], { tagFilter: pageContext.tagFilter });
|
|
|
|
if (!scene) {
|
|
throw render(404, `Cannot find scene '${pageContext.routeParams.sceneId}'.`);
|
|
}
|
|
|
|
return {
|
|
pageContext: {
|
|
title: getTitle(scene),
|
|
pageProps: {
|
|
scene,
|
|
},
|
|
campaigns: {
|
|
scene: campaigns[0],
|
|
},
|
|
},
|
|
};
|
|
}
|