improved oEmbed response generation

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

@ -102,7 +102,7 @@ If you primarily share media on Discord, you can add these additional (optional)
| **`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-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`** | Smaller text shown above the author |
| **`X-Ass-OG-Provider-Url`** | URL to open when the Provider is clicked | | **`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` |

@ -189,16 +189,16 @@ function startup() {
// If the ID is invalid, return 404 // If the ID is invalid, return 404
if (!resourceId || !data[resourceId]) return res.sendStatus(404); if (!resourceId || !data[resourceId]) return res.sendStatus(404);
// Build the oEmbed object // Build the oEmbed object & send the response
let { opengraph, mimetype } = data[resourceId]; let { opengraph, mimetype } = data[resourceId];
let oembed = { version: '1.0', type: mimetype.includes('video') ? 'video' : 'photo' }; res.type('json').send({
opengraph.author && (oembed.author_name = opengraph.author); version: '1.0',
opengraph.authorUrl && (oembed.author_url = opengraph.authorUrl); type: mimetype.includes('video') ? 'video' : 'photo',
opengraph.provider && (oembed.provider_name = opengraph.provider); author_name: opengraph.author,
opengraph.providerUrl && (oembed.provider_url = opengraph.providerUrl); author_url: opengraph.authorUrl,
provider_name: opengraph.provider,
// Send the oEmbed resonse provider_url: opengraph.providerUrl
res.type('json').send(oembed); });
}); });
// Delete file // Delete file

@ -63,14 +63,16 @@ const html = `
<html> <html>
<head> <head>
<title>ass</title> <title>ass</title>
<!-- Open Graph (https://ogp.me/) -->
<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 rel="alternate" type="application/json+oembed" href="{{{http}}}{{{domain}}}/{{{resourceId}}}/oembed.json" title="oEmbed">
{{{title}}} {{{title}}}
{{{description}}} {{{description}}}
{{{site}}} {{{site}}}
{{{color}}} {{{color}}}
{{{card}}} {{{card}}}
<!-- oEmbed (https://oembed.com/) -->
<link rel="alternate" type="application/json+oembed" href="{{{http}}}{{{domain}}}/{{{resourceId}}}/oembed.json" title="oEmbed">
</head> </head>
<body> <body>
Open Graph response for <a href="{{{github}}}" target="_blank">ass</a>. Open Graph response for <a href="{{{github}}}" target="_blank">ass</a>.

Loading…
Cancel
Save