|
|
|
@ -152,7 +152,27 @@ sub latest {
|
|
|
|
|
sub prune { |
|
|
|
|
my ($self) = @_; |
|
|
|
|
|
|
|
|
|
die("unimplemented\n"); |
|
|
|
|
eval { |
|
|
|
|
my $root = $self->app->config->{imgbin}->{root}; |
|
|
|
|
opendir(my $DH, $root) |
|
|
|
|
or die("opendir: $!\n"); |
|
|
|
|
my @files = grep { m/\d+\.json/oi } readdir($DH); |
|
|
|
|
my @times = map { s/\.json//oi } @items; |
|
|
|
|
closedir($DH); |
|
|
|
|
|
|
|
|
|
my $now = time(); |
|
|
|
|
foreach my $time (@times) { |
|
|
|
|
my $data = Mojo::Asset::File->new(path => $self->_data_path($time)); |
|
|
|
|
my $image = decode_json($data->slurp); |
|
|
|
|
next if $image->{expire} > $now; |
|
|
|
|
unlink $self->_image_path($time, $image->{format}, 1); |
|
|
|
|
unlink $self->_thumb_path($time); |
|
|
|
|
} 1; |
|
|
|
|
} or do { |
|
|
|
|
$self->flash(error => $@); |
|
|
|
|
}; |
|
|
|
|
$self->redirect_to('/imgbin'); |
|
|
|
|
$self->rendered(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
1; |
|
|
|
|