Browse Source

* LDV::Imgbin : implement 'prune'

master
Alex 'AdUser' Z 10 years ago
parent
commit
ad2ed95cba
  1. 2
      lib/LDV.pm
  2. 22
      lib/LDV/Imgbin.pm

2
lib/LDV.pm

@ -61,7 +61,7 @@ sub startup {
$ib->get ('/') -> to(action => 'create');
$ib->route('/:time', time => qr/\d+/)
->via('GET') -> to(action => 'view');
#$ib->get('/prune') -> to(action => 'prune');
$ib->get ('/prune') -> to(action => 'prune');
$ib->get ('/latest') -> to(action => 'latest')
if ($conf->{show_latest});

22
lib/LDV/Imgbin.pm

@ -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;

Loading…
Cancel
Save