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