JSON API: Add link to the result image.

This commit is contained in:
Madeorsk 2019-02-24 14:49:29 +01:00
parent 0db54c0446
commit bf94ab7e1c
1 changed files with 10 additions and 10 deletions

View File

@ -101,7 +101,7 @@ Flight::route("HEAD|GET /polls/@id:[a-fA-F0-9]+/results", function ($id) {
if ($poll)
{
if (Flight::request()->type === "application/json")
Flight::json(Format::poll($poll)); //TODO Add a svg for results?
Flight::json(array_merge(Format::poll($poll), ["image" => $VERLAINE["app_url"]."/polls/{$id}/results/svg"]));
else
{
Flight::render("svg/results", ["poll" => $poll, "colors" => $VERLAINE["chart_colors"]], "results_chart");
@ -114,6 +114,15 @@ Flight::route("HEAD|GET /polls/@id:[a-fA-F0-9]+/results", function ($id) {
Flight::notFound();
});
Flight::route("HEAD|GET /polls/@id:[a-fA-F0-9]+/results/svg", function ($id) {
global $VERLAINE;
$poll = Poll::load_poll($id);
if ($poll)
Flight::render("svg/results", ["poll" => $poll, "colors" => $VERLAINE["chart_colors"]]);
else
Flight::notFound();
});
Flight::route("GET|DELETE /polls/@id:[a-fA-F0-9]+/@token:[a-fA-F0-9]+", function ($id, $token) {
$poll = Poll::load_poll($id);
if ($poll)
@ -138,15 +147,6 @@ Flight::route("GET|DELETE /polls/@id:[a-fA-F0-9]+/@token:[a-fA-F0-9]+", function
Flight::notFound();
});
Flight::route("HEAD|GET /polls/@id:[a-fA-F0-9]+/results/svg", function ($id) {
global $VERLAINE;
$poll = Poll::load_poll($id);
if ($poll)
Flight::render("svg/results", ["poll" => $poll, "colors" => $VERLAINE["chart_colors"]]);
else
Flight::notFound();
});
Flight::route("/", function () {
global $VERLAINE;
Flight::render("home", ["app_url" => $VERLAINE["app_url"]], "body_content");