2024-10-22 01:12:42 +00:00
|
|
|
import { redirect, render } from 'vike/abort'; /* eslint-disable-line import/extensions */
|
2024-03-25 01:08:09 +00:00
|
|
|
|
2024-01-07 05:13:40 +00:00
|
|
|
import { fetchActorsById } from '#/src/actors.js';
|
|
|
|
import { fetchScenes } from '#/src/scenes.js';
|
2024-08-22 04:23:41 +00:00
|
|
|
import { fetchMovies } from '#/src/movies.js';
|
2024-01-07 05:13:40 +00:00
|
|
|
import { curateScenesQuery } from '#/src/web/scenes.js';
|
2024-08-22 04:23:41 +00:00
|
|
|
import { curateMoviesQuery } from '#/src/web/movies.js';
|
2024-10-22 01:12:42 +00:00
|
|
|
import { fetchCountries } from '#/src/countries.js';
|
2024-01-07 05:13:40 +00:00
|
|
|
|
2024-08-22 04:23:41 +00:00
|
|
|
async function fetchReleases(pageContext) {
|
|
|
|
if (pageContext.routeParams.domain === 'movies') {
|
|
|
|
return fetchMovies(await curateMoviesQuery({
|
2024-01-08 01:21:57 +00:00
|
|
|
...pageContext.urlQuery,
|
|
|
|
scope: pageContext.routeParams.scope || 'latest',
|
|
|
|
actorId: Number(pageContext.routeParams.actorId),
|
2024-04-02 03:55:53 +00:00
|
|
|
tagFilter: pageContext.tagFilter,
|
2024-01-08 01:21:57 +00:00
|
|
|
}), {
|
|
|
|
page: Number(pageContext.routeParams.page) || 1,
|
|
|
|
limit: Number(pageContext.urlParsed.search.limit) || 30,
|
|
|
|
aggregate: true,
|
2024-08-22 04:23:41 +00:00
|
|
|
}, 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) {
|
2024-10-22 01:12:42 +00:00
|
|
|
const isEditing = pageContext._pageId === '/pages/actors/@actorId/edit';
|
|
|
|
|
|
|
|
if (isEditing && !pageContext.user) {
|
|
|
|
throw redirect(`/login?r=${encodeURIComponent(pageContext.urlOriginal)}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const [[actor], actorReleases, countries] = await Promise.all([
|
2024-08-22 04:23:41 +00:00
|
|
|
fetchActorsById([Number(pageContext.routeParams.actorId)], {}, pageContext.user),
|
|
|
|
fetchReleases(pageContext),
|
2024-10-22 01:12:42 +00:00
|
|
|
isEditing && fetchCountries(),
|
2024-01-08 01:21:57 +00:00
|
|
|
]);
|
2024-01-07 05:13:40 +00:00
|
|
|
|
2024-03-25 01:08:09 +00:00
|
|
|
if (!actor) {
|
|
|
|
throw render(404, `Cannot find actor '${pageContext.routeParams.actorId}'.`);
|
|
|
|
}
|
|
|
|
|
2024-01-07 05:13:40 +00:00
|
|
|
return {
|
|
|
|
pageContext: {
|
2024-10-22 01:12:42 +00:00
|
|
|
title: isEditing
|
|
|
|
? `Editing '${actor.name}'`
|
|
|
|
: actor.name,
|
2024-01-07 05:13:40 +00:00
|
|
|
pageProps: {
|
|
|
|
actor,
|
2024-10-22 01:12:42 +00:00
|
|
|
countries,
|
2024-08-22 04:23:41 +00:00
|
|
|
...actorReleases,
|
2024-01-07 05:13:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|