diff options
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/ajax/download.php | 11 | ||||
-rw-r--r-- | apps/files/js/fileactions.js | 29 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 31 |
3 files changed, 59 insertions, 12 deletions
diff --git a/apps/files/ajax/download.php b/apps/files/ajax/download.php index e67635ab853..26bab8837b4 100644 --- a/apps/files/ajax/download.php +++ b/apps/files/ajax/download.php @@ -39,4 +39,15 @@ if (!is_array($files_list)) { $files_list = array($files); } +/** + * this sets a cookie to be able to recognize the start of the download + * the content must not be longer than 32 characters and must only contain + * alphanumeric characters + */ +if(isset($_GET['downloadStartSecret']) + && !isset($_GET['downloadStartSecret'][32]) + && preg_match('!^[a-zA-Z0-9]+$!', $_GET['downloadStartSecret']) === 1) { + setcookie('ocDownloadStarted', $_GET['downloadStartSecret'], time() + 20, '/'); +} + OC_Files::get($dir, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD'); diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index bf529aeb3e8..6678c2d5b34 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -491,14 +491,31 @@ var sourceImage = icon.attr('src'); icon.attr('src', sourceImage.replace('actions/download.svg', 'loading-small.gif')); - // TODO proper detection of "download has started" - setTimeout(function(){ - icon.attr('src', sourceImage); - downloadFileaction.removeClass('disabled'); - }, 2000); + var randomString = Math.random().toString(36).substring(2); + + var isCookieSet = function(name, value) { + var cookies = document.cookie.split(';'); + for (var i=0; i < cookies.length; i++) { + var cookie = cookies[i].split('='); + if (cookie[0].trim() === name && cookie[1].trim() === value) { + return true; + } + } + return false; + }; + + var checkForDownloadCookie = function() { + if (!isCookieSet('ocDownloadStarted', randomString)){ + setTimeout(checkForDownloadCookie, 500); + } else { + icon.attr('src', sourceImage); + downloadFileaction.removeClass('disabled'); + } + }; if (url) { - OC.redirect(url); + OC.redirect(url + '&downloadStartSecret=' + randomString); + checkForDownloadCookie(); } }, t('files', 'Download')); } diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 60fcd865880..86c6e225115 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -431,13 +431,32 @@ var sourceImage = icon.attr('src'); icon.attr('src', sourceImage.replace('actions/download.svg', 'loading-small.gif')); - // TODO proper detection of "download has started" - setTimeout(function(){ - icon.attr('src', sourceImage); - downloadFileaction.removeClass('disabled'); - }, 2000); + var randomString = Math.random().toString(36).substring(2); + + var isCookieSet = function(name, value) { + var cookies = document.cookie.split(';'); + for (var i=0; i < cookies.length; i++) { + var cookie = cookies[i].split('='); + if (cookie[0].trim() === name && cookie[1].trim() === value) { + return true; + } + } + return false; + }; + + var checkForDownloadCookie = function() { + console.log('check'); + if (!isCookieSet('ocDownloadStarted', randomString)){ + setTimeout(checkForDownloadCookie, 500); + } else { + console.log('boom'); + icon.attr('src', sourceImage); + downloadFileaction.removeClass('disabled'); + } + }; - OC.redirect(this.getDownloadUrl(files, dir)); + OC.redirect(this.getDownloadUrl(files, dir) + '&downloadStartSecret=' + randomString); + checkForDownloadCookie(); return false; }, |