1
0
mirror of https://git.cant.at/Madeorsk/PollVerlaine synced 2024-11-21 20:34:32 +01:00

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

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");