40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import { stringify } from '@brillout/json-serializer/stringify'; /* eslint-disable-line import/extensions */
|
|
|
|
import { fetchScenes } from '../scenes.js';
|
|
import { parseActorIdentifier } from '../query.js';
|
|
import { getIdsBySlug } from '../cache.js';
|
|
|
|
export async function curateScenesQuery(query) {
|
|
return {
|
|
scope: query.scope || 'latest',
|
|
query: query.q,
|
|
actorIds: [query.actorId, ...(query.actors?.split(',') || []).map((identifier) => parseActorIdentifier(identifier)?.id)].filter(Boolean),
|
|
tagIds: await getIdsBySlug([query.tagSlug, ...(query.tags?.split(',') || [])], 'tags'),
|
|
entityId: query.e ? await getIdsBySlug([query.e], 'entities').then(([id]) => id) : query.entityId,
|
|
stashId: Number(query.stashId),
|
|
};
|
|
}
|
|
|
|
export async function fetchScenesApi(req, res) {
|
|
const {
|
|
scenes,
|
|
aggActors,
|
|
aggTags,
|
|
aggChannels,
|
|
limit,
|
|
total,
|
|
} = await fetchScenes(await curateScenesQuery(req.query), {
|
|
page: Number(req.query.page) || 1,
|
|
limit: Number(req.query.limit) || 30,
|
|
});
|
|
|
|
res.send(stringify({
|
|
scenes,
|
|
aggActors,
|
|
aggTags,
|
|
aggChannels,
|
|
limit,
|
|
total,
|
|
}));
|
|
}
|