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