From 841e8c4436be3a1be9e577d85937efc7af946c8f Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Sun, 4 Oct 2015 01:49:57 +0200 Subject: [PATCH] Use helper for max_delay --- lib/Lufi.pm | 12 ++++++++++++ lib/Lufi/Controller/Files.pm | 2 +- templates/delays.html.ep | 2 +- templates/index.html.ep | 8 ++++---- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/Lufi.pm b/lib/Lufi.pm index ae158bf..e64e469 100644 --- a/lib/Lufi.pm +++ b/lib/Lufi.pm @@ -114,11 +114,23 @@ sub startup { } ); + $self->helper( + max_delay => sub { + my $c = shift; + + return $c->config('max_delay') if ($c->config('max_delay') >= 0); + + warn "max_delay set to a negative value. Default to 0."; + return 0; + } + ); + $self->helper( is_selected => sub { my $c = shift; my $num = shift; + return ($num == $c->max_delay) ? 'selected="selected"' : '' if ($c->max_delay && !$c->default_delay); return ($num == $c->default_delay) ? 'selected="selected"' : ''; } ); diff --git a/lib/Lufi/Controller/Files.pm b/lib/Lufi/Controller/Files.pm index 52f8d09..a0562f6 100644 --- a/lib/Lufi/Controller/Files.pm +++ b/lib/Lufi/Controller/Files.pm @@ -54,7 +54,7 @@ sub upload { } # If the file size is lower than the lowest configured size or if there is no delay_for_size setting, we choose the configured max delay unless (defined $delay) { - $delay = ($json->{delay} <= $c->config('max_delay') || $c->config('max_delay') == 0) ? $json->{delay} : $c->config('max_delay'); + $delay = ($json->{delay} <= $c->max_delay || $c->max_delay == 0) ? $json->{delay} : $c->max_delay; } $f = Lufi::File->new( diff --git a/templates/delays.html.ep b/templates/delays.html.ep index bab31ed..0afefd7 100644 --- a/templates/delays.html.ep +++ b/templates/delays.html.ep @@ -9,7 +9,7 @@

<%= l('This server sets limitations according to the file size. The expiration delay of your file will be the minimum between what you choose and the following limitations:') %>