Added working Discord video embeds (#6)

pull/12/head
Josh Moore 3 years ago committed by GitHub
parent a9efc94a7f
commit 39b61774bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,7 +7,7 @@ This project is still very young, so don't expect *everything* to be perfect yet
- ✔️ Token authorization via HTTP `Authorization` header
- ✔️ Upload images, videos, files
- ✔️ Discord compatibility mode for video embed
- ✔️ Seamless inline video embeds on Discord
- ❌ Thumbnail support
- ✔️ Delete support
- ❌ Multiple database types (JSON, Mongo, MySQL, PostgreSQL, etc. Currently uses JSON)
@ -59,7 +59,3 @@ The installation may look daunting but it's really pretty straightforward. Just
- URL: `$json:.resource$`
- Deletion URL: `$json:.delete$`
6. The file `sample_config.sxcu` can also be modified & imported to suit your needs
## Known issues
- **Videos won't embed on Discord**: I know. This is because Discord developers make some really stupid decisions & only show embeds if the URL ends with `.mp4`. To fix this, either enable Discord Mode during `npm run setup` or manually append "`.mp4`" to the end of your URL's when sharing on Discord.

@ -7,7 +7,7 @@ try {
}
// Load the config
const { host, port, domain, useSsl, resourceIdSize, resourceIdType, discordMode, isProxied } = require('./config.json');
const { host, port, domain, useSsl, resourceIdSize, resourceIdType, isProxied } = require('./config.json');
//#region Imports
const fs = require('fs-extra');
@ -63,12 +63,10 @@ function startup() {
data[resourceId.split('.')[0]] = req.file;
saveData(data);
let http = ('http').concat(useSsl ? 's' : '').concat('://');
let trueDomain = domain.concat((port == 80 || port == 443 || isProxied) ? '' : `:${port}`);
let discordCompat = (discordMode && req.file.mimetype == 'video/mp4') ? '.mp4' : '';
// Send the response
res.type('json').send({
resource: `${http}${trueDomain}/${resourceId}${discordCompat}`,
delete: `${http}${trueDomain}/delete/${req.file.filename}`
resource: `${getTrueHttp()}${getTrueDomain()}/${resourceId}`,
delete: `${getTrueHttp()}${getTrueDomain()}/delete/${req.file.filename}`
});
});
@ -83,6 +81,9 @@ function startup() {
// If the ID is invalid, return 404
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));
// Read the file and send it to the client
fs.readFile(path(data[resourceId].path))
.then((fileData) => res
@ -112,3 +113,23 @@ function startup() {
app.listen(port, host, () => log(`Server started on [${host}:${port}]\nAuthorized tokens: ${tokens.length}\nAvailable files: ${Object.keys(data).length}`));
}
function getTrueHttp() {
return ('http').concat(useSsl ? 's' : '').concat('://');
}
function getTrueDomain() {
return domain.concat((port == 80 || port == 443 || isProxied) ? '' : `:${port}`);
}
function genHtml(resourceId) {
return `
<html>
<head>
<title>ass</title>
<meta property="og:type" content="video.other">
<meta property="og:video" content="${getTrueHttp()}${getTrueDomain()}/${resourceId}.mp4">
</head>
<body>ass</body>
</html>
`;
}

@ -15,8 +15,7 @@ const config = {
useSsl: true,
isProxied: true,
resourceIdSize: 12,
resourceIdType: 'zws',
discordMode: false
resourceIdType: 'zws'
};
// Schema for setup prompts
@ -65,12 +64,6 @@ const setupSchema = {
require: false,
pattern: /(original|zws|random)/gi,
message: 'Must be one of: original, zws, random'
},
discordMode: {
description: 'Discord Mode (will automatically attach .mp4 to your video URLs so Discord embeds them properly)',
type: 'boolean',
default: config.discordMode,
required: false
}
}
};

@ -7,6 +7,7 @@ const idModes = {
zws: 'zws', // Zero-width spaces (see: https://zws.im/)
og: 'original', // Use original uploaded filename
r: 'random' // Use a randomly generated ID with a mixed-case alphanumeric character set
// todo: gfycat-style ID's (example.com/correct-horse-battery-staple)
};
module.exports = {

Loading…
Cancel
Save