mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
More refactorings.
This commit is contained in:
parent
fc8a0589dd
commit
c40fac67d0
9 changed files with 279 additions and 332 deletions
|
@ -16,7 +16,7 @@ class Api {
|
|||
|
||||
$options = $this->app->get_options();
|
||||
|
||||
list($action) = use_request_params(array("action"));
|
||||
$action = use_request_param("action");
|
||||
|
||||
if ($action === "get") {
|
||||
|
||||
|
@ -24,50 +24,54 @@ class Api {
|
|||
|
||||
if (has_request_param("options")) {
|
||||
|
||||
use_request_params("options");
|
||||
use_request_param("options");
|
||||
$response["options"] = $this->app->get_options();
|
||||
}
|
||||
|
||||
if (has_request_param("types")) {
|
||||
|
||||
use_request_params("types");
|
||||
use_request_param("types");
|
||||
$response["types"] = $this->app->get_types();
|
||||
}
|
||||
|
||||
if (has_request_param("langs")) {
|
||||
|
||||
use_request_params("langs");
|
||||
use_request_param("langs");
|
||||
$response["langs"] = $this->app->get_l10n_list();
|
||||
}
|
||||
|
||||
if (has_request_param("l10n")) {
|
||||
|
||||
list($iso_codes) = use_request_params("l10nCodes", "l10n");
|
||||
use_request_param("l10n");
|
||||
$iso_codes = use_request_param("l10nCodes");
|
||||
$iso_codes = explode(":", $iso_codes);
|
||||
$response["l10n"] = $this->app->get_l10n($iso_codes);
|
||||
}
|
||||
|
||||
if (has_request_param("checks")) {
|
||||
|
||||
use_request_params("checks");
|
||||
use_request_param("checks");
|
||||
$response["checks"] = $this->app->get_server_checks();
|
||||
}
|
||||
|
||||
if (has_request_param("server")) {
|
||||
|
||||
use_request_params("server");
|
||||
use_request_param("server");
|
||||
$response["server"] = $this->app->get_server_details();
|
||||
}
|
||||
|
||||
if (has_request_param("custom")) {
|
||||
|
||||
list($abs_href) = use_optional_request_params("customHref", "custom");
|
||||
use_request_param("custom");
|
||||
$abs_href = use_request_param("customHref", null);
|
||||
$response["custom"] = $this->app->get_customizations($abs_href);
|
||||
}
|
||||
|
||||
if (has_request_param("items")) {
|
||||
|
||||
list($abs_href, $what) = use_optional_request_params("itemsHref", "itemsWhat", "items");
|
||||
use_request_param("items");
|
||||
$abs_href = use_request_param("itemsHref", null);
|
||||
$what = use_request_param("itemsWhat", null);
|
||||
$what = is_numeric($what) ? intval($what, 10) : 1;
|
||||
$response["items"] = $this->app->get_items($abs_href, $what);
|
||||
}
|
||||
|
@ -91,15 +95,19 @@ class Api {
|
|||
json_fail(2, "thumbnails not supported");
|
||||
}
|
||||
|
||||
list($type, $src_abs_href, $mode, $width, $height) = use_request_params(array("type", "href", "mode", "width", "height"));
|
||||
$type = use_request_param("type");
|
||||
$src_url = use_request_param("href");
|
||||
$mode = use_request_param("mode");
|
||||
$width = use_request_param("width");
|
||||
$height = use_request_param("height");
|
||||
|
||||
$thumb = new Thumb($this->app);
|
||||
$thumb_href = $thumb->thumb($type, $src_abs_href, $mode, $width, $height);
|
||||
if ($thumb_href === null) {
|
||||
$thumb_url = $thumb->thumb($type, $src_url, $mode, $width, $height);
|
||||
if ($thumb_url === null) {
|
||||
json_fail(3, "thumbnail creation failed");
|
||||
}
|
||||
|
||||
json_exit(array("absHref" => $thumb_href));
|
||||
json_exit(array("absHref" => $thumb_url));
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,7 +115,9 @@ class Api {
|
|||
|
||||
json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
|
||||
|
||||
list($as, $type, $hrefs) = use_request_params(array("as", "type", "hrefs"));
|
||||
$as = use_request_param("as");
|
||||
$type = use_request_param("type");
|
||||
$hrefs = use_request_param("hrefs");
|
||||
|
||||
normalized_require_once("Archive.php");
|
||||
$archive = new Archive($this->app);
|
||||
|
@ -129,7 +139,7 @@ class Api {
|
|||
|
||||
else if ($action === "upload") {
|
||||
|
||||
list($href) = use_request_params(array("href"));
|
||||
$href = use_request_param("href");
|
||||
|
||||
json_fail(1, "wrong HTTP method", strtolower($_SERVER["REQUEST_METHOD"]) !== "post");
|
||||
json_fail(2, "something went wrong", !array_key_exists("userfile", $_FILES));
|
||||
|
@ -139,10 +149,10 @@ class Api {
|
|||
json_fail(3, "something went wrong [" . $userfile["error"] . "]", $userfile["error"] !== 0);
|
||||
json_fail(4, "folders not supported", file_get_contents($userfile["tmp_name"]) === "null");
|
||||
|
||||
$upload_dir = $this->app->get_abs_path($href);
|
||||
$upload_dir = $this->app->to_path($href);
|
||||
$code = $this->app->get_http_code($href);
|
||||
|
||||
json_fail(5, "upload dir no h5ai folder or ignored", $code !== App::$MAGIC_SEQUENCE || $this->app->is_ignored($upload_dir));
|
||||
json_fail(5, "upload dir no h5ai folder or ignored", $code !== MAGIC_SEQUENCE || $this->app->is_ignored($upload_dir));
|
||||
|
||||
$dest = $upload_dir . "/" . utf8_encode($userfile["name"]);
|
||||
|
||||
|
@ -157,7 +167,7 @@ class Api {
|
|||
|
||||
json_fail(1, "deletion disabled", !$options["delete"]["enabled"]);
|
||||
|
||||
list($hrefs) = use_request_params(array("hrefs"));
|
||||
$hrefs = use_request_param("hrefs");
|
||||
|
||||
$hrefs = explode("|:|", trim($hrefs));
|
||||
$errors = array();
|
||||
|
@ -169,9 +179,9 @@ class Api {
|
|||
|
||||
$code = $this->app->get_http_code($d);
|
||||
|
||||
if ($code == App::$MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
|
||||
if ($code == MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
|
||||
|
||||
$abs_path = $this->app->get_abs_path($href);
|
||||
$abs_path = $this->app->to_path($href);
|
||||
|
||||
if (!unlink($abs_path)) {
|
||||
$errors[] = $href;
|
||||
|
@ -191,16 +201,17 @@ class Api {
|
|||
|
||||
json_fail(1, "renaming disabled", !$options["rename"]["enabled"]);
|
||||
|
||||
list($href, $name) = use_request_params(array("href", "name"));
|
||||
$href = use_request_param("href");
|
||||
$name = use_request_param("name");
|
||||
|
||||
$d = normalize_path(dirname($href), true);
|
||||
$n = basename($href);
|
||||
|
||||
$code = $this->app->get_http_code($d);
|
||||
|
||||
if ($code == App::$MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
|
||||
if ($code == MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
|
||||
|
||||
$abs_path = $this->app->get_abs_path($href);
|
||||
$abs_path = $this->app->to_path($href);
|
||||
$folder = normalize_path(dirname($abs_path));
|
||||
|
||||
if (!rename($abs_path, $folder . "/" . $name)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue