Added MIME types and stuff so the browser is able to show the file [experimental]
This commit is contained in:
parent
2d9e3fc94c
commit
e8f03c430c
1 changed files with 10 additions and 3 deletions
|
@ -3,10 +3,12 @@
|
||||||
|
|
||||||
use Mojolicious::Lite -signatures;
|
use Mojolicious::Lite -signatures;
|
||||||
use Mojolicious::Routes::Pattern;
|
use Mojolicious::Routes::Pattern;
|
||||||
|
use List::MoreUtils qw(any uniq);
|
||||||
|
use MIME::Types;
|
||||||
use v5.36;
|
use v5.36;
|
||||||
plugin 'RenderFile';
|
plugin 'RenderFile';
|
||||||
|
|
||||||
|
|
||||||
my $MAX_SIZE = 1024 * 1024 * 100;
|
my $MAX_SIZE = 1024 * 1024 * 100;
|
||||||
|
|
||||||
my @BANNED = qw(); # Add banned IP addresses here
|
my @BANNED = qw(); # Add banned IP addresses here
|
||||||
|
@ -30,7 +32,7 @@ sub handle_file {
|
||||||
status => 400
|
status => 400
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ( $c->tx->remote_address ~~ @BANNED ) {
|
if ( any { /$c->tx->remote_address/ } uniq @BANNED ) {
|
||||||
$c->render(
|
$c->render(
|
||||||
text =>
|
text =>
|
||||||
"Hi! Seems like the server admin added your IP address to the banned IP array." .
|
"Hi! Seems like the server admin added your IP address to the banned IP array." .
|
||||||
|
@ -70,7 +72,12 @@ get '/f/:dir/:name' => sub ($c) {
|
||||||
my $captures = $c->req->url;
|
my $captures = $c->req->url;
|
||||||
$captures =~ s/^.//;
|
$captures =~ s/^.//;
|
||||||
my $filerender = Mojolicious::Plugin::RenderFile->new;
|
my $filerender = Mojolicious::Plugin::RenderFile->new;
|
||||||
$c->render_file( filepath => $captures );
|
my ($ext) = $captures =~ /(\.[^.]+)$/;
|
||||||
|
print $ext;
|
||||||
|
$c->render_file( filepath => $captures,
|
||||||
|
format => $ext,
|
||||||
|
content_disposition => 'inline'
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
app->max_request_size( 1024 * 1024 * 100 );
|
app->max_request_size( 1024 * 1024 * 100 );
|
||||||
|
|
Loading…
Add table
Reference in a new issue