From d5397d813cd731b5bf8ac4b7c193ac39d704af6e Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 13 Feb 2014 20:20:00 +0100 Subject: [PATCH 1/2] 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 c69f5a8860c..69f859daa97 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 a855d6cbe59..d6cffde05de 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); + } + var path = dir || FileList.getCurrentDirectory(); + var params = { + service: 'files', + t: $('#sharingToken').val(), + path: path, + download: null + }; + if (filename) { + params.files = filename; } - return null; + return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); }; } diff --git a/lib/private/files.php b/lib/private/files.php index 24fca4a5df3..5bbc2e960d7 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']; From 94b3296a71c5950f70919836bc12f0066016b705 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 17 Feb 2014 18:26:29 +0100 Subject: [PATCH 2/2] Trashbin select all now doesn't send file list - Fixed "delete" and "restore" actions to not send the file list when all files are selected - When some files are selected, sends the current dir - Removed "dirListing" attribute as the backend is able to compute the value based on the current dir --- apps/files_trashbin/ajax/delete.php | 16 ++- apps/files_trashbin/ajax/undelete.php | 31 +++++- apps/files_trashbin/js/trash.js | 141 ++++++++++++++------------ 3 files changed, 109 insertions(+), 79 deletions(-) diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index 75d481768ad..ebabc5bc7a2 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -2,42 +2,38 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); +$folder = isset($_POST['dir']) ? $_POST['dir'] : '/'; // "empty trash" command if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true'){ $deleteAll = true; - $folder = isset($_POST['dir']) ? $_POST['dir'] : '/'; if ($folder === '/' || $folder === '') { OCA\Files_Trashbin\Trashbin::deleteAll(); $list = array(); } else { - $dirname = dirname($folder); - if ( $dirname !== '/' && $dirname !== '.' ) { - $dirlisting = '1'; - } else { - $dirlisting = '0'; - } $list[] = $folder; + $folder = dirname($folder); } } else { $deleteAll = false; $files = $_POST['files']; - $dirlisting = $_POST['dirlisting']; $list = json_decode($files); } + +$folder = rtrim($folder, '/') . '/'; $error = array(); $success = array(); $i = 0; foreach ($list as $file) { - if ( $dirlisting === '0') { + if ($folder === '/') { $file = ltrim($file, '/'); $delimiter = strrpos($file, '.d'); $filename = substr($file, 0, $delimiter); $timestamp = substr($file, $delimiter+2); } else { - $filename = $file; + $filename = $folder . '/' . $file; $timestamp = null; } diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index 876ad269a70..9c3ccba7ed8 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -4,15 +4,36 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); $files = $_POST['files']; -$dirlisting = $_POST['dirlisting']; -$list = json_decode($files); +$dir = '/'; +if (isset($_POST['dir'])) { + $dir = rtrim($_POST['dir'], '/'). '/'; +} +$allFiles = false; +if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true') { + $allFiles = true; + $list = array(); + $dirListing = true; + if ($dir === '' || $dir === '/') { + $dirListing = false; + } + foreach (OCA\Files_Trashbin\Helper::getTrashFiles($dir) as $file) { + $fileName = $file['name']; + if (!$dirListing) { + $fileName .= '.d' . $file['timestamp']; + } + $list[] = $fileName; + } +} else { + $list = json_decode($files); +} $error = array(); $success = array(); $i = 0; foreach ($list as $file) { - if ( $dirlisting === '0') { + $path = $dir . '/' . $file; + if ($dir === '/') { $file = ltrim($file, '/'); $delimiter = strrpos($file, '.d'); $filename = substr($file, 0, $delimiter); @@ -23,9 +44,9 @@ foreach ($list as $file) { $timestamp = null; } - if ( !OCA\Files_Trashbin\Trashbin::restore($file, $filename, $timestamp) ) { + if ( !OCA\Files_Trashbin\Trashbin::restore($path, $filename, $timestamp) ) { $error[] = $filename; - OC_Log::write('trashbin','can\'t restore ' . $filename, OC_Log::ERROR); + OC_Log::write('trashbin', 'can\'t restore ' . $filename, OC_Log::ERROR); } else { $success[$i]['filename'] = $file; $success[$i]['timestamp'] = $timestamp; diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 46d8b56308c..6aade210505 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -1,5 +1,29 @@ +/* + * Copyright (c) 2014 + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ + +/* global OC, t, FileList, FileActions */ $(document).ready(function() { + function removeCallback(result) { + if (result.status !== 'success') { + OC.dialogs.alert(result.data.message, t('core', 'Error')); + } + + var files = result.data.success; + for (var i = 0; i < files.length; i++) { + FileList.findFileEl(OC.basename(files[i].filename)).remove(); + } + FileList.updateFileSummary(); + FileList.updateEmptyContent(); + enableActions(); + } if (typeof FileActions !== 'undefined') { FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename) { @@ -7,22 +31,12 @@ $(document).ready(function() { var deleteAction = tr.children("td.date").children(".action.delete"); deleteAction.removeClass('delete-icon').addClass('progress-icon'); disableActions(); - $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), - {files: JSON.stringify([$('#dir').val() + '/' + filename]), dirlisting: tr.attr('data-dirlisting')}, - function(result) { - for (var i = 0; i < result.data.success.length; i++) { - var row = document.getElementById(result.data.success[i].filename); - row.parentNode.removeChild(row); - } - if (result.status !== 'success') { - OC.dialogs.alert(result.data.message, t('core', 'Error')); - } - enableActions(); - FileList.updateFileSummary(); - FileList.updateEmptyContent(); - } + $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), { + files: JSON.stringify([filename]), + dir: FileList.getCurrentDirectory() + }, + removeCallback ); - }); }; @@ -34,22 +48,12 @@ $(document).ready(function() { var deleteAction = tr.children("td.date").children(".action.delete"); deleteAction.removeClass('delete-icon').addClass('progress-icon'); disableActions(); - $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), - {files: JSON.stringify([$('#dir').val() + '/' +filename]), dirlisting: tr.attr('data-dirlisting')}, - function(result) { - for (var i = 0; i < result.data.success.length; i++) { - var row = document.getElementById(result.data.success[i].filename); - row.parentNode.removeChild(row); - } - if (result.status !== 'success') { - OC.dialogs.alert(result.data.message, t('core', 'Error')); - } - enableActions(); - FileList.updateFileSummary(); - FileList.updateEmptyContent(); - } + $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), { + files: JSON.stringify([filename]), + dir: FileList.getCurrentDirectory() + }, + removeCallback ); - }); // Sets the select_all checkbox behaviour : @@ -68,29 +72,45 @@ $(document).ready(function() { $('.undelete').click('click', function(event) { event.preventDefault(); - var files = getSelectedFiles('file'); - var fileslist = JSON.stringify(files); - var dirlisting = getSelectedFiles('dirlisting')[0]; + var allFiles = $('#select_all').is(':checked'); + var files = []; + var params = {}; disableActions(); - for (var i = 0; i < files.length; i++) { - var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete"); - deleteAction.removeClass('delete-icon').addClass('progress-icon'); + if (allFiles) { + FileList.showMask(); + params = { + allfiles: true, + dir: FileList.getCurrentDirectory() + }; + } + else { + files = getSelectedFiles('name'); + for (var i = 0; i < files.length; i++) { + var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete"); + deleteAction.removeClass('delete-icon').addClass('progress-icon'); + } + params = { + files: JSON.stringify(files), + dir: FileList.getCurrentDirectory() + }; } $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), - {files: fileslist, dirlisting: dirlisting}, - function(result) { - for (var i = 0; i < result.data.success.length; i++) { - var row = document.getElementById(result.data.success[i].filename); - row.parentNode.removeChild(row); - } + params, + function(result) { + if (allFiles) { if (result.status !== 'success') { OC.dialogs.alert(result.data.message, t('core', 'Error')); } + FileList.hideMask(); + // simply remove all files + FileList.update(''); enableActions(); - FileList.updateFileSummary(); - FileList.updateEmptyContent(); } + else { + removeCallback(result); + } + } ); }); @@ -101,17 +121,17 @@ $(document).ready(function() { var params = {}; if (allFiles) { params = { - allfiles: true, - dir: $('#dir').val() + allfiles: true, + dir: FileList.getCurrentDirectory() }; } else { - files = getSelectedFiles('file'); + files = getSelectedFiles('name'); params = { files: JSON.stringify(files), - dirlisting: getSelectedFiles('dirlisting')[0] + dir: FileList.getCurrentDirectory() }; - }; + } disableActions(); if (allFiles) { @@ -128,22 +148,17 @@ $(document).ready(function() { params, function(result) { if (allFiles) { + if (result.status !== 'success') { + OC.dialogs.alert(result.data.message, t('core', 'Error')); + } FileList.hideMask(); // simply remove all files - $('#fileList').empty(); + FileList.update(''); + enableActions(); } else { - for (var i = 0; i < result.data.success.length; i++) { - var row = document.getElementById(result.data.success[i].filename); - row.parentNode.removeChild(row); - } + removeCallback(result); } - if (result.status !== 'success') { - OC.dialogs.alert(result.data.message, t('core', 'Error')); - } - enableActions(); - FileList.updateFileSummary(); - FileList.updateEmptyContent(); } ); @@ -208,11 +223,9 @@ function getSelectedFiles(property){ var files=[]; elements.each(function(i,element){ var file={ - name:$(element).attr('data-filename'), - file:$('#dir').val() + "/" + $(element).attr('data-file'), + name:$(element).attr('data-file'), timestamp:$(element).attr('data-timestamp'), - type:$(element).attr('data-type'), - dirlisting:$(element).attr('data-dirlisting') + type:$(element).attr('data-type') }; if(property){ files.push(file[property]);