Added basic actor page with scenes and co-star filtering.

This commit is contained in:
2024-01-07 06:13:40 +01:00
parent ffcb77ab45
commit e32a366fff
14 changed files with 476 additions and 144 deletions

29
src/web/scenes.js Normal file
View File

@@ -0,0 +1,29 @@
import { stringify } from '@brillout/json-serializer/stringify';
import { fetchScenes } from '../scenes.js';
export function curateScenesQuery(query) {
return {
scope: query.scope || 'latest',
actorIds: [query.actorId, ...(query.actors?.split(',') || [])].filter(Boolean).map((actorId) => Number(actorId)),
};
}
export async function fetchScenesApi(req, res) {
const {
scenes,
actors,
limit,
total,
} = await fetchScenes(curateScenesQuery(req.query), {
page: Number(req.query.page) || 1,
limit: Number(req.query.limit) || 30,
});
res.send(stringify({
scenes,
actors,
limit,
total,
}));
}

View File

@@ -20,7 +20,8 @@ import { renderPage } from 'vike/server'; // eslint-disable-line import/extensio
// import root from './root.js';
import { fetchActorsApi } from './actors.js'; // eslint-disable-line import/extensions
import { fetchScenesApi } from './scenes.js';
import { fetchActorsApi } from './actors.js';
const isProduction = process.env.NODE_ENV === 'production';
@@ -60,6 +61,8 @@ async function startServer() {
router.get('/api/actors', fetchActorsApi);
router.get('/api/scenes', fetchScenesApi);
// ...
// Other middlewares (e.g. some RPC middleware such as Telefunc)
// ...
@@ -75,6 +78,10 @@ async function startServer() {
const pageContext = await renderPage(pageContextInit);
const { httpResponse } = pageContext;
if (pageContext.errorWhileRendering) {
console.error(pageContext.errorWhileRendering);
}
if (!httpResponse) {
next();
return;