2024-03-25 01:08:09 +00:00
|
|
|
import { render } from 'vike/abort'; /* eslint-disable-line import/extensions */
|
|
|
|
|
|
|
|
import { fetchMoviesById } from '#/src/movies.js';
|
|
|
|
import { fetchScenes } from '#/src/scenes.js';
|
|
|
|
import { curateScenesQuery } from '#/src/web/scenes.js';
|
|
|
|
|
|
|
|
function getTitle(movie) {
|
|
|
|
if (movie.title) {
|
|
|
|
return movie.title;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (movie.actors.length > 0) {
|
|
|
|
return `Movie with ${movie.actors.map((actor) => actor.name).join(', ')}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Movie';
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function onBeforeRender(pageContext) {
|
|
|
|
const [[movie], movieScenes] = await Promise.all([
|
|
|
|
fetchMoviesById([Number(pageContext.routeParams.movieId)], pageContext.user),
|
|
|
|
fetchScenes(await curateScenesQuery({
|
|
|
|
...pageContext.urlQuery,
|
2024-05-31 03:05:33 +00:00
|
|
|
scope: 'oldest',
|
2024-03-25 01:08:09 +00:00
|
|
|
movieId: Number(pageContext.routeParams.movieId),
|
|
|
|
}), {
|
|
|
|
page: Number(pageContext.routeParams.page) || 1,
|
|
|
|
limit: Number(pageContext.urlParsed.search.limit) || 30,
|
|
|
|
aggregate: true,
|
|
|
|
}, pageContext.user),
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!movie) {
|
|
|
|
throw render(404, `Cannot find movie '${pageContext.routeParams.movieId}'.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
scenes,
|
|
|
|
aggActors,
|
|
|
|
aggTags,
|
|
|
|
aggChannels,
|
|
|
|
total,
|
|
|
|
limit,
|
|
|
|
} = movieScenes;
|
|
|
|
|
|
|
|
return {
|
|
|
|
pageContext: {
|
|
|
|
title: getTitle(movie),
|
|
|
|
pageProps: {
|
|
|
|
movie,
|
|
|
|
scenes,
|
|
|
|
aggActors,
|
|
|
|
aggTags,
|
|
|
|
aggChannels,
|
|
|
|
total,
|
|
|
|
limit,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|