|
|
@ -5,7 +5,6 @@ use warnings; |
|
|
|
use utf8; |
|
|
|
use utf8; |
|
|
|
|
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious::Controller'; |
|
|
|
use Mojo::Base 'Mojolicious::Controller'; |
|
|
|
use JSON qw(encode_json decode_json); |
|
|
|
|
|
|
|
use Mojo::Asset::File; |
|
|
|
use Mojo::Asset::File; |
|
|
|
use Imager; |
|
|
|
use Imager; |
|
|
|
|
|
|
|
|
|
|
@ -45,7 +44,7 @@ sub view { |
|
|
|
eval { |
|
|
|
eval { |
|
|
|
my $path = $self->_data_path($time); |
|
|
|
my $path = $self->_data_path($time); |
|
|
|
my $data = Mojo::Asset::File->new(path => $path); |
|
|
|
my $data = Mojo::Asset::File->new(path => $path); |
|
|
|
my $json = decode_json($data->slurp); |
|
|
|
my $json = $self->app->json->decode($data->slurp); |
|
|
|
die("image expired\n") if (time() > $json->{expire}); |
|
|
|
die("image expired\n") if (time() > $json->{expire}); |
|
|
|
$json->{path} = $self->_image_path($time, $json->{format}); |
|
|
|
$json->{path} = $self->_image_path($time, $json->{format}); |
|
|
|
|
|
|
|
|
|
|
@ -106,7 +105,7 @@ sub save { |
|
|
|
$upload->move_to($self->_image_path($time, $json->{format}, 'fullpath')); |
|
|
|
$upload->move_to($self->_image_path($time, $json->{format}, 'fullpath')); |
|
|
|
|
|
|
|
|
|
|
|
my $data = Mojo::Asset::File->new(path => $self->_data_path($time)); |
|
|
|
my $data = Mojo::Asset::File->new(path => $self->_data_path($time)); |
|
|
|
$data->add_chunk(encode_json($json)); |
|
|
|
$data->add_chunk($self->app->json->encode($json)); |
|
|
|
$data->move_to($self->_data_path($time)); |
|
|
|
$data->move_to($self->_data_path($time)); |
|
|
|
|
|
|
|
|
|
|
|
$self->redirect_to("/imgbin/$time"); |
|
|
|
$self->redirect_to("/imgbin/$time"); |
|
|
@ -134,7 +133,7 @@ sub latest { |
|
|
|
@items = sort { $b <=> $a } @items; |
|
|
|
@items = sort { $b <=> $a } @items; |
|
|
|
foreach my $time (splice(@items, 0, 10)) { |
|
|
|
foreach my $time (splice(@items, 0, 10)) { |
|
|
|
my $data = Mojo::Asset::File->new(path => $self->_data_path($time)); |
|
|
|
my $data = Mojo::Asset::File->new(path => $self->_data_path($time)); |
|
|
|
my $image = decode_json($data->slurp); |
|
|
|
my $image = $self->app->json->decode($data->slurp); |
|
|
|
$image->{path} = $self->_thumb_path($time); |
|
|
|
$image->{path} = $self->_thumb_path($time); |
|
|
|
$image->{url} = sprintf '/imgbin/%d', $time; |
|
|
|
$image->{url} = sprintf '/imgbin/%d', $time; |
|
|
|
push @images, $image; |
|
|
|
push @images, $image; |
|
|
@ -162,7 +161,7 @@ sub prune { |
|
|
|
my $now = time(); |
|
|
|
my $now = time(); |
|
|
|
foreach my $time (@times) { |
|
|
|
foreach my $time (@times) { |
|
|
|
my $data = Mojo::Asset::File->new(path => $self->_data_path($time)); |
|
|
|
my $data = Mojo::Asset::File->new(path => $self->_data_path($time)); |
|
|
|
my $image = decode_json($data->slurp); |
|
|
|
my $image = $self->app->json->decode($data->slurp); |
|
|
|
next if $image->{expire} > $now; |
|
|
|
next if $image->{expire} > $now; |
|
|
|
unlink $self->_image_path($time, $image->{format}, 1); |
|
|
|
unlink $self->_image_path($time, $image->{format}, 1); |
|
|
|
unlink $self->_thumb_path($time); |
|
|
|
unlink $self->_thumb_path($time); |
|
|
|