pull/12/head
tycrek 4 years ago
parent ebd4e55ee4
commit 8135b3a46d
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -66,18 +66,10 @@ function startup() {
// View file
app.get('/:resourceId', (req, res) => {
let resourceId = req.params.resourceId.split('.')[0];
let isMp4Req = req.params.resourceId.split('.')[1] == 'mp4';
let isBot = req.useragent.isBot == 'discordbot';
let redirect = req.query['redirect'];
if (data[resourceId] && data[resourceId].mimetype == 'video/mp4' && !isMp4Req && isBot && redirect) return res.redirect(req.url + '.mp4');
let fileData = fs.readFileSync(path(data[resourceId].path));
if (data[resourceId] && data[resourceId].mimetype == 'video/mp4' && !isMp4Req && isBot && !redirect)
res.type('html').send(generateDiscordMp4Response(req.url + '?redirect=true'));
else 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])
res/* .header('Accept-Ranges', 'bytes').header('Content-Length', fileData.byteLength).type(data[resourceId].mimetype).send(fileData); */.sendFile(path(data[resourceId].path));
else
res.sendStatus(404);
});
@ -101,17 +93,3 @@ 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 '' +
'<html>' + '\n' +
'<head>' + '\n' +
`\t<meta property="og:video" content="${url}">` + '\n' +
`\t<meta property="og:url" content="${url}">` + '\n' +
'</head>' + '\n' +
'<body>' + '\n' +
`\t<video src="${url}" type="video/mp4" controls>Your browser does not support HTML5 video tags.</video>` + '\n' +
'</body>' + '\n' +
'</html>';
}
Loading…
Cancel
Save