@ -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 } \n Authorized tokens: ${ tokens . length } \n Available 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>' ;
}