diff --git a/src/_h5ai/client/js/inc/ext/download.js b/src/_h5ai/client/js/inc/ext/download.js index 4a287f8e..dfc9b42a 100644 --- a/src/_h5ai/client/js/inc/ext/download.js +++ b/src/_h5ai/client/js/inc/ext/download.js @@ -27,34 +27,6 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co }, 1000); }, - handleResponse = function (json) { - - $download.removeClass('current'); - $img.attr('src', resource.image('download')); - - if (json && json.code === 0) { - setTimeout(function () { // wait here so the img above can be updated in time - - window.location = '?action=getArchive&id=' + json.id + '&as=' + (settings.packageName || location.getItem().label) + '.' + settings.format; - }, 200); - } else { - failed(); - } - }, - - requestArchive = function (hrefsStr) { - - $download.addClass('current'); - $img.attr('src', resource.image('loading.gif', true)); - - server.request({ - action: 'createArchive', - type: settings.type, - format: settings.format, - hrefs: hrefsStr - }, handleResponse); - }, - onSelection = function (items) { selectedHrefsStr = ''; @@ -72,15 +44,19 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co onClick = function (event) { var type = settings.type, - extension = type === 'shell-zip' ? 'zip' : 'tar', - query = '?action=passArchive' + - '&as=' + encodeURIComponent((settings.packageName || location.getItem().label) + '.' + extension) + - '&type=' + type + - '&hrefs=' + encodeURIComponent(selectedHrefsStr), - $iframe = $(''); + extension = (type === 'shell-zip') ? 'zip' : 'tar', + query = { + action: 'passArchive', + as: (settings.packageName || location.getItem().label) + '.' + extension, + type: type, + hrefs: selectedHrefsStr + }, + $form = $('
'); - $iframe.appendTo('body'); - setTimeout(function () { $iframe.remove(); }, 1000); + for (var key in query) { + $form.append('') + } + $form.appendTo('body').submit().remove(); }, init = function () { diff --git a/src/_h5ai/server/php/inc/Api.php b/src/_h5ai/server/php/inc/Api.php index 5e208467..8ecabb1d 100644 --- a/src/_h5ai/server/php/inc/Api.php +++ b/src/_h5ai/server/php/inc/Api.php @@ -100,57 +100,6 @@ class Api { } - else if ($action === "createArchive") { - - json_fail(1, "downloads disabled", !$options["download"]["enabled"]); - - list($format, $hrefs) = use_request_params(array("format", "hrefs")); - - normalized_require_once("/server/php/inc/Archive.php"); - $archive = new Archive($this->app); - - $hrefs = explode("|:|", trim($hrefs)); - $target = $archive->create($format, $hrefs); - - if (!is_string($target)) { - json_fail($target, "package creation failed"); - } - - json_exit(array("id" => basename($target), "size" => filesize($target))); - } - - - else if ($action === "getArchive") { - - json_fail(1, "downloads disabled", !$options["download"]["enabled"]); - - list($id, $as) = use_request_params(array("id", "as")); - json_fail(2, "file not found", !preg_match("/^package-/", $id)); - - $target = $this->app->get_cache_abs_path() . "/" . $id; - json_fail(3, "file not found", !file_exists($target)); - - header("Content-Type: application/octet-stream"); - header("Content-Length: " . filesize($target)); - header("Content-Disposition: attachment; filename=\"$as\""); - header("Connection: close"); - register_shutdown_function("delete_tempfile", $target); - - // readfile($target); - - // Send data in small segments of 16MB to not hit PHP's memory limit (default: 128M) - if ($fd = fopen($target, 'rb')) { - set_time_limit(0); - while (!feof($fd)) { - print fread($fd, 1024 * 1024 * 16); - ob_flush(); - flush(); - } - fclose($fd); - } - } - - else if ($action === "passArchive") { json_fail(1, "downloads disabled", !$options["download"]["enabled"]); diff --git a/src/_h5ai/server/php/inc/Archive.php b/src/_h5ai/server/php/inc/Archive.php index 5d5e8890..4280fdfa 100644 --- a/src/_h5ai/server/php/inc/Archive.php +++ b/src/_h5ai/server/php/inc/Archive.php @@ -41,35 +41,6 @@ class Archive { } - // public function create($format, $hrefs) { - - // $this->dirs = array(); - // $this->files = array(); - - // $this->add_hrefs($hrefs); - - // if (count($this->dirs) === 0 && count($this->files) === 0) { - // return 404; - // } - - // $target = $this->app->get_cache_abs_path() . "/package-" . sha1(microtime(true) . rand()) . "." . $format; - - // try { - // $archive = new PharData($target); - // foreach ($this->dirs as $archived_dir) { - // $archive->addEmptyDir($archived_dir); - // } - // foreach ($this->files as $real_file => $archived_file) { - // $archive->addFile($real_file, $archived_file); // very, very slow :/ - // } - // } catch (Exeption $err) { - // return 500; - // } - - // return @filesize($target) ? $target : null; - // } - - private function shell_cmd($cmd) { $cmd = str_replace("[ROOTDIR]", "\"" . $this->app->get_abs_path() . "\"", $cmd);