attempting opengraph stuff

pull/15/head
tycrek 3 years ago
parent 6966f903d1
commit 020a53c4e0
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -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))

@ -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) ? `<meta property="og:title" content="${this.title}">` : '';
view.site = (this.author.length != 0) ? `<meta property="og:site_name" content="${this.author}">` : '';
return Mustache.render(html, view);
}
}
const html = `
<html>
<head>
<title>ass</title>
<meta property="og:type" content="{{ogtype}}">
<meta property="og:{{type}}" content="{{http}}{{domain}}/{{resourceId}}{{ext}}">
{{title}}
{{site}}
</head>
<body>ass</body>
</html>
`;
module.exports = OpenGraph;

18
package-lock.json generated

@ -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",

@ -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"
}
}
}

Loading…
Cancel
Save