Browse Source

+ LDV::Zerobin->prune

master
Alex 'AdUser' Z 10 years ago committed by Alex 'AdUser' Z
parent
commit
ed8c6f27a0
  1. 1
      lib/LDV.pm
  2. 16
      lib/LDV/Zerobin.pm

1
lib/LDV.pm

@ -48,6 +48,7 @@ sub startup {
$zb->get ('/') -> to(action => 'create');
$zb->route('/:time', time => qr/\d+/)
->via('GET') -> to(action => 'view');
$zb->get('/prune') -> to(action => 'prune');
my $root = $self->app->config->{zerobin}->{root};
mkdir $self->app->home->rel_dir($root);

16
lib/LDV/Zerobin.pm

@ -4,6 +4,7 @@ use strict;
use warnings;
use utf8;
use POSIX qw(strftime);
use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON;
use Mojo::Asset::File;
@ -97,7 +98,20 @@ sub prune
my ($self) = @_;
eval {
die("not implemented\n"); 1;
my $time = time();
my $storage = $self->app->config->{zerobin}->{root};
my $files = $self->app->home->list_files($storage);
my $json = Mojo::JSON->new;
foreach my $file (@$files) {
next unless $file =~ m/^(\d+)\.json$/oi;
my $paste_time = $1;
my $path = "$storage/$file";
my $data = $json->decode($self->app->home->slurp_rel_file("$storage/$file"));
next if ($data->{expire} > $time); # not yet
my $date = strftime("%Y-%m-%d %H:%M", localtime($data->{expire}));
$self->app->log->info("Removing expired paste: $file ($date)");
unlink $self->_paste_path($paste_time);
} 1;
} or do {
chomp $@;
$self->app->log->error($@);

Loading…
Cancel
Save