const Mustache = require('mustache'); const DateTime = require('luxon').DateTime; const { homepage, version } = require('./package.json'); const { s3enabled, s3endpoint, s3bucket } = require('./config.json'); const { formatBytes, randomHexColour } = require('./utils'); // https://ogp.me/ class OpenGraph { http; domain; resourceId; filename; type; size; timestamp; vibrant; title; description; author; color; constructor(http, domain, resourceId, { originalname, mimetype, size, timestamp, opengraph, vibrant }) { this.http = http; this.domain = domain; this.resourceId = resourceId; this.type = mimetype; this.filename = originalname; this.size = size; this.timestamp = timestamp; this.vibrant = vibrant; this.title = opengraph.title || ''; this.description = opengraph.description || ''; this.author = opengraph.author || ''; this.color = opengraph.color || ''; } build() { let resourceUrl = !s3enabled ? (this.http + this.domain + "/" + this.resourceId + (this.type.includes('video') ? '.mp4' : this.type.includes('gif') ? '.gif' : '')) : `https://${s3bucket}.${s3endpoint}/${this.filename}`; return Mustache.render(html, { homepage, version, http: this.http, domain: this.domain, resourceId: this.resourceId, resourceUrl, media: this.type.includes('video') ? `