mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Refactor API.
This commit is contained in:
parent
e31028f5a9
commit
7c4f9d574c
5 changed files with 53 additions and 36 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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\"");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue