2024-03-14 23:08:24 +00:00
|
|
|
import { render } from 'vike/abort'; /* eslint-disable-line import/extensions */
|
|
|
|
|
|
|
|
import { fetchStashByUsernameAndSlug } from '#/src/stashes.js';
|
|
|
|
import { fetchScenes } from '#/src/scenes.js';
|
|
|
|
import { curateScenesQuery } from '#/src/web/scenes.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 stashScenes = await fetchScenes(await curateScenesQuery({
|
|
|
|
...pageContext.urlQuery,
|
2024-03-17 02:03:36 +00:00
|
|
|
scope: pageContext.routeParams.scope || 'stashed',
|
2024-03-14 23:08:24 +00:00
|
|
|
stashId: stash.id,
|
|
|
|
}), {
|
|
|
|
page: Number(pageContext.routeParams.page) || 1,
|
|
|
|
limit: Number(pageContext.urlParsed.search.limit) || 30,
|
|
|
|
}, pageContext.user);
|
|
|
|
|
|
|
|
const {
|
|
|
|
scenes,
|
|
|
|
aggActors,
|
|
|
|
aggTags,
|
|
|
|
aggChannels,
|
|
|
|
total,
|
|
|
|
limit,
|
|
|
|
} = stashScenes;
|
|
|
|
|
|
|
|
return {
|
|
|
|
pageContext: {
|
|
|
|
title: `${stash.name} by ${stash.user.username}`,
|
|
|
|
pageProps: {
|
|
|
|
stash,
|
|
|
|
scenes,
|
|
|
|
aggActors,
|
|
|
|
aggTags,
|
|
|
|
aggChannels,
|
|
|
|
total,
|
|
|
|
limit,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof HttpError) {
|
|
|
|
throw render(error.httpCode, error.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|