44 lines
1.0 KiB
JavaScript
Executable File
44 lines
1.0 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
const config = require('config');
|
|
const { makeExtendSchemaPlugin, gql } = require('graphile-utils');
|
|
|
|
const schemaExtender = makeExtendSchemaPlugin((_build) => ({
|
|
typeDefs: gql`
|
|
extend type Media {
|
|
thumbnailWidth: Int @requires(columns: ["width", "height"])
|
|
thumbnailHeight: Int @requires(columns: ["height", "width"])
|
|
}
|
|
`,
|
|
resolvers: {
|
|
Media: {
|
|
thumbnailWidth(parent, _args, _context, _info) {
|
|
if (!parent.width || !parent.height) {
|
|
return null;
|
|
}
|
|
|
|
if (parent.height <= config.media.thumbnailSize) {
|
|
// thumbnails aren't upscaled
|
|
return parent.width;
|
|
}
|
|
|
|
return Math.round(parent.width / (parent.height / config.media.thumbnailSize));
|
|
},
|
|
thumbnailHeight(parent, _args, _context, _info) {
|
|
if (!parent.width || !parent.height) {
|
|
return null;
|
|
}
|
|
|
|
if (parent.height <= config.media.thumbnailSize) {
|
|
// thumbnails aren't upscaled
|
|
return parent.height;
|
|
}
|
|
|
|
return config.media.thumbnailSize;
|
|
},
|
|
},
|
|
},
|
|
}));
|
|
|
|
module.exports = [schemaExtender];
|