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
351c395f82
commit
0b28a9eea1
3 changed files with 163 additions and 156 deletions
|
@ -3,21 +3,31 @@
|
|||
class Api {
|
||||
|
||||
|
||||
private $app;
|
||||
private $actions, $app, $options;
|
||||
|
||||
|
||||
public function __construct($app) {
|
||||
|
||||
$this->actions = array("get", "getThumbHref", "download", "upload", "delete", "rename");
|
||||
$this->app = $app;
|
||||
$this->options = $app->get_options();
|
||||
}
|
||||
|
||||
|
||||
public function apply() {
|
||||
|
||||
$options = $this->app->get_options();
|
||||
$action = use_request_param("action");
|
||||
|
||||
if ($action === "get") {
|
||||
if (in_array($action, $this->actions)) {
|
||||
$methodname = "on_$action";
|
||||
$this->$methodname();
|
||||
}
|
||||
|
||||
json_fail(100, "unsupported request");
|
||||
}
|
||||
|
||||
|
||||
private function on_get() {
|
||||
|
||||
$response = array();
|
||||
|
||||
|
@ -77,9 +87,9 @@ class Api {
|
|||
}
|
||||
|
||||
|
||||
else if ($action === "getThumbHref") {
|
||||
private function on_getThumbHref() {
|
||||
|
||||
json_fail(1, "thumbnails disabled", !$options["thumbnails"]["enabled"]);
|
||||
json_fail(1, "thumbnails disabled", !$this->options["thumbnails"]["enabled"]);
|
||||
json_fail(2, "thumbnails not supported", !HAS_PHP_JPG);
|
||||
|
||||
$type = use_request_param("type");
|
||||
|
@ -96,9 +106,9 @@ class Api {
|
|||
}
|
||||
|
||||
|
||||
else if ($action === "download") {
|
||||
private function on_download() {
|
||||
|
||||
json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
|
||||
json_fail(1, "downloads disabled", !$this->options["download"]["enabled"]);
|
||||
|
||||
$as = use_request_param("as");
|
||||
$type = use_request_param("type");
|
||||
|
@ -119,7 +129,7 @@ class Api {
|
|||
}
|
||||
|
||||
|
||||
else if ($action === "upload") {
|
||||
private function on_upload() {
|
||||
|
||||
$href = use_request_param("href");
|
||||
|
||||
|
@ -144,9 +154,9 @@ class Api {
|
|||
}
|
||||
|
||||
|
||||
else if ($action === "delete") {
|
||||
private function on_delete() {
|
||||
|
||||
json_fail(1, "deletion disabled", !$options["delete"]["enabled"]);
|
||||
json_fail(1, "deletion disabled", !$this->options["delete"]["enabled"]);
|
||||
|
||||
$hrefs = use_request_param("hrefs");
|
||||
|
||||
|
@ -175,9 +185,9 @@ class Api {
|
|||
}
|
||||
|
||||
|
||||
else if ($action === "rename") {
|
||||
private function on_rename() {
|
||||
|
||||
json_fail(1, "renaming disabled", !$options["rename"]["enabled"]);
|
||||
json_fail(1, "renaming disabled", !$this->options["rename"]["enabled"]);
|
||||
|
||||
$href = use_request_param("href");
|
||||
$name = use_request_param("name");
|
||||
|
@ -199,7 +209,4 @@ class Api {
|
|||
|
||||
json_exit();
|
||||
}
|
||||
|
||||
json_fail(100, "unsupported request");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ class App {
|
|||
|
||||
public function get_setup() {
|
||||
|
||||
$consts = get_defined_constants(true)['user'];
|
||||
$consts['PHP_VERSION'] = PHP_VERSION;
|
||||
$consts = get_defined_constants(true)["user"];
|
||||
$consts["PHP_VERSION"] = PHP_VERSION;
|
||||
return $consts;
|
||||
}
|
||||
|
||||
|
@ -99,8 +99,8 @@ class App {
|
|||
return 500;
|
||||
}
|
||||
|
||||
foreach ($this->options["view"]["indexFiles"] as $if) {
|
||||
if (file_exists($path . "/" . $if)) {
|
||||
foreach ($this->options["view"]["indexFiles"] as $name) {
|
||||
if (file_exists($path . "/" . $name)) {
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ function setup() {
|
|||
// PATHS
|
||||
$script_name = getenv("SCRIPT_NAME");
|
||||
if (SERVER_NAME === "lighttpd") {
|
||||
$script_name = preg_replace("#^.*//#", "/", $script_name);
|
||||
$script_name = preg_replace("#^.*?//#", "/", $script_name);
|
||||
}
|
||||
define("APP_URL", normalize_path(dirname(dirname(dirname($script_name))), true));
|
||||
define("APP_PATH", normalize_path(dirname(dirname(dirname(dirname(__FILE__)))), false));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue