Browse Source

* use JSON instead Mojo::JSON

master
Alex 'AdUser' Z 10 years ago
parent
commit
121adf1b89
  1. 9
      lib/LDV/Zerobin.pm

9
lib/LDV/Zerobin.pm

@ -4,9 +4,9 @@ use strict;
use warnings;
use utf8;
use JSON qw(encode_json decode_json);
use POSIX qw(strftime);
use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON;
use Mojo::Asset::File;
use Mojo::Util qw(b64_encode b64_decode decode encode);
@ -40,7 +40,7 @@ sub view
my $path = $self->_paste_path($time);
die("paste not found\n") unless (-f $path);
my $asset = Mojo::Asset::File->new(path => $path);
my $json = Mojo::JSON->new->decode($asset->slurp());
my $json = decode_json($asset->slurp());
$json->{data} = decode('UTF-8', b64_decode($json->{data}));
if (time() > $json->{expire}) {
unlink($path);
@ -78,7 +78,7 @@ sub save
data => b64_encode(encode('UTF-8', $paste)),
};
my $asset = Mojo::Asset::File->new;
$asset->add_chunk(Mojo::JSON->new->encode($json));
$asset->add_chunk(encode_json($json));
$asset->move_to($self->_paste_path($time));
$self->redirect_to("/zerobin2/$time"); 1;
} or do {
@ -101,13 +101,12 @@ sub prune
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 $time = $1;
my $path = $self->app->home->rel_file("$storage/$file");
my $asset = Mojo::Asset::File->new(path => $path);
my $data = $json->decode($asset->slurp);
my $data = decode_json($asset->slurp);
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)");

Loading…
Cancel
Save