traxxx-web/pages/actors/@actorId/+onBeforeRender.js

55 lines
1.6 KiB
JavaScript

import { render } from 'vike/abort'; /* eslint-disable-line import/extensions */
import { fetchActorsById } from '#/src/actors.js';
import { fetchScenes } from '#/src/scenes.js';
import { fetchMovies } from '#/src/movies.js';
import { curateScenesQuery } from '#/src/web/scenes.js';
import { curateMoviesQuery } from '#/src/web/movies.js';
async function fetchReleases(pageContext) {
if (pageContext.routeParams.domain === 'movies') {
return fetchMovies(await curateMoviesQuery({
...pageContext.urlQuery,
scope: pageContext.routeParams.scope || 'latest',
actorId: Number(pageContext.routeParams.actorId),
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',
actorId: Number(pageContext.routeParams.actorId),
tagFilter: pageContext.tagFilter,
}), {
page: Number(pageContext.routeParams.page) || 1,
limit: Number(pageContext.urlParsed.search.limit) || 30,
aggregate: true,
}, pageContext.user);
}
export async function onBeforeRender(pageContext) {
const [[actor], actorReleases] = await Promise.all([
fetchActorsById([Number(pageContext.routeParams.actorId)], {}, pageContext.user),
fetchReleases(pageContext),
]);
if (!actor) {
throw render(404, `Cannot find actor '${pageContext.routeParams.actorId}'.`);
}
return {
pageContext: {
title: actor.name,
pageProps: {
actor,
...actorReleases,
},
},
};
}