X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/0d67e0ca4e449915d0548819f1f09a29dae52c9a..7736957442e464ad66415e458330b9da6c47ae23:/lib/functions_v7.js diff --git a/lib/functions_v7.js b/lib/functions_v7.js index 00b7df0..cb0ff73 100644 --- a/lib/functions_v7.js +++ b/lib/functions_v7.js @@ -1,6 +1,7 @@ /* * Jirafeau, your web file repository * Copyright (C) 2015 Jerome Jutteau + * Copyright (C) 2015 Nicola Spanti (RyDroid) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -13,7 +14,7 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ function show_link (url, reference, delete_code, crypt_key, date) @@ -125,7 +126,7 @@ function hide_upload_progression () function upload_progress (e) { - if (!e.lengthComputable) + if (e == undefined || e == null || !e.lengthComputable) return; // Init time estimation if needed @@ -181,6 +182,46 @@ function pop_failure (e) document.getElementById('send').style.display = ''; } +function add_time_string_to_date(d, time_string) +{ + if(typeof(d) != 'object' || !(d instanceof Date)) + { + return false; + } + + if (time == 'minute') + { + d.setSeconds (d.getSeconds() + 60); + return true; + } + if (time == 'hour') + { + d.setSeconds (d.getSeconds() + 3600); + return true; + } + if (time == 'day') + { + d.setSeconds (d.getSeconds() + 86400); + return true; + } + if (time == 'week') + { + d.setSeconds (d.getSeconds() + 604800); + return true; + } + if (time == 'month') + { + d.setSeconds (d.getSeconds() + 2419200); + return true; + } + if (time == 'year') + { + d.setSeconds (d.getSeconds() + 29030400); + return true; + } + return false; +} + function classic_upload (url, file, time, password, one_time, upload_password) { // Delay time estimation init as we can't have file size @@ -204,20 +245,10 @@ function classic_upload (url, file, time, password, one_time, upload_password) if (time != 'none') { var d = new Date(); - if (time == 'minute') - d.setSeconds (d.getSeconds() + 60); - else if (time == 'hour') - d.setSeconds (d.getSeconds() + 3600); - else if (time == 'day') - d.setSeconds (d.getSeconds() + 86400); - else if (time == 'week') - d.setSeconds (d.getSeconds() + 604800); - else if (time == 'month') - d.setSeconds (d.getSeconds() + 2419200); - else if (time == 'year') - d.setSeconds (d.getSeconds() + 29030400); - else + if(!add_time_string_to_date(d)) + { return; + } show_link (url, res[0], res[1], res[2], d.toString()); } else @@ -242,9 +273,7 @@ function classic_upload (url, file, time, password, one_time, upload_password) function check_html5_file_api () { - if (window.File && window.FileReader && window.FileList && window.Blob) - return true; - return false; + return window.File && window.FileReader && window.FileList && window.Blob; } var async_global_transfered = 0; @@ -304,7 +333,7 @@ function async_upload_start (url, max_size, file, time, password, one_time, uplo function async_upload_progress (e) { - if (!e.lengthComputable && async_global_file.size != 0) + if (e == undefined || e == null || !e.lengthComputable && async_global_file.size != 0) return; // Compute percentage @@ -387,19 +416,7 @@ function async_upload_end (code) if (async_global_time != 'none') { var d = new Date(); - if (async_global_time == 'minute') - d.setSeconds (d.getSeconds() + 60); - else if (async_global_time == 'hour') - d.setSeconds (d.getSeconds() + 3600); - else if (async_global_time == 'day') - d.setSeconds (d.getSeconds() + 86400); - else if (async_global_time == 'week') - d.setSeconds (d.getSeconds() + 604800); - else if (async_global_time == 'month') - d.setSeconds (d.getSeconds() + 2419200); - else if (async_global_time == 'year') - d.setSeconds (d.getSeconds() + 29030400); - else + if(!add_time_string_to_date(d)) return; show_link (async_global_url, res[0], res[1], res[2], d.toString()); } @@ -494,8 +511,7 @@ function upload_time_estimation_speed_string() } if (res == 0) return ''; - else - return res.toString() + ' ' + scale; + return res.toString() + ' ' + scale; } function milliseconds_to_time_string (milliseconds)