Fixed search breaking due missing restrictions, added restrictions to API calls.
This commit is contained in:
@@ -16,22 +16,24 @@ export async function onBeforeRender(pageContext) {
|
||||
}), {
|
||||
page: Number(pageContext.routeParams.page) || 1,
|
||||
limit: Number(pageContext.urlParsed.search.limit) || 15,
|
||||
}, pageContext.user),
|
||||
}, pageContext.user, { restriction: pageContext.restriction }),
|
||||
fetchActors(curateActorsQuery(pageContext.urlQuery), {
|
||||
page: Number(pageContext.routeParams.page) || 1,
|
||||
limit: Number(pageContext.urlParsed.search.limit) || 10,
|
||||
order: ['results', 'desc'],
|
||||
}, pageContext.user),
|
||||
}, pageContext.user, { restriction: pageContext.restriction }),
|
||||
fetchMovies(await curateMoviesQuery({
|
||||
...pageContext.urlQuery,
|
||||
scope: pageContext.routeParams.scope || 'results',
|
||||
}), {
|
||||
page: Number(pageContext.routeParams.page) || 1,
|
||||
limit: Number(pageContext.urlParsed.search.limit) || 5,
|
||||
}, pageContext.user),
|
||||
}, pageContext.user, { restriction: pageContext.restriction }),
|
||||
fetchEntities({
|
||||
query: pageContext.urlParsed.search.q,
|
||||
limit: 5,
|
||||
}, {
|
||||
restriction: pageContext.restriction,
|
||||
}),
|
||||
]);
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ const tagSlugs = {
|
||||
};
|
||||
|
||||
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 {
|
||||
pageContext: {
|
||||
|
||||
@@ -51,7 +51,7 @@ export function curateEntity(entity, context = {}) {
|
||||
return curatedEntity;
|
||||
}
|
||||
|
||||
export async function fetchEntities(options = {}, context) {
|
||||
export async function fetchEntities(options = {}, context = {}) {
|
||||
const entities = await knex('entities')
|
||||
.select('entities.*', knex.raw('row_to_json(parents) as parent'))
|
||||
.modify((builder) => {
|
||||
|
||||
@@ -65,7 +65,7 @@ function curateMovie(rawMovie, assets, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchMoviesById(movieIds, reqUser, context) {
|
||||
export async function fetchMoviesById(movieIds, reqUser, context = {}) {
|
||||
const {
|
||||
movies,
|
||||
channels,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { curateMedia } from './media.js';
|
||||
|
||||
const logger = initLogger();
|
||||
|
||||
function curateTag(tag, context) {
|
||||
function curateTag(tag, context = {}) {
|
||||
return {
|
||||
id: tag.id,
|
||||
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 [tags, posters] = await Promise.all([
|
||||
@@ -70,7 +70,7 @@ export async function fetchTags(options = {}) {
|
||||
return tags.map((tagEntry) => curateTag({
|
||||
...tagEntry,
|
||||
poster: postersByTagId[tagEntry.id],
|
||||
}));
|
||||
}, context));
|
||||
}
|
||||
|
||||
export async function fetchTagsById(tagIds, options = {}, reqUser, context = {}) {
|
||||
|
||||
@@ -33,7 +33,7 @@ export async function fetchMoviesApi(req, res) {
|
||||
} = await fetchMovies(await curateMoviesQuery(req.query), {
|
||||
page: Number(req.query.page) || 1,
|
||||
limit: Number(req.query.limit) || 30,
|
||||
}, req.user);
|
||||
}, req.user, { restriction: req.restriction });
|
||||
|
||||
res.send(stringify({
|
||||
movies,
|
||||
@@ -47,7 +47,7 @@ export async function fetchMoviesApi(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) {
|
||||
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,
|
||||
limit: query.limit || 30,
|
||||
aggregate: false,
|
||||
}, req.user);
|
||||
}, req.user, { restriction: req.restriction });
|
||||
|
||||
return {
|
||||
nodes: movies,
|
||||
|
||||
@@ -68,7 +68,9 @@ async function fetchScenesApi(req, res) {
|
||||
}), {
|
||||
page: Number(req.query.page) || 1,
|
||||
limit: Number(req.query.limit) || 30,
|
||||
}, req.user);
|
||||
}, req.user, {
|
||||
restriction: req.restriction,
|
||||
});
|
||||
|
||||
res.send(stringify({
|
||||
scenes,
|
||||
@@ -250,7 +252,7 @@ export async function fetchScenesGraphql(query, req) {
|
||||
}
|
||||
|
||||
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) {
|
||||
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), {
|
||||
reqUser: req.user,
|
||||
includePartOf: true,
|
||||
restriction: req.restriction,
|
||||
});
|
||||
|
||||
if (query.ids) {
|
||||
|
||||
@@ -3,6 +3,8 @@ import { fetchTags } from '../tags.js';
|
||||
export async function fetchTagsApi(req, res) {
|
||||
const tags = await fetchTags({
|
||||
query: req.query.query,
|
||||
}, {
|
||||
restriction: req.restriction,
|
||||
});
|
||||
|
||||
res.send(tags);
|
||||
|
||||
2
static
2
static
Submodule static updated: 389d659cb2...ea8019c555
Reference in New Issue
Block a user