diff --git a/README.md b/README.md index 05f6a2d..8978ce4 100755 --- a/README.md +++ b/README.md @@ -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. diff --git a/ass.js b/ass.js index 1c88511..9770ab4 100755 --- a/ass.js +++ b/ass.js @@ -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 ` + + + ass + + + + ass + +`; +} diff --git a/setup.js b/setup.js index 61639c4..1371fba 100755 --- a/setup.js +++ b/setup.js @@ -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 } } }; diff --git a/utils.js b/utils.js index 182038d..81c33f9 100755 --- a/utils.js +++ b/utils.js @@ -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 = {