From d5397d813cd731b5bf8ac4b7c193ac39d704af6e Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 13 Feb 2014 20:20:00 +0100 Subject: [PATCH] Do not send file list for select all on Download/delete - When all files are selected, do not send the whole file list - Download will trigger download for the parent folder, also works with root - Delete will send "allfiles" to the server that will find the file list or the passed directory by itself --- apps/files/ajax/delete.php | 15 +++++- apps/files/js/filelist.js | 74 +++++++++++++++++++------- apps/files/js/files.js | 23 ++++---- apps/files/tests/js/fileactionsSpec.js | 2 +- apps/files/tests/js/filelistSpec.js | 13 +++-- apps/files_sharing/js/public.js | 30 +++++++++-- lib/private/files.php | 9 +++- 7 files changed, 126 insertions(+), 40 deletions(-) diff --git a/apps/files/ajax/delete.php b/apps/files/ajax/delete.php index c69f5a8860..69f859daa9 100644 --- a/apps/files/ajax/delete.php +++ b/apps/files/ajax/delete.php @@ -9,8 +9,21 @@ OCP\JSON::callCheck(); // Get data $dir = stripslashes($_POST["dir"]); $files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"]; +$allFiles = isset($_POST["allfiles"]) ? $_POST["allfiles"] : $_POST["allfiles"]; +if ($allFiles === 'true') { + $allFiles = true; +} -$files = json_decode($files); +// delete all files in dir ? +if ($allFiles) { + $files = array(); + $fileList = \OC\Files\Filesystem::getDirectoryContent($dir); + foreach ($fileList as $fileInfo) { + $files[] = $fileInfo['name']; + } +} else { + $files = json_decode($files); +} $filesWithError = ''; $success = true; diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index a855d6cbe5..d6cffde05d 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -582,30 +582,49 @@ window.FileList={ }}); } }, - do_delete:function(files) { - if (files.substr) { + do_delete:function(files, dir) { + var params; + if (files && files.substr) { files=[files]; } - for (var i=0; i 0) { - return $(tr).find('a.name').attr('href') + '&download'; + if ($.isArray(filename)) { + filename = JSON.stringify(filename); } - return null; + var path = dir || FileList.getCurrentDirectory(); + var params = { + service: 'files', + t: $('#sharingToken').val(), + path: path, + download: null + }; + if (filename) { + params.files = filename; + } + return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); }; } diff --git a/lib/private/files.php b/lib/private/files.php index 24fca4a5df..5bbc2e960d 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -103,7 +103,12 @@ class OC_Files { if ($xsendfile) { $filename = OC_Helper::moveToNoClean($filename); } - $name = $files . '.zip'; + // downloading root ? + if ($files === '') { + $name = 'download.zip'; + } else { + $name = $files . '.zip'; + } set_time_limit($executionTime); } else { $zip = false; @@ -198,6 +203,8 @@ class OC_Files { $dirname=basename($dir); $zip->addEmptyDir($internalDir.$dirname); $internalDir.=$dirname.='/'; + // prevent absolute dirs + $internalDir = ltrim($internalDir, '/'); $files=OC_Files::getDirectoryContent($dir); foreach($files as $file) { $filename=$file['name'];