const Mustache = require('mustache'); const DateTime = require('luxon').DateTime; const github = require('./package.json').homepage; const { formatBytes, randomHexColour } = require('./utils'); // class OpenGraph { http; domain; resourceId; filename; type; size; timestamp; title; description; author; color; constructor(http, domain, resourceId, { originalname, mimetype, size, timestamp, opengraph }) { this.http = http; this.domain = domain; this.resourceId = resourceId; this.type = mimetype; this.filename = originalname; this.size = size; this.timestamp = timestamp; this.title = opengraph.title || ''; this.description = opengraph.description || ''; this.author = opengraph.author || ''; this.color = opengraph.color || ''; } build() { return Mustache.render(html, { github, http: this.http, domain: this.domain, resourceId: this.resourceId, ogtype: this.type.includes('video') ? 'video.other' : 'image', type: this.type.includes('video') ? 'video' : 'image', ext: this.type.includes('video') ? '.mp4' : this.type.includes('gif') ? '.gif' : '', title: (this.title.length != 0) ? `` : '', description: (this.description.length != 0) ? `` : '', site: (this.author.length != 0) ? `` : '', color: (this.color.length != 0) ? `` : '', card: !this.type.includes('video') ? `` : '', }) .replace(new RegExp('&size', 'g'), formatBytes(this.size)) .replace(new RegExp('&filename', 'g'), this.filename) .replace(new RegExp('×tamp', 'g'), DateTime.fromMillis(this.timestamp).toLocaleString(DateTime.DATETIME_MED)); } } const html = `