More verbose error messages using the 'Carp' module and $ERRNO
This commit is contained in:
parent
c8f7473690
commit
b8dd0be83b
1 changed files with 15 additions and 5 deletions
|
@ -5,6 +5,8 @@ use if $^O eq "openbsd", OpenBSD::Pledge, qw(pledge);
|
||||||
use Mojolicious::Lite -signatures;
|
use Mojolicious::Lite -signatures;
|
||||||
use Mojolicious::Routes::Pattern;
|
use Mojolicious::Routes::Pattern;
|
||||||
use List::MoreUtils qw(any uniq);
|
use List::MoreUtils qw(any uniq);
|
||||||
|
use Carp;
|
||||||
|
use English;
|
||||||
use MIME::Types;
|
use MIME::Types;
|
||||||
use experimental 'signatures';
|
use experimental 'signatures';
|
||||||
plugin 'RenderFile';
|
plugin 'RenderFile';
|
||||||
|
@ -52,8 +54,10 @@ sub handle_file {
|
||||||
my @chars = ( '0' .. '9', 'a' .. 'Z' );
|
my @chars = ( '0' .. '9', 'a' .. 'Z' );
|
||||||
$dirname .= $chars[ rand @chars ] for 1 .. 5;
|
$dirname .= $chars[ rand @chars ] for 1 .. 5;
|
||||||
my $filename = $filedata->filename;
|
my $filename = $filedata->filename;
|
||||||
mkdir( "f/" . $dirname );
|
carp "sakisafe warning: could not create directory: $ERRNO" unless
|
||||||
|
mkdir( "f/" . $dirname );
|
||||||
$filename .= ".txt" if $filename eq "-";
|
$filename .= ".txt" if $filename eq "-";
|
||||||
|
|
||||||
$filedata->move_to( "f/" . $dirname . "/" . $filename );
|
$filedata->move_to( "f/" . $dirname . "/" . $filename );
|
||||||
my $host = $c->req->url->to_abs->host;
|
my $host = $c->req->url->to_abs->host;
|
||||||
$c->res->headers->header(
|
$c->res->headers->header(
|
||||||
|
@ -80,10 +84,11 @@ get '/f/:dir/:name' => sub ($c) {
|
||||||
my $filerender = Mojolicious::Plugin::RenderFile->new;
|
my $filerender = Mojolicious::Plugin::RenderFile->new;
|
||||||
my $ext = $captures;
|
my $ext = $captures;
|
||||||
$ext =~ s/.*\.//;
|
$ext =~ s/.*\.//;
|
||||||
$c->render_file( filepath => $captures,
|
carp "sakisafe warning: could not get file: $ERRNO" unless
|
||||||
format => $ext,
|
$c->render_file( filepath => $captures,
|
||||||
content_disposition => 'inline'
|
format => $ext,
|
||||||
);
|
content_disposition => 'inline'
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
app->max_request_size( 1024 * 1024 * 100 );
|
app->max_request_size( 1024 * 1024 * 100 );
|
||||||
|
@ -92,6 +97,11 @@ post '/upload' => sub ($c) { handle_file($c) };
|
||||||
|
|
||||||
app->start;
|
app->start;
|
||||||
|
|
||||||
|
# Index template
|
||||||
|
|
||||||
|
#By default Mojolicious gets the "directory root" from the "public"
|
||||||
|
# directory, so the css and the favicon from the "public" directory,
|
||||||
|
# in the root of this repo.
|
||||||
__DATA__
|
__DATA__
|
||||||
|
|
||||||
@@ index.html.ep
|
@@ index.html.ep
|
||||||
|
|
Loading…
Add table
Reference in a new issue