traxxx-web/pages/search/+onBeforeRender.js

70 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

import { fetchScenes } from '#/src/scenes.js';
import { fetchActors } from '#/src/actors.js';
import { fetchMovies } from '#/src/movies.js';
import { curateScenesQuery } from '#/src/web/scenes.js';
import { curateActorsQuery } from '#/src/web/actors.js';
import { curateMoviesQuery } from '#/src/web/movies.js';
export async function onBeforeRender(pageContext) {
const [searchScenes, searchActors, searchMovies] = await Promise.all([
fetchScenes(await curateScenesQuery({
...pageContext.urlQuery,
query: pageContext.urlParsed.search.q,
scope: pageContext.urlParsed.search.scope || 'results',
tagFilter: pageContext.tagFilter,
}), {
page: Number(pageContext.routeParams.page) || 1,
limit: Number(pageContext.urlParsed.search.limit) || 15,
}, pageContext.user),
fetchActors(curateActorsQuery(pageContext.urlQuery), {
page: Number(pageContext.routeParams.page) || 1,
limit: Number(pageContext.urlParsed.search.limit) || 10,
order: ['results', 'desc'],
}, pageContext.user),
fetchMovies(await curateMoviesQuery({
...pageContext.urlQuery,
scope: pageContext.routeParams.scope || 'results',
}), {
page: Number(pageContext.routeParams.page) || 1,
limit: Number(pageContext.urlParsed.search.limit) || 5,
}, pageContext.user),
]);
const {
scenes,
aggYears,
aggActors,
aggTags,
aggChannels,
total: sceneTotal,
} = searchScenes;
const {
actors,
total: actorTotal,
} = searchActors;
const {
movies,
total: movieTotal,
} = searchMovies;
return {
pageContext: {
title: `Search '${pageContext.urlParsed.search.q || ''}'`,
pageProps: {
actors,
scenes,
movies,
aggYears,
aggActors,
aggTags,
aggChannels,
sceneTotal,
actorTotal,
movieTotal,
},
},
};
}