50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
import { render } from 'vike/abort'; /* eslint-disable-line import/extensions */
|
|
|
|
import { fetchStashByUsernameAndSlug } from '#/src/stashes.js';
|
|
import { fetchActors } from '#/src/actors.js';
|
|
import { curateActorsQuery } from '#/src/web/actors.js';
|
|
import { HttpError } from '#/src/errors.js';
|
|
|
|
export async function onBeforeRender(pageContext) {
|
|
try {
|
|
const stash = await fetchStashByUsernameAndSlug(pageContext.routeParams.username, pageContext.routeParams.stashSlug, pageContext.user);
|
|
|
|
const stashActors = await fetchActors(curateActorsQuery({
|
|
...pageContext.urlQuery,
|
|
stashId: stash.id,
|
|
}), {
|
|
page: Number(pageContext.routeParams.page) || 1,
|
|
limit: Number(pageContext.urlParsed.search.limit) || 120,
|
|
order: pageContext.urlParsed.search.order?.split('.') || ['stashed', 'desc'],
|
|
}, pageContext.user);
|
|
|
|
const {
|
|
actors,
|
|
countries,
|
|
cupRange,
|
|
limit,
|
|
total,
|
|
} = stashActors;
|
|
|
|
return {
|
|
pageContext: {
|
|
title: `${stash.name} by ${stash.user.username}`,
|
|
pageProps: {
|
|
stash,
|
|
actors,
|
|
countries,
|
|
cupRange,
|
|
limit,
|
|
total,
|
|
},
|
|
},
|
|
};
|
|
} catch (error) {
|
|
if (error instanceof HttpError) {
|
|
throw render(error.httpCode, error.message);
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
}
|