30 lines
907 B
JavaScript
30 lines
907 B
JavaScript
export default function consentHandler(req, res, next) {
|
|
if (Object.hasOwn(req.query, 'lgbt')) {
|
|
const lgbtFilters = (req.tagFilter || []).filter((tag) => !['gay', 'bisexual', 'transsexual'].includes(tag));
|
|
|
|
req.tagFilter = lgbtFilters; // eslint-disable-line no-param-reassign
|
|
res.cookie('tags', JSON.stringify(lgbtFilters));
|
|
}
|
|
|
|
if (Object.hasOwn(req.query, 'straight')) {
|
|
const straightFilters = Array.from(new Set([...(req.tagFilter || []), 'gay', 'bisexual', 'transsexual']));
|
|
|
|
req.tagFilter = straightFilters; // eslint-disable-line no-param-reassign
|
|
res.cookie('tags', JSON.stringify(straightFilters));
|
|
}
|
|
|
|
if (Object.hasOwn(req.query, 'consent')) {
|
|
req.session.hasConsent = true; // eslint-disable-line no-param-reassign
|
|
res.redirect(req.path);
|
|
|
|
return;
|
|
}
|
|
|
|
if (!req.path.includes('/consent') && !req.session?.hasConsent) {
|
|
res.redirect('/consent');
|
|
return;
|
|
}
|
|
|
|
next();
|
|
}
|