From 37feb11430af0ebe8234fee0c2fda046d610b59c Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Mon, 24 Feb 2014 21:57:50 +0100 Subject: [PATCH] Fix #8 --- README.md | 3 ++- lib/Lutim.pm | 38 ++++++++++++++++++++++++++++++++++---- lib/Lutim/I18N/en.pm | 1 + lib/Lutim/I18N/fr.pm | 1 + lutim.conf.template | 1 + templates/index.html.ep | 5 +++++ 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 60c7fac..c841a7a 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ vi lutim.conf * keep\_ip\_during: when you delete IP addresses of image's senders with `script/lutim cron cleanbdd`, the IP addresses of images older than `keep_ip_during` days will be deleted (default is 365) ; * broadcast\_message: put some string (not HTML) here and this message will be displayed on all LUTIm pages (not in JSON responses) ; * allowed\_domains: array of authorized domains for API calls. Example: `['http://1.example.com', 'http://2.example.com']`. If you want to authorize everyone to use the API: `['*']` ; -* default\_delay: what is the default time limit for files? Valid values are 0, 1, 7, 30 and 365. +* default\_delay: what is the default time limit for files? Valid values are 0, 1, 7, 30 and 365 ; +* max\_delay: if defined, the images will be deleted after that delay (in days), even if they were uploaded with "no delay" (or value superior to max\_delay) option and a warning message will be displayed on homepage. ##Usage ``` diff --git a/lib/Lutim.pm b/lib/Lutim.pm index fa759ea..571d36a 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -126,14 +126,44 @@ sub startup { } ); + $self->helper( + max_delay => sub { + my $c = shift; + + if (defined($c->config->{max_delay})) { + my $delay = $c->config->{max_delay}; + if ($delay >= 0) { + return $delay; + } else { + warn "max_delay set to a negative value. Default to 0." + } + } + return 0; + } + ); + + $self->helper( + default_delay => sub { + my $c = shift; + + if (defined($c->config->{default_delay})) { + my $delay = $c->config->{default_delay}; + if ($delay >= 0) { + return $delay; + } else { + warn "default_delay set to a negative value. Default to 0." + } + } + return 0; + } + ); + $self->helper( is_selected => sub { my $c = shift; my $num = shift; - $c->config->{default_delay} = 0 unless (defined($c->config->{default_delay})); - - return ($num == $c->config->{default_delay}) ? 'selected="selected"' : ''; + return ($num == $c->default_delay) ? 'selected="selected"' : ''; } ); @@ -306,7 +336,7 @@ sub startup { mediatype => $mediatype, footprint => digest_file_hex($path, 'SHA-512'), enabled => 1, - delete_at_day => ($c->param('delete-day')) ? $c->param('delete-day') : 0, + delete_at_day => ($c->param('delete-day')) ? $c->param('delete-day') : $c->max_delay, delete_at_first_view => ($c->param('first-view')) ? 1 : 0, created_at => time(), created_by => $ip diff --git a/lib/Lutim/I18N/en.pm b/lib/Lutim/I18N/en.pm index 8c4fa25..8589124 100644 --- a/lib/Lutim/I18N/en.pm +++ b/lib/Lutim/I18N/en.pm @@ -64,6 +64,7 @@ our %Lexicon = ( 'delay_7' => '7 days', 'delay_30' => '30 days', 'delay_365' => '1 year', + 'max_delay' => 'Warning! The maximum time limit for an image is [_1] day(s), even if you choose "no time limit".', ); 1; diff --git a/lib/Lutim/I18N/fr.pm b/lib/Lutim/I18N/fr.pm index 0a312dd..8bb1a32 100644 --- a/lib/Lutim/I18N/fr.pm +++ b/lib/Lutim/I18N/fr.pm @@ -64,6 +64,7 @@ our %Lexicon = ( 'delay_7' => '7 jours', 'delay_30' => '30 jours', 'delay_365' => '1 an', + 'max_delay' => 'Attention ! Le délai maximal de rétention d\'une image est de [_1] jour(s), même si vous choisissez « pas de limitation de durée ».', ); 1; diff --git a/lutim.conf.template b/lutim.conf.template index 7fa180f..ad79c73 100644 --- a/lutim.conf.template +++ b/lutim.conf.template @@ -23,4 +23,5 @@ #broadcast_message => 'Maintenance', #optional, the broadcast_message is displayed on all pages of LUTIm (but no in json response) #allowed_domains => ['http://1.example.com', 'http://2.example.com'], #optional, array of authorized domains for API calls. If you want to authorize everyone to use the API: ['*'] #default_delay => 0, #optional: what is the default time limit for files? Valid values are 0, 1, 7, 30 and 365. + #max_delay => 0, #optional, if defined, the images will be deleted after that delay (in days), even if they were uploaded with "no delay" (or value superior to max\_delay) option and a warning message will be displayed on homepage. }; diff --git a/templates/index.html.ep b/templates/index.html.ep index cc1deb1..25d2ae4 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -1,6 +1,11 @@ % # vim:set sw=4 ts=4 sts=4 ft=html.epl expandtab: % my $scheme = (defined(config('https')) && config('https')) ? 'https' : 'http';
+% if (max_delay != 0) { +
+ <%=l('max_delay', max_delay) %> +
+% } % if (defined(flash('short'))) {