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-24 22:36:25 +00:00
|
|
|
import { fetchMovies } from '#/src/movies.js';
|
|
|
|
import { curateMoviesQuery } from '#/src/web/movies.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-24 22:36:25 +00:00
|
|
|
const movieResults = await fetchMovies(await curateMoviesQuery({
|
|
|
|
...pageContext.urlQuery,
|
|
|
|
scope: pageContext.routeParams.scope || 'latest',
|
|
|
|
stashId: stash.id,
|
2024-04-02 14:17:23 +00:00
|
|
|
tagFilter: pageContext.tagFilter,
|
2024-03-24 22:36:25 +00:00
|
|
|
}), {
|
|
|
|
page: Number(pageContext.routeParams.page) || 1,
|
|
|
|
limit: Number(pageContext.urlParsed.search.limit) || 50,
|
2024-03-25 01:08:09 +00:00
|
|
|
}, pageContext.user);
|
2024-03-24 22:36:25 +00:00
|
|
|
|
2024-03-14 23:08:24 +00:00
|
|
|
return {
|
|
|
|
pageContext: {
|
|
|
|
title: `${stash.name} by ${stash.user.username}`,
|
|
|
|
pageProps: {
|
|
|
|
stash,
|
2024-08-18 21:34:38 +00:00
|
|
|
...movieResults,
|
2024-03-14 23:08:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof HttpError) {
|
|
|
|
throw render(error.httpCode, error.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|