diff --git a/lib/Lufi/Controller/Files.pm b/lib/Lufi/Controller/Files.pm
index 9d0551a..360ce0c 100644
--- a/lib/Lufi/Controller/Files.pm
+++ b/lib/Lufi/Controller/Files.pm
@@ -28,11 +28,29 @@ sub upload {
my @records = LufiDB::Files->select('WHERE short = ?', $json->{id});
$f = Lufi::File->new(record => $records[0]);
} else {
+ my $delay;
+
+ if (defined $c->config('delay_for_size')) {
+ # Choose delay according to config
+ my $delays = $c->config('delay_for_size');
+ my @keys = sort {$b <=> $a} keys %{$delays};
+ for my $key (@keys) {
+ if ($json->{size} >= $key) {
+ $delay = ($json->{delay} < $delays->{$key}) ? $json->{delay} : $delays->{$key};
+ last;
+ }
+ }
+ }
+ # 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');
+ }
+
$f = Lufi::File->new(
record => $c->get_empty,
created_by => $c->ip,
delete_at_first_view => ($json->{del_at_first_view}) ? 1 : 0,
- delete_at_day => $json->{delay},
+ delete_at_day => $delay,
mediatype => $json->{type},
filename => $json->{name},
filesize => $json->{size},
diff --git a/lufi.conf.template b/lufi.conf.template
index 5d5dfb9..d1613a9 100644
--- a/lufi.conf.template
+++ b/lufi.conf.template
@@ -54,6 +54,7 @@
# size thresholds: if you want to define max delays for different sizes of file
# the keys are size in Bytes, you can't have 10*1000*10000 as key
+ # if a file is smaller than the smallest configured size, it will have a expiration delay of max_delay (see above)
# optional, default is using max_delay (see above) for all sizes
#delay_for_size => {
# 10000000 => 90, # between 10MB and 50MB => max is 90 days, less than 10MB => max is max_delay (see above)
diff --git a/public/js/lufi-up.js b/public/js/lufi-up.js
index 327e11d..428df5d 100644
--- a/public/js/lufi-up.js
+++ b/public/js/lufi-up.js
@@ -1,5 +1,7 @@
// vim:set sw=4 ts=4 sts=4 ft=javascript expandtab:
+window.fc = 0;
+// Copy a link to clipboard
function copyToClipboard(el) {
el = el.previousSibling;
var textArea = document.createElement('textarea');
@@ -31,6 +33,8 @@ function copyToClipboard(el) {
document.body.removeChild(textArea);
}
+
+// Copy all links to clipboard
function copyAllToClipboard() {
var text = new Array();
var a = document.getElementsByClassName('link-input');
@@ -67,6 +71,8 @@ function copyAllToClipboard() {
document.body.removeChild(textArea);
}
+
+// Add item to localStorage
function addItem(name, url, size, del_at_first_view, created_at, delay, short, token) {
var files = localStorage.getItem('files');
if (files === null) {
@@ -110,7 +116,7 @@ function uploadFile(i, delay, del_at_first_view) {
var r = document.getElementById('ul-results');
var w = document.createElement('li');
w.setAttribute('class', 'list-group-item');
- w.innerHTML='
';
+ w.innerHTML='';
r.appendChild(w);
sliceAndUpload(randomkey, i, parts, 0, delay, del_at_first_view, null);
@@ -167,17 +173,18 @@ function updateProgressBar(data) {
var created_at = data.created_at;
var delay = data.delay;
- var dp = document.getElementById('progress-'+i);
+ var dp = document.getElementById('progress-'+window.fc);
var key = dp.getAttribute('data-key');
if (j + 1 === parts) {
- var n = document.getElementById('name-'+i);
+ var n = document.getElementById('name-'+window.fc);
var d = document.createElement('div');
var baseURL = document.location.href.replace(/#$/, '');
var url = baseURL+'r/'+short+'#'+key;
var del_url = baseURL+'d/'+short+'/'+data.token;
var links = encodeURIComponent('["'+short+'"]');
- n.innerHTML = n.innerHTML+' ';
+ var limit = (delay === 0) ? i18n.noLimit : i18n.expiration+' '+moment.unix(delay * 86400 + created_at).locale(window.navigator.language).format('LLLL');
+ n.innerHTML = n.innerHTML+'
'+limit;
d.innerHTML = '
diff --git a/templates/files.html.ep b/templates/files.html.ep
index 3ebb312..93ff69f 100644
--- a/templates/files.html.ep
+++ b/templates/files.html.ep
@@ -31,7 +31,7 @@
files.forEach(function(element, index, array) {
var del_view = (element.del_at_first_view) ? '' : '';
var dlink = '<%== url_for('/')->to_abs() %>d/'+element.short+'/'+element.token;
- var limit = (element.limit === 0) ? '<%= l('No limit') %>' : moment.unix(element.delay * 86400 + element.created_at).locale(window.navigator.language).format('LLLL');
+ var limit = (element.delay === 0) ? '<%= l('No limit') %>' : moment.unix(element.delay * 86400 + element.created_at).locale(window.navigator.language).format('LLLL');
var created_at = moment.unix(element.created_at).locale(window.navigator.language).format('LLLL');
var tr = document.createElement('tr');
diff --git a/templates/index.html.ep b/templates/index.html.ep
index 2da68f9..3b5bc2b 100644
--- a/templates/index.html.ep
+++ b/templates/index.html.ep
@@ -63,18 +63,21 @@
%= javascript begin
-var ws_url = '<%= url_for('upload')->to_abs() %>';
+var ws_url = '<%= url_for('upload')->to_abs() %>';
var i18n = {
+ confirmExit: '<%= l('You have attempted to leave this page. The upload will be canceled. Are you sure?') %>',
copyAll: '<%= l('Copy all links to clipboard') %>',
cpText: '<%= l('Copy to clipboard') %>',
delText: '<%= l('Deletion link') %>',
dlText: '<%= l('Download link') %>',
download: '<%= l('Download') %>',
- confirmExit: '<%= l('You have attempted to leave this page. The upload will be canceled. Are you sure?') %>',
+ expiration: '<%= l('Expiration:') %>',
hit: '<%= l('Hit Enter, then Ctrl+C to copy the download link') %>',
hits: '<%= l('Hit Enter, then Ctrl+C to copy all the download links') %>',
mailTo: '<%= l('Send all links by email') %>',
-}
+ noLimit: '<%= l('No limit') %>',
+};
% end
%= javascript '/js/sjcl.js'
+%= javascript '/js/moment-with-locales.min.js'
%= javascript '/js/lufi-up.js'
diff --git a/templates/mail.html.ep b/templates/mail.html.ep
index 6ee6445..36ea4d3 100644
--- a/templates/mail.html.ep
+++ b/templates/mail.html.ep
@@ -66,7 +66,7 @@
links.forEach(function(name, index, array) {
var item = findItem(name);
if (item !== null) {
- var limit = (item.limit === 0) ? null : moment.unix(item.delay * 86400 + item.created_at).locale(window.navigator.language).format('LLLL');
+ var limit = (item.delay === 0) ? null : moment.unix(item.delay * 86400 + item.created_at).locale(window.navigator.language).format('LLLL');
text = text+'- '+item.name+'<%= l(':') %> '+item.url;
if (limit !== null) {
text = text+"\n (<%= l('deadline: ') %>"+limit+')';