Added experimental GraphQL API.
This commit is contained in:
parent
c4dc953d63
commit
c169e5c008
|
@ -35,6 +35,7 @@
|
||||||
"express-query-boolean": "^2.0.0",
|
"express-query-boolean": "^2.0.0",
|
||||||
"express-session": "^1.18.0",
|
"express-session": "^1.18.0",
|
||||||
"floating-vue": "^5.2.2",
|
"floating-vue": "^5.2.2",
|
||||||
|
"graphql": "^16.9.0",
|
||||||
"ip-cidr": "^4.0.0",
|
"ip-cidr": "^4.0.0",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"knex": "^3.1.0",
|
"knex": "^3.1.0",
|
||||||
|
@ -6310,6 +6311,14 @@
|
||||||
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/graphql": {
|
||||||
|
"version": "16.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz",
|
||||||
|
"integrity": "sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==",
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/has-bigints": {
|
"node_modules/has-bigints": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz",
|
||||||
|
@ -14877,6 +14886,11 @@
|
||||||
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"graphql": {
|
||||||
|
"version": "16.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz",
|
||||||
|
"integrity": "sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw=="
|
||||||
|
},
|
||||||
"has-bigints": {
|
"has-bigints": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz",
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
"express-query-boolean": "^2.0.0",
|
"express-query-boolean": "^2.0.0",
|
||||||
"express-session": "^1.18.0",
|
"express-session": "^1.18.0",
|
||||||
"floating-vue": "^5.2.2",
|
"floating-vue": "^5.2.2",
|
||||||
|
"graphql": "^16.9.0",
|
||||||
"ip-cidr": "^4.0.0",
|
"ip-cidr": "^4.0.0",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"knex": "^3.1.0",
|
"knex": "^3.1.0",
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
export default function consentHandler(req, res, next) {
|
export default function consentHandler(req, res, next) {
|
||||||
const redirect = req.headers.referer && new URL(req.headers.referer).searchParams.get('redirect');
|
const redirect = req.headers.referer && new URL(req.headers.referer).searchParams.get('redirect');
|
||||||
|
|
||||||
if (req.path.includes('/api')) {
|
|
||||||
next();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.hasOwn(req.query, 'lgbt')) {
|
if (Object.hasOwn(req.query, 'lgbt')) {
|
||||||
const lgbtFilters = (req.tagFilter || []).filter((tag) => !['gay', 'bisexual', 'transsexual'].includes(tag));
|
const lgbtFilters = (req.tagFilter || []).filter((tag) => !['gay', 'bisexual', 'transsexual'].includes(tag));
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,6 @@ export async function curateScenesQuery(query) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchScenesApi(req, res) {
|
export async function fetchScenesApi(req, res) {
|
||||||
console.log('REQUEST', req.query);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
scenes,
|
scenes,
|
||||||
aggActors,
|
aggActors,
|
||||||
|
@ -58,8 +56,6 @@ export async function fetchScenesApi(req, res) {
|
||||||
limit: Number(req.query.limit) || 30,
|
limit: Number(req.query.limit) || 30,
|
||||||
}, req.user);
|
}, req.user);
|
||||||
|
|
||||||
console.log('OUTPUT', scenes.length);
|
|
||||||
|
|
||||||
res.send(stringify({
|
res.send(stringify({
|
||||||
scenes,
|
scenes,
|
||||||
aggActors,
|
aggActors,
|
||||||
|
@ -69,3 +65,33 @@ export async function fetchScenesApi(req, res) {
|
||||||
total,
|
total,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const scenesSchema = `
|
||||||
|
type Scene {
|
||||||
|
id: Int!
|
||||||
|
title: String
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export async function fetchScenesGraphql(query, req) {
|
||||||
|
const {
|
||||||
|
scenes,
|
||||||
|
aggActors,
|
||||||
|
aggTags,
|
||||||
|
aggChannels,
|
||||||
|
limit,
|
||||||
|
total,
|
||||||
|
} = await fetchScenes({}, {
|
||||||
|
page: 1,
|
||||||
|
limit: 30,
|
||||||
|
}, req.user);
|
||||||
|
|
||||||
|
return {
|
||||||
|
scenes,
|
||||||
|
aggActors,
|
||||||
|
aggTags,
|
||||||
|
aggChannels,
|
||||||
|
limit,
|
||||||
|
total,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ import compression from 'compression';
|
||||||
import cookie from 'cookie';
|
import cookie from 'cookie';
|
||||||
import { renderPage } from 'vike/server'; // eslint-disable-line import/extensions
|
import { renderPage } from 'vike/server'; // eslint-disable-line import/extensions
|
||||||
|
|
||||||
// import root from './root.js';
|
|
||||||
|
|
||||||
import redis from '../redis.js';
|
import redis from '../redis.js';
|
||||||
|
|
||||||
import errorHandler from './error.js';
|
import errorHandler from './error.js';
|
||||||
|
@ -22,6 +20,8 @@ import { fetchMoviesApi } from './movies.js';
|
||||||
import { fetchEntitiesApi } from './entities.js';
|
import { fetchEntitiesApi } from './entities.js';
|
||||||
import { fetchTagsApi } from './tags.js';
|
import { fetchTagsApi } from './tags.js';
|
||||||
|
|
||||||
|
import { graphqlApi } from './graphql.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
setUserApi,
|
setUserApi,
|
||||||
loginApi,
|
loginApi,
|
||||||
|
@ -124,8 +124,6 @@ export default async function initServer() {
|
||||||
router.use(viteDevMiddleware);
|
router.use(viteDevMiddleware);
|
||||||
}
|
}
|
||||||
|
|
||||||
router.use(consentHandler);
|
|
||||||
|
|
||||||
router.get('/consent', (req, res) => {
|
router.get('/consent', (req, res) => {
|
||||||
res.sendFile(path.join(import.meta.dirname, '../../assets/consent.html'));
|
res.sendFile(path.join(import.meta.dirname, '../../assets/consent.html'));
|
||||||
});
|
});
|
||||||
|
@ -175,6 +173,9 @@ export default async function initServer() {
|
||||||
// TAGS
|
// TAGS
|
||||||
router.get('/api/tags', fetchTagsApi);
|
router.get('/api/tags', fetchTagsApi);
|
||||||
|
|
||||||
|
router.post('/graphql', graphqlApi);
|
||||||
|
router.use(consentHandler);
|
||||||
|
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
res.set('Accept-CH', 'Sec-CH-Prefers-Color-Scheme');
|
res.set('Accept-CH', 'Sec-CH-Prefers-Color-Scheme');
|
||||||
|
|
Loading…
Reference in New Issue