added oEmbed support for clickable Authors/Providers

pull/19/head
tycrek 4 years ago
parent d0bf63b077
commit da328cc4ac
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -101,6 +101,9 @@ If you primarily share media on Discord, you can add these additional (optional)
| **`X-Ass-OG-Title`** | Large text shown above your media | | **`X-Ass-OG-Title`** | Large text shown above your media |
| **`X-Ass-OG-Description`** | Small text shown below the title but above the media (does not show up on videos yet) | | **`X-Ass-OG-Description`** | Small text shown below the title but above the media (does not show up on videos yet) |
| **`X-Ass-OG-Author`** | Small text shown above the title | | **`X-Ass-OG-Author`** | Small text shown above the title |
| **`X-Ass-OG-Author-Url`** | URL to open when the Author is clicked |
| **`X-Ass-OG-Provider`** | Similar to Author. Used to describe the site serving the resource |
| **`X-Ass-OG-Provider-Url`** | URL to open when the Provider is clicked |
| **`X-Ass-OG-Color`** | Colour shown on the left side of the embed. Must be either a hex colour value (for example: `#fe3c29`) or `&random` | | **`X-Ass-OG-Color`** | Colour shown on the left side of the embed. Must be either a hex colour value (for example: `#fe3c29`) or `&random` |
#### Embed placeholders #### Embed placeholders

@ -103,6 +103,9 @@ function startup() {
title: req.headers['x-ass-og-title'], title: req.headers['x-ass-og-title'],
description: req.headers['x-ass-og-description'], description: req.headers['x-ass-og-description'],
author: req.headers['x-ass-og-author'], author: req.headers['x-ass-og-author'],
authorUrl: req.headers['x-ass-og-author-url'],
provider: req.headers['x-ass-og-provider'],
providerUrl: req.headers['x-ass-og-provider-url'],
color: req.headers['x-ass-og-color'] color: req.headers['x-ass-og-color']
}; };
@ -176,6 +179,28 @@ function startup() {
.catch(console.error); .catch(console.error);
}); });
// oEmbed response for clickable authors/providers
// https://oembed.com/
// https://old.reddit.com/r/discordapp/comments/82p8i6/a_basic_tutorial_on_how_to_get_the_most_out_of/
app.get('/:resourceId/oembed', (req, res) => {
// Parse the resource ID
let resourceId = req.params.resourceId.split('.')[0];
// If the ID is invalid, return 404
if (!resourceId || !data[resourceId]) return res.sendStatus(404);
// Build the oEmbed object
let { opengraph } = data[resourceId];
let oembed = {};
opengraph.author && (oembed.author_name = opengraph.author);
opengraph.authorUrl && (oembed.author_url = opengraph.authorUrl);
opengraph.provider && (oembed.provider_name = opengraph.provider);
opengraph.providerUrl && (oembed.provider_url = opengraph.providerUrl);
// Send the oEmbed resonse
res.type('application/json+oembed').send(oembed);
});
// Delete file // Delete file
app.get('/delete/:filename', (req, res) => { app.get('/delete/:filename', (req, res) => {
let filename = req.params.filename; let filename = req.params.filename;

@ -3,7 +3,7 @@ const DateTime = require('luxon').DateTime;
const github = require('./package.json').homepage; const github = require('./package.json').homepage;
const { formatBytes, randomHexColour } = require('./utils'); const { formatBytes, randomHexColour } = require('./utils');
// // https://ogp.me/
class OpenGraph { class OpenGraph {
http; http;
domain; domain;
@ -65,6 +65,7 @@ const html = `
<title>ass</title> <title>ass</title>
<meta property="og:type" content="{{{ogtype}}}"> <meta property="og:type" content="{{{ogtype}}}">
<meta property="og:{{{type}}}" content="{{{http}}}{{{domain}}}/{{{resourceId}}}{{{ext}}}"> <meta property="og:{{{type}}}" content="{{{http}}}{{{domain}}}/{{{resourceId}}}{{{ext}}}">
<link type="application/json+oembed" href="/{{{resourceId}}}/oembed">
{{{title}}} {{{title}}}
{{{description}}} {{{description}}}
{{{site}}} {{{site}}}

Loading…
Cancel
Save