Changes some API things.

This commit is contained in:
Lars Jung 2012-10-09 14:16:57 +02:00
parent 811994423d
commit a60d5556af
13 changed files with 36 additions and 33 deletions

View file

@ -5,9 +5,7 @@ modulejs.define('core/server', ['$', '_', 'config'], function ($, _, config) {
request: function (data, callback) { request: function (data, callback) {
data.api = true; if (server.api) {
if (server.apiHref) {
$.ajax({ $.ajax({
url: '.', url: '.',
data: data, data: data,

View file

@ -57,7 +57,7 @@ modulejs.define('ext/delete', ['_', '$', 'core/settings', 'core/event', 'core/re
init = function () { init = function () {
if (!settings.enabled || !server.apiHref) { if (!settings.enabled || !server.api) {
return; return;
} }

View file

@ -35,7 +35,7 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
if (json && json.code === 0) { if (json && json.code === 0) {
setTimeout(function () { // wait here so the img above can be updated in time setTimeout(function () { // wait here so the img above can be updated in time
window.location = server.apiHref + '?action=getarchive&id=' + json.id + '&as=h5ai-selection.' + settings.format; window.location = '?action=getArchive&id=' + json.id + '&as=package.' + settings.format;
}, 200); }, 200);
} else { } else {
failed(); failed();
@ -48,7 +48,7 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
$img.attr('src', resource.image('loading.gif', true)); $img.attr('src', resource.image('loading.gif', true));
server.request({ server.request({
action: 'archive', action: 'createArchive',
execution: settings.execution, execution: settings.execution,
format: settings.format, format: settings.format,
hrefs: hrefsStr hrefs: hrefsStr
@ -71,7 +71,7 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
init = function () { init = function () {
if (!settings.enabled || !server.apiHref) { if (!settings.enabled || !server.api) {
return; return;
} }

View file

@ -17,7 +17,7 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/r
init = function () { init = function () {
if (!settings.enabled || !server.apiHref) { if (!settings.enabled || !server.api) {
return; return;
} }
@ -47,7 +47,7 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/r
maxfiles: settings.maxfiles, maxfiles: settings.maxfiles,
maxfilesize: settings.maxfilesize, maxfilesize: settings.maxfilesize,
url: server.apiHref, url: server.api,
data: { data: {
action: 'upload', action: 'upload',
href: entry.absHref href: entry.absHref

View file

@ -11,7 +11,7 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve
requestThumbSmall = function (type, href, callback) { requestThumbSmall = function (type, href, callback) {
server.request({action: 'getthumbsrc', type: type, href: href, mode: 'square', width: 16, height: 16}, function (json) { server.request({action: 'getThumbHref', type: type, href: href, mode: 'square', width: 16, height: 16}, function (json) {
callback(json && json.code === 0 ? json.absHref : null); callback(json && json.code === 0 ? json.absHref : null);
}); });
@ -19,7 +19,7 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve
requestThumbBig = function (type, href, callback) { requestThumbBig = function (type, href, callback) {
server.request({action: 'getthumbsrc', type: type, href: href, mode: 'rational', width: 100, height: 48}, function (json) { server.request({action: 'getThumbHref', type: type, href: href, mode: 'rational', width: 100, height: 48}, function (json) {
callback(json && json.code === 0 ? json.absHref : null); callback(json && json.code === 0 ? json.absHref : null);
}); });
@ -58,7 +58,7 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve
init = function (entry) { init = function (entry) {
if (!settings.enabled || !server.apiHref) { if (!settings.enabled || !server.api) {
return; return;
} }

View file

@ -1,5 +1,5 @@
modulejs.define('h5ai-main', ['_', 'core/event', 'core/settings'], function (_, event, settings) { modulejs.define('h5ai-main', ['_', 'core/event'], function (_, event) {
event.pub('beforeView'); event.pub('beforeView');

View file

@ -57,7 +57,6 @@
if (backend === 'php') { if (backend === 'php') {
$.getJSON('.', { $.getJSON('.', {
api: true,
action: 'get', action: 'get',
options: true, options: true,
types: true, types: true,
@ -77,7 +76,7 @@
langs: langs, langs: langs,
server: { server: {
backend: backend, backend: backend,
apiHref: null, api: false,
name: 'apache', name: 'apache',
version: null version: null
} }

View file

@ -104,7 +104,7 @@ Options
*/ */
"download": { "download": {
"enabled": true, "enabled": true,
"execution": "php", "execution": "shell",
"format": "zip" "format": "zip"
}, },

View file

@ -77,7 +77,7 @@ class Api {
} }
else if ($action === "getthumbsrc") { else if ($action === "getThumbHref") {
if (!$options["thumbnails"]["enabled"]) { if (!$options["thumbnails"]["enabled"]) {
json_fail(1, "thumbnails disabled"); json_fail(1, "thumbnails disabled");
@ -100,7 +100,7 @@ class Api {
} }
else if ($action === "archive") { else if ($action === "createArchive") {
json_fail(1, "downloads disabled", !$options["download"]["enabled"]); json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
@ -120,7 +120,7 @@ class Api {
} }
else if ($action === "getarchive") { else if ($action === "getArchive") {
json_fail(1, "downloads disabled", !$options["download"]["enabled"]); json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
@ -222,11 +222,6 @@ class Api {
json_exit(); json_exit();
} }
else {
json_fail(100, "unsupported action");
}
} }
} }

View file

@ -292,7 +292,7 @@ class App {
return array( return array(
"backend" => "php", "backend" => "php",
"apiHref" => $this->app_abs_href . "server/php/api.php", "api" => true,
"name" => strtolower(preg_replace("/\\/.*$/", "", getenv("SERVER_SOFTWARE"))), "name" => strtolower(preg_replace("/\\/.*$/", "", getenv("SERVER_SOFTWARE"))),
"version" => strtolower(preg_replace("/^.*\\//", "", preg_replace("/\\s.*$/", "", getenv("SERVER_SOFTWARE")))) "version" => strtolower(preg_replace("/^.*\\//", "", preg_replace("/\\s.*$/", "", getenv("SERVER_SOFTWARE"))))
); );

View file

@ -77,6 +77,7 @@ class Archive {
$real_file = $this->app->get_abs_path($href); $real_file = $this->app->get_abs_path($href);
$archived_file = preg_replace("!^" . normalize_path($this->app->get_root_abs_path(), true) . "!", "", $real_file); $archived_file = preg_replace("!^" . normalize_path($this->app->get_root_abs_path(), true) . "!", "", $real_file);
// $archived_file = preg_replace("!^" . normalize_path($this->app->get_abs_path(), true) . "!", "", $real_file);
if (is_dir($real_file)) { if (is_dir($real_file)) {
$this->add_dir($real_file, $archived_file); $this->add_dir($real_file, $archived_file);

View file

@ -19,14 +19,25 @@ normalized_require_once("/server/php/inc/util.php");
normalized_require_once("/server/php/inc/App.php"); normalized_require_once("/server/php/inc/App.php");
normalized_require_once("/server/php/inc/Entry.php"); normalized_require_once("/server/php/inc/Entry.php");
$APP = new App(APP_ABS_PATH, APP_ABS_HREF, ABS_HREF); $app = new App(APP_ABS_PATH, APP_ABS_HREF, ABS_HREF);
if (array_key_exists("api", $_REQUEST)) { if (count($_REQUEST)) {
header("Content-type: application/json;h5ai={{pkg.version}}");
use_request_params("api");
normalized_require_once("/server/php/inc/Api.php"); normalized_require_once("/server/php/inc/Api.php");
$api = new Api($APP); $api = new Api($app);
$api->apply(); $api->apply();
json_fail(100, "unsupported request");
} else {
header("Content-type: text/html;h5ai={{pkg.version}}");
$HREF = $app->get_app_abs_href();
$JSON = $app->get_generic_json();
$FALLBACK = $app->get_no_js_fallback();
} }
?> ?>

View file

@ -1,9 +1,8 @@
|<?php require_once(str_replace("\\", "/", dirname(__FILE__)) . "/inc/init.php"); ?> |<?php require_once(str_replace("\\", "/", dirname(__FILE__)) . "/inc/init.php"); ?>
|<?php header("Content-type: text/html;h5ai={{pkg.version}}"); ?>
- var href = "<?php echo $APP->get_app_abs_href(); ?>" - var href = "<?php echo $HREF; ?>"
- var json = "<?php echo $APP->get_generic_json(); ?>" - var json = "<?php echo $JSON; ?>"
- var fallback = "<?php echo $APP->get_no_js_fallback(); ?>" - var fallback = "<?php echo $FALLBACK; ?>"
doctype 5 doctype 5
//if lt IE 9 //if lt IE 9