Implemented negative filters in back-end, added basic fixed filters settings dialog.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import redis from './redis.js';
|
||||
|
||||
export async function getIdsBySlug(slugs, domain) {
|
||||
if (!slugs) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const ids = await Promise.all(slugs.map(async (slug) => {
|
||||
if (!slug) {
|
||||
return null;
|
||||
|
||||
@@ -9,7 +9,9 @@ export default function navigate(path, query, options = {}) {
|
||||
}).toString();
|
||||
|
||||
const url = queryString
|
||||
? `${path}?${queryString.replace(/%2C/g, ',')}` // URLSearchParams encodes commas, we don't want that
|
||||
? `${path}?${queryString
|
||||
.replace(/%2C/g, ',') // URLSearchParams encodes commas and colons, we don't want that
|
||||
.replace(/%3A/g, ':')}`
|
||||
: path;
|
||||
|
||||
if (options.redirect) {
|
||||
|
||||
@@ -439,10 +439,18 @@ async function queryManticoreSql(filters, options, _reqUser) {
|
||||
builder.where('any(tag_ids)', tagId);
|
||||
});
|
||||
|
||||
if (filters.notTagIds) {
|
||||
builder.whereNotIn('tag_ids', filters.notTagIds);
|
||||
}
|
||||
|
||||
filters.actorIds?.forEach((actorId) => {
|
||||
builder.where('any(actor_ids)', actorId);
|
||||
});
|
||||
|
||||
if (filters.notActorIds) {
|
||||
builder.whereNotIn('actor_ids', filters.notActorIds);
|
||||
}
|
||||
|
||||
if (filters.entityId) {
|
||||
builder.whereRaw('any(entity_ids) = ?', filters.entityId);
|
||||
|
||||
@@ -455,6 +463,10 @@ async function queryManticoreSql(filters, options, _reqUser) {
|
||||
*/
|
||||
}
|
||||
|
||||
if (filters.notEntityIds) {
|
||||
builder.whereNotIn('entity_ids', filters.notEntityIds);
|
||||
}
|
||||
|
||||
if (filters.movieId) {
|
||||
builder.whereRaw('any(movie_ids) = ?', filters.movieId);
|
||||
}
|
||||
|
||||
@@ -3,14 +3,36 @@ import { stringify } from '@brillout/json-serializer/stringify'; /* eslint-disab
|
||||
import { fetchScenes } from '../scenes.js';
|
||||
import { parseActorIdentifier } from '../query.js';
|
||||
import { getIdsBySlug } from '../cache.js';
|
||||
import slugify from '../../utils/slugify.js';
|
||||
import promiseProps from '../../utils/promise-props.js';
|
||||
|
||||
export async function curateScenesQuery(query) {
|
||||
const splitTags = query.tags?.split(',') || [];
|
||||
const splitActors = query.actors?.split(',') || [];
|
||||
const splitEntities = query.e?.split(',') || [];
|
||||
const mainEntity = splitEntities.find((entity) => entity.charAt(0) !== '!');
|
||||
|
||||
const {
|
||||
tagIds,
|
||||
notTagIds,
|
||||
entityId,
|
||||
notEntityIds,
|
||||
} = await promiseProps({
|
||||
tagIds: getIdsBySlug([query.tagSlug, ...splitTags.filter((tag) => tag.charAt(0) !== '!')], 'tags'),
|
||||
notTagIds: getIdsBySlug([...query.tagFilter, ...(splitTags.filter((tag) => tag.charAt(0) === '!').map((tag) => tag.slice(1)) || [])].map((tag) => slugify(tag)), 'tags'),
|
||||
entityId: mainEntity ? await getIdsBySlug([mainEntity], 'entities').then(([id]) => id) : query.entityId,
|
||||
notEntityIds: await getIdsBySlug(splitEntities.filter((entity) => entity.charAt(0) === '!').map((entity) => entity.slice(1)), 'entities'),
|
||||
});
|
||||
|
||||
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,
|
||||
actorIds: [query.actorId, ...splitActors.filter((actor) => actor.charAt(0) !== '!').map((identifier) => parseActorIdentifier(identifier)?.id)].filter(Boolean),
|
||||
notActorIds: splitActors.filter((actor) => actor.charAt(0) === '!').map((identifier) => parseActorIdentifier(identifier.slice(1))?.id).filter(Boolean),
|
||||
tagIds,
|
||||
notTagIds: notTagIds.filter((tagId) => !tagIds.includes(tagId)), // included tags get priority over excluded tags
|
||||
entityId,
|
||||
notEntityIds,
|
||||
movieId: Number(query.movieId) || null,
|
||||
stashId: Number(query.stashId) || null,
|
||||
};
|
||||
@@ -24,7 +46,10 @@ export async function fetchScenesApi(req, res) {
|
||||
aggChannels,
|
||||
limit,
|
||||
total,
|
||||
} = await fetchScenes(await curateScenesQuery(req.query), {
|
||||
} = await fetchScenes(await curateScenesQuery({
|
||||
...req.query,
|
||||
tagFilter: req.tagFilter,
|
||||
}), {
|
||||
page: Number(req.query.page) || 1,
|
||||
limit: Number(req.query.limit) || 30,
|
||||
}, req.user);
|
||||
|
||||
@@ -5,6 +5,7 @@ import Router from 'express-promise-router';
|
||||
import session from 'express-session';
|
||||
import RedisStore from 'connect-redis';
|
||||
import compression from 'compression';
|
||||
import cookie from 'cookie';
|
||||
import { renderPage } from 'vike/server'; // eslint-disable-line import/extensions
|
||||
|
||||
// import root from './root.js';
|
||||
@@ -58,6 +59,17 @@ export default async function initServer() {
|
||||
router.use('/', express.static('static'));
|
||||
router.use('/media', express.static(config.media.path));
|
||||
|
||||
router.use((req, res, next) => {
|
||||
const cookies = cookie.parse(req.headers.cookie);
|
||||
|
||||
/* eslint-disable no-param-reassign */
|
||||
req.cookies = cookies;
|
||||
req.tagFilter = cookies.tags ? JSON.parse(cookies.tags) : [];
|
||||
/* eslint-enable no-param-reassign */
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
router.use(express.json());
|
||||
|
||||
const redisStore = new RedisStore({
|
||||
@@ -129,6 +141,9 @@ export default async function initServer() {
|
||||
const pageContextInit = {
|
||||
urlOriginal: req.originalUrl,
|
||||
urlQuery: req.query, // vike's own query does not apply boolean parser
|
||||
headers: req.headers,
|
||||
cookies: req.cookies,
|
||||
tagFilter: req.tagFilter,
|
||||
user: req.user && {
|
||||
id: req.user.id,
|
||||
username: req.user.username,
|
||||
|
||||
Reference in New Issue
Block a user