Add minified option to status action

This commit is contained in:
Starbeamrainbowlabs 2018-03-27 17:20:58 +01:00
parent 5af29c133f
commit 1c30d2543b
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
4 changed files with 14 additions and 7 deletions

View File

@ -19,6 +19,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
- You'll need to rebuild your search index for this fix to fully take effect (call the `invindex-rebuild` action as a mod or better)
- Normalise utf8 text to avoid duplicate ids and missing search results.
- Improved handling of mime types in some places in the API.
- Added `minified` option to `status` action to reduce data usage slightly
### Changed
- Disallow uploads if editing is disabled. Previously files could still be uploaded even if editing was disabled - unless `upload_enabled` was set to `false`.

View File

@ -2368,11 +2368,12 @@ register_module([
"code" => function() {
global $settings;
/**
* @api {get} ?action=status Get the json-formatted status of this wiki
* @api {get} ?action=status[&minified=type] Get the json-formatted status of this wiki
* @apiName Status
* @apiGroup Stats
* @apiPermission Anonymous
*
*
* @apiParam {boolean} Whether or not the result should be minified JSON. Default: false
*/
@ -2387,6 +2388,8 @@ register_module([
exit("Unfortunately, this API is currently only available in application/json at the moment, which you haven't indicated you accept in your http accept header. You said this in your accept header:\n" . $_SERVER["HTTP_ACCEPT"]);
}
$minified = ($_GET["minified"] ?? "false") == "true";
$action_names = array_keys(get_object_vars($actions));
sort($action_names);
@ -2398,7 +2401,7 @@ register_module([
$result->logo_url = $settings->favicon;
header("content-type: application/json");
exit(json_encode($result, JSON_PRETTY_PRINT) . "\n");
exit($minified ? json_encode($result) : json_encode($result, JSON_PRETTY_PRINT) . "\n");
});
add_help_section("960-api-status", "Wiki Status API", "<p></p>");

View File

@ -41,7 +41,7 @@
"author": "Starbeamrainbowlabs",
"description": "Provides a basic JSON status action that provices a few useful bits of information for API consumption.",
"id": "api-status",
"lastupdate": 1522166256,
"lastupdate": 1522167607,
"optional": false
},
{

View File

@ -8,11 +8,12 @@ register_module([
"code" => function() {
global $settings;
/**
* @api {get} ?action=status Get the json-formatted status of this wiki
* @api {get} ?action=status[&minified=type] Get the json-formatted status of this wiki
* @apiName Status
* @apiGroup Stats
* @apiPermission Anonymous
*
*
* @apiParam {boolean} Whether or not the result should be minified JSON. Default: false
*/
@ -27,6 +28,8 @@ register_module([
exit("Unfortunately, this API is currently only available in application/json at the moment, which you haven't indicated you accept in your http accept header. You said this in your accept header:\n" . $_SERVER["HTTP_ACCEPT"]);
}
$minified = ($_GET["minified"] ?? "false") == "true";
$action_names = array_keys(get_object_vars($actions));
sort($action_names);
@ -38,7 +41,7 @@ register_module([
$result->logo_url = $settings->favicon;
header("content-type: application/json");
exit(json_encode($result, JSON_PRETTY_PRINT) . "\n");
exit($minified ? json_encode($result) : json_encode($result, JSON_PRETTY_PRINT) . "\n");
});
add_help_section("960-api-status", "Wiki Status API", "<p></p>");