Add support for JSON listing #1
@ -13,6 +13,29 @@ function handleNotFoundRequest() {
|
||||
return;
|
||||
}
|
||||
|
||||
function renderDownloadResponseAsJSON($lister) {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
// Require v=1 to be specified
|
||||
if (!isset($_GET['v']) || $_GET['v'] != '1') {
|
||||
$data = [ 'error' => 'Missing supported format version, for example v=1'];
|
||||
echo json_encode( $data );
|
||||
http_response_code(400);
|
||||
return;
|
||||
}
|
||||
$builds = $lister->getBuilds();
|
||||
$renderer = new BuildsRenderer($builds);
|
||||
$renderer->renderJSON();
|
||||
return;
|
||||
}
|
||||
|
||||
function renderDownloadResponseAsHTML($lister) {
|
||||
// Serve the directory listing as HTML.
|
||||
require 'templates/header.php';
|
||||
|
||||
// Logic inside content_build_lister.php will render the list of builds
|
||||
require 'templates/content_build_lister.php';
|
||||
fsiddi marked this conversation as resolved
Outdated
Sergey Sharybin
commented
Move to Move to `renderDownloadResponceAsJSON` or something similar.
|
||||
require 'templates/footer.php';
|
||||
}
|
||||
|
||||
function handleDownloadRequest() {
|
||||
$lister = createListerForCurrentRequest();
|
||||
$is_valid = $lister->isValid();
|
||||
@ -30,26 +53,12 @@ function handleDownloadRequest() {
|
||||
}
|
||||
|
||||
// Check if we are requesting a JSON formatted view.
|
||||
if (isset($_GET['format']) && $_GET['format'] == 'json') {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
// Require v=1 to be specified
|
||||
if (!isset($_GET['v']) || $_GET['v'] != '1') {
|
||||
$data = [ 'error' => 'Missing supported format version, for example v=1'];
|
||||
echo json_encode( $data );
|
||||
http_response_code(400);
|
||||
return;
|
||||
}
|
||||
$builds = $lister->getBuilds();
|
||||
$renderer = new BuildsRenderer($builds);
|
||||
$renderer->renderJSON();
|
||||
return;
|
||||
if ($_GET['format'] == 'json') {
|
||||
renderDownloadResponseAsJSON($lister);
|
||||
}
|
||||
|
||||
// Serve the directory listing as HTML.
|
||||
require 'templates/header.php';
|
||||
// Logic inside content_build_lister.php will render the list of builds
|
||||
require 'templates/content_build_lister.php';
|
||||
require 'templates/footer.php';
|
||||
renderDownloadResponseAsHTML($lister);
|
||||
|
||||
}
|
||||
|
||||
function handleDashboardRequest() {
|
||||
|
Loading…
Reference in New Issue
Block a user
You do not need to check
isset($_GET['format'])
when you're comparing to an explicit constant. Doingif ($_GET['format'] == 'json') {
should suffice.I tried, but removing the check raises:
Warning: Undefined array key "format" in /var/www/html/source/main.php on line 56