Fixed search breaking due missing restrictions, added restrictions to API calls.

This commit is contained in:
2026-02-04 06:37:41 +01:00
parent 6c8fce49d6
commit a1e080c20d
9 changed files with 22 additions and 15 deletions

View File

@@ -16,22 +16,24 @@ export async function onBeforeRender(pageContext) {
}), { }), {
page: Number(pageContext.routeParams.page) || 1, page: Number(pageContext.routeParams.page) || 1,
limit: Number(pageContext.urlParsed.search.limit) || 15, limit: Number(pageContext.urlParsed.search.limit) || 15,
}, pageContext.user), }, pageContext.user, { restriction: pageContext.restriction }),
fetchActors(curateActorsQuery(pageContext.urlQuery), { fetchActors(curateActorsQuery(pageContext.urlQuery), {
page: Number(pageContext.routeParams.page) || 1, page: Number(pageContext.routeParams.page) || 1,
limit: Number(pageContext.urlParsed.search.limit) || 10, limit: Number(pageContext.urlParsed.search.limit) || 10,
order: ['results', 'desc'], order: ['results', 'desc'],
}, pageContext.user), }, pageContext.user, { restriction: pageContext.restriction }),
fetchMovies(await curateMoviesQuery({ fetchMovies(await curateMoviesQuery({
...pageContext.urlQuery, ...pageContext.urlQuery,
scope: pageContext.routeParams.scope || 'results', scope: pageContext.routeParams.scope || 'results',
}), { }), {
page: Number(pageContext.routeParams.page) || 1, page: Number(pageContext.routeParams.page) || 1,
limit: Number(pageContext.urlParsed.search.limit) || 5, limit: Number(pageContext.urlParsed.search.limit) || 5,
}, pageContext.user), }, pageContext.user, { restriction: pageContext.restriction }),
fetchEntities({ fetchEntities({
query: pageContext.urlParsed.search.q, query: pageContext.urlParsed.search.q,
limit: 5, limit: 5,
}, {
restriction: pageContext.restriction,
}), }),
]); ]);

View File

@@ -118,7 +118,7 @@ const tagSlugs = {
}; };
async function searchTags(pageContext) { async function searchTags(pageContext) {
const tags = await fetchTags({ query: pageContext.urlParsed.search.q }); const tags = await fetchTags({ query: pageContext.urlParsed.search.q }, { restriction: pageContext.restriction });
return { return {
pageContext: { pageContext: {

View File

@@ -51,7 +51,7 @@ export function curateEntity(entity, context = {}) {
return curatedEntity; return curatedEntity;
} }
export async function fetchEntities(options = {}, context) { export async function fetchEntities(options = {}, context = {}) {
const entities = await knex('entities') const entities = await knex('entities')
.select('entities.*', knex.raw('row_to_json(parents) as parent')) .select('entities.*', knex.raw('row_to_json(parents) as parent'))
.modify((builder) => { .modify((builder) => {

View File

@@ -65,7 +65,7 @@ function curateMovie(rawMovie, assets, context = {}) {
}; };
} }
export async function fetchMoviesById(movieIds, reqUser, context) { export async function fetchMoviesById(movieIds, reqUser, context = {}) {
const { const {
movies, movies,
channels, channels,

View File

@@ -7,7 +7,7 @@ import { curateMedia } from './media.js';
const logger = initLogger(); const logger = initLogger();
function curateTag(tag, context) { function curateTag(tag, context = {}) {
return { return {
id: tag.id, id: tag.id,
name: censor(tag.name, context.restriction), name: censor(tag.name, context.restriction),
@@ -24,7 +24,7 @@ function curateTag(tag, context) {
}; };
} }
export async function fetchTags(options = {}) { export async function fetchTags(options = {}, context = {}) {
const query = options.query?.trim(); const query = options.query?.trim();
const [tags, posters] = await Promise.all([ const [tags, posters] = await Promise.all([
@@ -70,7 +70,7 @@ export async function fetchTags(options = {}) {
return tags.map((tagEntry) => curateTag({ return tags.map((tagEntry) => curateTag({
...tagEntry, ...tagEntry,
poster: postersByTagId[tagEntry.id], poster: postersByTagId[tagEntry.id],
})); }, context));
} }
export async function fetchTagsById(tagIds, options = {}, reqUser, context = {}) { export async function fetchTagsById(tagIds, options = {}, reqUser, context = {}) {

View File

@@ -33,7 +33,7 @@ export async function fetchMoviesApi(req, res) {
} = await fetchMovies(await curateMoviesQuery(req.query), { } = await fetchMovies(await curateMoviesQuery(req.query), {
page: Number(req.query.page) || 1, page: Number(req.query.page) || 1,
limit: Number(req.query.limit) || 30, limit: Number(req.query.limit) || 30,
}, req.user); }, req.user, { restriction: req.restriction });
res.send(stringify({ res.send(stringify({
movies, movies,
@@ -47,7 +47,7 @@ export async function fetchMoviesApi(req, res) {
} }
export async function fetchMovieApi(req, res) { export async function fetchMovieApi(req, res) {
const [movie] = await fetchMoviesById([Number(req.params.movieId)], { reqUser: req.user }); const [movie] = await fetchMoviesById([Number(req.params.movieId)], { reqUser: req.user }, { restriction: req.restriction });
if (!movie) { if (!movie) {
throw new HttpError(`No movie with ID ${req.params.movieId} found`, 404); throw new HttpError(`No movie with ID ${req.params.movieId} found`, 404);
@@ -137,7 +137,7 @@ export async function fetchMoviesGraphql(query, req) {
page: query.page || 1, page: query.page || 1,
limit: query.limit || 30, limit: query.limit || 30,
aggregate: false, aggregate: false,
}, req.user); }, req.user, { restriction: req.restriction });
return { return {
nodes: movies, nodes: movies,

View File

@@ -68,7 +68,9 @@ async function fetchScenesApi(req, res) {
}), { }), {
page: Number(req.query.page) || 1, page: Number(req.query.page) || 1,
limit: Number(req.query.limit) || 30, limit: Number(req.query.limit) || 30,
}, req.user); }, req.user, {
restriction: req.restriction,
});
res.send(stringify({ res.send(stringify({
scenes, scenes,
@@ -250,7 +252,7 @@ export async function fetchScenesGraphql(query, req) {
} }
async function fetchSceneApi(req, res) { async function fetchSceneApi(req, res) {
const [scene] = await fetchScenesById([Number(req.params.sceneId)], { reqUser: req.user }); const [scene] = await fetchScenesById([Number(req.params.sceneId)], { reqUser: req.user }, { restriction: req.restriction });
if (!scene) { if (!scene) {
throw new HttpError(`No scene with ID ${req.params.sceneId} found`, 404); throw new HttpError(`No scene with ID ${req.params.sceneId} found`, 404);
@@ -263,6 +265,7 @@ export async function fetchScenesByIdGraphql(query, req) {
const scenes = await fetchScenesById([].concat(query.id, query.ids).filter(Boolean), { const scenes = await fetchScenesById([].concat(query.id, query.ids).filter(Boolean), {
reqUser: req.user, reqUser: req.user,
includePartOf: true, includePartOf: true,
restriction: req.restriction,
}); });
if (query.ids) { if (query.ids) {

View File

@@ -3,6 +3,8 @@ import { fetchTags } from '../tags.js';
export async function fetchTagsApi(req, res) { export async function fetchTagsApi(req, res) {
const tags = await fetchTags({ const tags = await fetchTags({
query: req.query.query, query: req.query.query,
}, {
restriction: req.restriction,
}); });
res.send(tags); res.send(tags);

2
static

Submodule static updated: 389d659cb2...ea8019c555