diff --git a/ass.js b/ass.js index 555e70b..42a1593 100755 --- a/ass.js +++ b/ass.js @@ -67,9 +67,11 @@ function startup() { app.get('/:resourceId', (req, res) => { log('Is bot: ' + (req.useragent.isBot == 'discordbot')); let resourceId = req.params.resourceId.split('.')[0]; - if (data[resourceId] && data[resourceId].mimetype == 'video/mp4' && req.params.resourceId.split('.')[1] != 'mp4') return res.redirect(req.url + '.mp4'); + let isMp4Req = req.params.resourceId.split('.')[1] == 'mp4'; + if (data[resourceId] && data[resourceId].mimetype == 'video/mp4' && !isMp4Req) return res.redirect(req.url + '.mp4'); let fileData = fs.readFileSync(path(data[resourceId].path)); - if (data[resourceId]) res.header('Accept-Ranges', 'bytes').header('Content-Length', fileData.byteLength).type(data[resourceId].mimetype).send(fileData);// .sendFile(path(data[resourceId].path)); + if (data[resourceId] && !isMp4Req) res.header('Accept-Ranges', 'bytes').header('Content-Length', fileData.byteLength).type(data[resourceId].mimetype).send(fileData);// .sendFile(path(data[resourceId].path)); + else if (data[resourceId] && isMp4Req) res.type('html').send(generateDiscordMp4Response(req.url + '.mp4')); else res.sendStatus(404); }); @@ -91,4 +93,18 @@ function startup() { }) app.listen(process.env.PORT, () => log(`Server started on port ${process.env.PORT}\nAuthorized tokens: ${tokens.length}\nAvailable files: ${Object.keys(data).length}`)); +} + +function generateDiscordMp4Response(url) { + log('Generating video for Discord'); + return '' + + '' + '\n' + + '
' + '\n' + + `\t` + '\n' + + `\t` + '\n' + + '' + '\n' + + '' + '\n' + + `\t` + '\n' + + '' + '\n' + + ''; } \ No newline at end of file