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 = ` + + + ass + + + {{title}} + {{site}} + + ass + +`; + +module.exports = OpenGraph; diff --git a/package-lock.json b/package-lock.json index 8d1f917..723d980 100755 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ass", - "version": "1.0.0", + "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ass", - "version": "1.0.0", + "version": "0.1.0", "license": "ISC", "dependencies": { "crypto-random-string": "3.3.1", @@ -14,6 +14,7 @@ "express-useragent": "^1.0.15", "fs-extra": "^9.1.0", "multer": "^1.4.2", + "mustache": "^4.2.0", "prompt": "^1.1.0", "uuid": "^8.3.2" } @@ -594,6 +595,14 @@ "node": ">= 0.10.0" } }, + "node_modules/mustache": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", + "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", + "bin": { + "mustache": "bin/mustache" + } + }, "node_modules/mute-stream": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", @@ -1454,6 +1463,11 @@ "xtend": "^4.0.0" } }, + "mustache": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", + "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==" + }, "mute-stream": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", diff --git a/package.json b/package.json index 0fa2b4e..1dd0799 100755 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "express-useragent": "^1.0.15", "fs-extra": "^9.1.0", "multer": "^1.4.2", + "mustache": "^4.2.0", "prompt": "^1.1.0", "uuid": "^8.3.2" } -} \ No newline at end of file +}