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);
function copySummary() {
navigator.clipboard.writeText(summary);
navigator.clipboard.writeText(summary.value);
events.emit('feedback', {
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';
const schema = buildSchema(`
type Query {
scenes: [Scene]
scenes(
limit: Int = 30
): Result
}
scalar Date
${scenesSchema}
`);
const DateTimeScalar = new GraphQLScalarType({
name: 'DateTime',
serialize(value) {
if (value instanceof Date) {
return value.toISOString();
}
return value;
},
});
export async function graphqlApi(req, res) {
const data = await graphql({
schema,
source: req.body.query,
variableValues: req.body.variables,
resolvers: {
DateTimeScalar,
},
rootValue: {
scenes: async (query) => fetchScenesGraphql(query, req),
},
});
console.log(data);
// console.log(data);
res.send(data);
}

View File

@ -71,28 +71,81 @@ export async function fetchScenesApi(req, res) {
}
export const scenesSchema = `
type Aggregate {
actors: [Actor]
}
type Result {
nodes: [Scene]
aggregates: Aggregate
}
type Scene {
id: Int!
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) {
const {
scenes,
/*
aggActors,
/*
aggTags,
aggChannels,
limit,
total,
*/
} = await fetchScenes({}, {
page: 1,
limit: 30,
page: query.page || 1,
limit: query.limit || 30,
}, req.user);
return scenes;
// console.log('agg actors', aggActors);
console.log('query', query);
return {
nodes: scenes,
aggregates: {
actors: aggActors,
},
};
/*
return {