diff --git a/src/_h5ai/client/js/inc/ext/download.js b/src/_h5ai/client/js/inc/ext/download.js index 5743b0a3..c7ea7713 100644 --- a/src/_h5ai/client/js/inc/ext/download.js +++ b/src/_h5ai/client/js/inc/ext/download.js @@ -42,10 +42,14 @@ modulejs.define('ext/download', ['_', '$', 'core/event', 'core/location', 'core/ action: 'download', as: name + '.' + extension, type: type, - baseHref: location.getAbsHref(), - hrefs: _.pluck(selectedItems, 'absHref').join('|:|') + baseHref: location.getAbsHref() }; + _.each(selectedItems, function (item, idx) { + + query['hrefs[' + idx + ']'] = item.absHref; + }); + server.formRequest(query); } diff --git a/src/_h5ai/client/js/inc/ext/preview-img.js b/src/_h5ai/client/js/inc/ext/preview-img.js index 3841fab4..a13cbbef 100644 --- a/src/_h5ai/client/js/inc/ext/preview-img.js +++ b/src/_h5ai/client/js/inc/ext/preview-img.js @@ -20,14 +20,16 @@ modulejs.define('ext/preview-img', ['_', '$', 'core/event', 'core/server', 'core } server.request({ - action: 'getThumbHref', - type: 'img', - href: href, - width: settings.size, - height: 0 + action: 'get', + thumbs: [{ + type: 'img', + href: href, + width: settings.size, + height: 0 + }] }, function (json) { - callback(json && json.href ? json.href : null); + callback(json && json.thumbs && json.thumbs[0] ? json.thumbs[0] : null); }); } diff --git a/src/_h5ai/client/js/inc/ext/thumbnails.js b/src/_h5ai/client/js/inc/ext/thumbnails.js index 6885645a..10d1f561 100644 --- a/src/_h5ai/client/js/inc/ext/thumbnails.js +++ b/src/_h5ai/client/js/inc/ext/thumbnails.js @@ -7,21 +7,23 @@ modulejs.define('ext/thumbnails', ['_', 'core/event', 'core/server', 'core/setti doc: ['x-pdf', 'x-ps'], delay: 1, size: 100, - exif: true + exif: false }, allsettings.thumbnails); function requestThumb(type, href, ratio, callback) { server.request({ - action: 'getThumbHref', - type: type, - href: href, - width: Math.round(settings.size * ratio), - height: settings.size + action: 'get', + thumbs: [{ + type: type, + href: href, + width: Math.round(settings.size * ratio), + height: settings.size + }] }, function (json) { - callback(json && json.href ? json.href : null); + callback(json && json.thumbs && json.thumbs[0] ? json.thumbs[0] : null); }); } diff --git a/src/_h5ai/server/php/inc/class-api.php b/src/_h5ai/server/php/inc/class-api.php index 0676b676..fc391206 100644 --- a/src/_h5ai/server/php/inc/class-api.php +++ b/src/_h5ai/server/php/inc/class-api.php @@ -14,7 +14,7 @@ class Api { public function apply() { $action = Util::get_request_param("action"); - $supported = array("login", "logout", "get", "getThumbHref", "download"); + $supported = array("login", "logout", "get", "download"); Util::json_fail(Util::ERR_UNSUPPORTED, "unsupported action", !in_array($action, $supported)); $methodname = "on_${action}"; @@ -71,28 +71,19 @@ class Api { $response["items"] = $this->app->get_items($href, $what); } + if (Util::get_request_param("thumbs", false)) { + + Util::json_fail(Util::ERR_DISABLED, "thumbnails disabled", !$this->app->get_option("thumbnails.enabled", false)); + Util::json_fail(Util::ERR_UNSUPPORTED, "thumbnails not supported", !HAS_PHP_JPEG); + + $thumbs = Util::get_request_param("thumbs"); + $response["thumbs"] = $this->app->get_thumbs($thumbs); + } + Util::json_exit($response); } - private function on_getThumbHref() { - - Util::json_fail(Util::ERR_DISABLED, "thumbnails disabled", !$this->app->get_option("thumbnails.enabled", false)); - Util::json_fail(Util::ERR_UNSUPPORTED, "thumbnails not supported", !HAS_PHP_JPEG); - - $type = Util::get_request_param("type"); - $src_href = Util::get_request_param("href"); - $width = Util::get_request_param("width"); - $height = Util::get_request_param("height"); - - $thumb = new Thumb($this->app); - $thumb_href = $thumb->thumb($type, $src_href, $width, $height); - Util::json_fail(Util::ERR_FAILED, "thumbnail creation failed", $thumb_href === null); - - Util::json_exit(array("href" => $thumb_href)); - } - - private function on_download() { Util::json_fail(Util::ERR_DISABLED, "downloads disabled", !$this->app->get_option("download.enabled", false)); @@ -104,8 +95,6 @@ class Api { $archive = new Archive($this->app); - $hrefs = explode("|:|", trim($hrefs)); - set_time_limit(0); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"$as\""); diff --git a/src/_h5ai/server/php/inc/class-app.php b/src/_h5ai/server/php/inc/class-app.php index 92ceeac9..6686f42b 100644 --- a/src/_h5ai/server/php/inc/class-app.php +++ b/src/_h5ai/server/php/inc/class-app.php @@ -383,4 +383,24 @@ class App { "footerType" => $footer_type ); } + + + public function get_thumbs($requests) { + + $hrefs = []; + + foreach ($requests as $req) { + $type = $req["type"]; + $src_href = $req["href"]; + $width = $req["width"]; + $height = $req["height"]; + + $thumb = new Thumb($this); + $thumb_href = $thumb->thumb($type, $src_href, $width, $height); + + $hrefs[] = $thumb_href; + } + + return $hrefs; + } }