|
|
@ -4,6 +4,7 @@ use strict; |
|
|
|
use warnings; |
|
|
|
use warnings; |
|
|
|
use utf8; |
|
|
|
use utf8; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use POSIX qw(strftime); |
|
|
|
use Mojo::Base 'Mojolicious::Controller'; |
|
|
|
use Mojo::Base 'Mojolicious::Controller'; |
|
|
|
use Mojo::JSON; |
|
|
|
use Mojo::JSON; |
|
|
|
use Mojo::Asset::File; |
|
|
|
use Mojo::Asset::File; |
|
|
@ -97,7 +98,20 @@ sub prune |
|
|
|
my ($self) = @_; |
|
|
|
my ($self) = @_; |
|
|
|
|
|
|
|
|
|
|
|
eval { |
|
|
|
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 { |
|
|
|
} or do { |
|
|
|
chomp $@; |
|
|
|
chomp $@; |
|
|
|
$self->app->log->error($@); |
|
|
|
$self->app->log->error($@); |
|
|
|