diff --git a/ass.js b/ass.js index 0a0567f..156e1b9 100755 --- a/ass.js +++ b/ass.js @@ -14,6 +14,7 @@ const fs = require('fs-extra'); const express = require('express'); const useragent = require('express-useragent'); const multer = require('multer'); +const OpenGraph = require('./ogp'); const { path, saveData, log, verify, generateToken, generateId } = require('./utils'); //#endregion @@ -108,7 +109,7 @@ function startup() { if (!resourceId || !data[resourceId]) return res.sendStatus(404); // If a Discord client wants to load an mp4, send the data needed for a proper inline embed - if (req.useragent.isBot && data[resourceId].mimetype == 'video/mp4') return res.type('html').send(genHtml(resourceId)); + if (req.useragent.isBot /* && data[resourceId].mimetype == 'video/mp4' */) return res.type('html').send(new OpenGraph(getTrueHttp(), getTrueDomain(), resourceId, data[resourceId]).build()); // Read the file and send it to the client fs.readFile(path(data[resourceId].path)) diff --git a/ogp.js b/ogp.js new file mode 100644 index 0000000..e61e11e --- /dev/null +++ b/ogp.js @@ -0,0 +1,81 @@ +/* + +Optional: +- og:title +- og:description +- og:site_name + +*/ +const Mustache = require('mustache'); + +// +class OpenGraph { + http; + domain; + resourceId; + + filename; + type; + size; + + title = ''; + author = ''; + showSize = false; + + constructor(http, domain, resourceId, { originalname, mimetype, size }) { + this.http = http; + this.domain = domain; + this.resourceId = resourceId; + + this.type = mimetype; + this.filename = originalname; + this.size = size; + } + + setTitle(title) { + this.title = title; + return this; + } + + setAuthor(author) { + this.author = author; + return this; + } + + setShowSize(showSize) { + this.showSize = showSize; + return this; + } + + build() { + let view = { + 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' : '', + }; + + view.title = (this.title.length != 0) ? `` : ''; + view.site = (this.author.length != 0) ? `` : ''; + + return Mustache.render(html, view); + } +} + +const html = ` + +
+