Fixed summary copy button value. Expanded experimental GraphQL API.

This commit is contained in:
DebaucheryLibrarian 2024-08-28 02:06:01 +02:00
parent e727745e7d
commit 24f5597521
3 changed files with 84 additions and 8 deletions

View File

@ -458,7 +458,7 @@ function selectTemplate(templateId, allowFallback = true) {
selectTemplate(env.selectedTemplate); selectTemplate(env.selectedTemplate);
function copySummary() { function copySummary() {
navigator.clipboard.writeText(summary); navigator.clipboard.writeText(summary.value);
events.emit('feedback', { events.emit('feedback', {
type: 'success', type: 'success',

View File

@ -1,25 +1,48 @@
import { graphql, buildSchema } from 'graphql'; import {
graphql,
buildSchema,
GraphQLScalarType,
} from 'graphql';
import { scenesSchema, fetchScenesGraphql } from './scenes.js'; import { scenesSchema, fetchScenesGraphql } from './scenes.js';
const schema = buildSchema(` const schema = buildSchema(`
type Query { type Query {
scenes: [Scene] scenes(
limit: Int = 30
): Result
} }
scalar Date
${scenesSchema} ${scenesSchema}
`); `);
const DateTimeScalar = new GraphQLScalarType({
name: 'DateTime',
serialize(value) {
if (value instanceof Date) {
return value.toISOString();
}
return value;
},
});
export async function graphqlApi(req, res) { export async function graphqlApi(req, res) {
const data = await graphql({ const data = await graphql({
schema, schema,
source: req.body.query, source: req.body.query,
variableValues: req.body.variables, variableValues: req.body.variables,
resolvers: {
DateTimeScalar,
},
rootValue: { rootValue: {
scenes: async (query) => fetchScenesGraphql(query, req), scenes: async (query) => fetchScenesGraphql(query, req),
}, },
}); });
console.log(data); // console.log(data);
res.send(data); res.send(data);
} }

View File

@ -71,28 +71,81 @@ export async function fetchScenesApi(req, res) {
} }
export const scenesSchema = ` export const scenesSchema = `
type Aggregate {
actors: [Actor]
}
type Result {
nodes: [Scene]
aggregates: Aggregate
}
type Scene { type Scene {
id: Int! id: Int!
title: String title: String
effectiveDate: Date
shootId: Int
channel: Entity
network: Entity
actors: [Actor]
poster: Media
trailer: Media
photos: [Media]
covers: [Media]
}
type Actor {
id: Int!
name: String
slug: String
}
type Entity {
id: Int!
name: String
slug: String
parent: Entity
}
type Media {
id: String!
path: String
thumbnail: String
lazy: String
mime: String
hash: String
isS3: Boolean
width: Int
height: Int
size: Int
createdAt: Int
} }
`; `;
export async function fetchScenesGraphql(query, req) { export async function fetchScenesGraphql(query, req) {
const { const {
scenes, scenes,
/*
aggActors, aggActors,
/*
aggTags, aggTags,
aggChannels, aggChannels,
limit, limit,
total, total,
*/ */
} = await fetchScenes({}, { } = await fetchScenes({}, {
page: 1, page: query.page || 1,
limit: 30, limit: query.limit || 30,
}, req.user); }, req.user);
return scenes; // console.log('agg actors', aggActors);
console.log('query', query);
return {
nodes: scenes,
aggregates: {
actors: aggActors,
},
};
/* /*
return { return {