Tied consent warning to session.

This commit is contained in:
DebaucheryLibrarian 2020-12-19 23:01:17 +01:00
parent be4d025505
commit bd77d4347d
10 changed files with 121 additions and 11 deletions

View File

@ -6,7 +6,8 @@
<Warning
v-if="showWarning"
class="warning-container"
@enter="closeWarning"
@enter="setConsent(true)"
@leave="setConsent(false)"
/>
<transition name="slide">
@ -41,9 +42,11 @@ function toggleSidebar(state) {
this.showSidebar = typeof state === 'boolean' ? state : !this.showSidebar;
}
function closeWarning() {
this.showWarning = false;
sessionStorage.setItem('warning', 'warned');
async function setConsent(consent) {
if (consent) {
this.showWarning = false;
await this.$store.dispatch('setConsent', true);
}
}
function mounted() {
@ -61,7 +64,7 @@ export default {
data() {
return {
showSidebar: false,
showWarning: sessionStorage.getItem('warning') !== 'warned',
showWarning: !window.env.consent,
};
},
computed: {
@ -72,7 +75,7 @@ export default {
mounted,
methods: {
toggleSidebar,
closeWarning,
setConsent,
},
};
</script>

View File

@ -21,6 +21,7 @@
<a
href="https://www.google.com"
class="button leave"
@click="$emit('leave')"
>Leave</a>
<button

View File

@ -1,4 +1,4 @@
import { graphql } from '../api';
import { graphql, post } from '../api';
import { curateRelease, curateActor } from '../curate';
function initUiActions(_store, _router) {
@ -26,6 +26,12 @@ function initUiActions(_store, _router) {
localStorage.setItem('sfw', sfw);
}
async function setConsent({ _commit }, consent) {
const res = await post('/consent', consent);
return res.ok;
}
async function search({ _commit }, { query, limit = 20 }) {
const res = await graphql(`
query SearchReleases(
@ -188,6 +194,7 @@ function initUiActions(_store, _router) {
setRange,
setBatch,
setSfw,
setConsent,
setTheme,
fetchStats,
};

View File

@ -10,6 +10,14 @@ module.exports = {
port: 5000,
sfwHost: '0.0.0.0',
sfwPort: 5001,
session: {
secret: '12345678abcdefghij',
resave: false,
saveUninitialized: false,
cookie: {
secure: false,
},
},
},
exclude: {
channels: [

67
package-lock.json generated
View File

@ -2918,6 +2918,15 @@
"integrity": "sha512-KbS1Y0jMtyPgIxjO7ZzMAuUpAKMt1SzCL9fsrKsX6b0zJPTaT0SiSPmewwVZg9UAO83HVIlEhZF84LIjZ0lmAw==",
"dev": true
},
"connect-session-knex": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/connect-session-knex/-/connect-session-knex-2.0.0.tgz",
"integrity": "sha512-1QaN7k9NjXcXmE+MHoH7YeAGcUGdqZzpIKb8otHgqFQ2IYLhoeGG/o1PP2cdJZNgcr1gPHJEL8hmKIx8XosOhg==",
"requires": {
"bluebird": "^3.7.2",
"knex": "^0.21.5"
}
},
"console-browserify": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.2.0.tgz",
@ -4483,6 +4492,46 @@
"object-assign": "^4.1.1"
}
},
"express-session": {
"version": "1.17.1",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.1.tgz",
"integrity": "sha512-UbHwgqjxQZJiWRTMyhvWGvjBQduGCSBDhhZXYenziMFjxst5rMV+aJZ6hKPHZnPyHGsrqRICxtX8jtEbm/z36Q==",
"requires": {
"cookie": "0.4.0",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "~2.0.0",
"on-headers": "~1.0.2",
"parseurl": "~1.3.3",
"safe-buffer": "5.2.0",
"uid-safe": "~2.1.5"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"safe-buffer": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
"integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg=="
}
}
},
"extend": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-2.0.2.tgz",
@ -8179,6 +8228,11 @@
"ee-first": "1.1.1"
}
},
"on-headers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA=="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@ -9090,6 +9144,11 @@
"integrity": "sha1-nsYfeQSYdXB9aUFFlv2Qek1xHnM=",
"dev": true
},
"random-bytes": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
"integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs="
},
"randombytes": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
@ -11454,6 +11513,14 @@
"is-typedarray": "^1.0.0"
}
},
"uid-safe": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
"integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
"requires": {
"random-bytes": "~1.0.0"
}
},
"umzug": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/umzug/-/umzug-2.2.0.tgz",

View File

@ -85,6 +85,7 @@
"cheerio": "^1.0.0-rc.3",
"cli-confirm": "^1.0.1",
"config": "^3.2.5",
"connect-session-knex": "^2.0.0",
"csv-stringify": "^5.3.6",
"dayjs": "^1.8.21",
"dompurify": "^2.0.11",
@ -92,6 +93,7 @@
"express": "^4.17.1",
"express-promise-router": "^3.0.3",
"express-react-views": "^0.11.0",
"express-session": "^1.17.1",
"face-api.js": "^0.22.2",
"faker": "^5.1.0",
"file-type": "^14.1.4",

View File

@ -8,5 +8,5 @@ module.exports = knex({
connection: config.database,
// performance overhead, don't use asyncStackTraces in production
asyncStackTraces: process.env.NODE_ENV === 'development',
debug: process.env.NODE_ENV === 'development',
// debug: process.env.NODE_ENV === 'development',
});

View File

@ -126,7 +126,7 @@ function toBaseSource(rawSource) {
return null;
}
function baseSourceToBaseMedia(baseSource, role, metadata) {
function baseSourceToBaseMedia(baseSource, role, metadata, options) {
if (Array.isArray(baseSource)) {
if (baseSource.length > 0) {
return {
@ -134,6 +134,7 @@ function baseSourceToBaseMedia(baseSource, role, metadata) {
id: nanoid(),
role,
sources: baseSource,
...options,
};
}
@ -146,6 +147,7 @@ function baseSourceToBaseMedia(baseSource, role, metadata) {
id: nanoid(),
role,
sources: [baseSource],
...options,
};
}
@ -299,6 +301,8 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
const info = await image.metadata();
const isProcessed = media.meta.subtype !== 'jpeg' || media.process;
console.log(media);
if (media.process) {
Object.entries(media.process).forEach(([operation, options]) => {
if (image[operation]) {
@ -727,9 +731,9 @@ async function associateAvatars(profiles) {
? {
...profile,
avatarBaseMedia: toBaseMedias([profile.avatar], 'avatars', {
credit: (profile.credit !== undefined && (profile.network?.name || profile.site?.name)) || null,
credit: profile.credit || profile.entity?.name || null,
scraper: profile.scraper || null,
})[0],
}, { stats: true })[0],
}
: profile
));

8
src/web/consent.js Normal file
View File

@ -0,0 +1,8 @@
'use strict';
function setConsent(req, res) {
req.session.consent = !!req.body;
res.status(204).send();
}
module.exports = setConsent;

View File

@ -6,12 +6,15 @@ const express = require('express');
const { postgraphile } = require('postgraphile');
const Router = require('express-promise-router');
const bodyParser = require('body-parser');
const session = require('express-session');
const KnexSessionStore = require('connect-session-knex')(session);
const PgConnectionFilterPlugin = require('postgraphile-plugin-connection-filter');
const PgSimplifyInflectorPlugin = require('@graphile-contrib/pg-simplify-inflector');
const PgOrderByRelatedPlugin = require('@graphile-contrib/pg-order-by-related');
const logger = require('../logger')(__filename);
const knex = require('../knex');
const { ActorPlugins, SitePlugins, ReleasePlugins } = require('./plugins/plugins');
const {
@ -35,9 +38,12 @@ const {
fetchTags,
} = require('./tags');
const setConsent = require('./consent');
async function initServer() {
const app = express();
const router = Router();
const store = new KnexSessionStore({ knex });
const connectionString = `postgres://${config.database.user}:${config.database.password}@${config.database.host}:5432/${config.database.database}`;
@ -77,6 +83,7 @@ async function initServer() {
});
router.use(bodyParser.json({ strict: false }));
router.use(session({ ...config.web.session, store }));
router.get('/api/scenes', fetchScenes);
router.get('/api/scenes/:releaseId', fetchScene);
@ -103,10 +110,13 @@ async function initServer() {
router.get('/api/tags', fetchTags);
router.get('/api/tags/:tagId', fetchTag);
router.post('/api/consent', setConsent);
router.get('*', (req, res) => {
res.render(path.join(__dirname, '../../assets/index.ejs'), {
env: JSON.stringify({
sfw: !!req.headers.sfw || Object.prototype.hasOwnProperty.call(req.query, 'sfw'),
consent: !!req.session.consent,
}),
});
});