X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=app%2FController%2FGithub.php;h=164f3205134070d8464ca6927382151f9f050594;hb=36cfa28cf2dcee3422f0231f91c6692eb28e7824;hp=0c38bd7721cb3daf40f36e65ac8dbcf9a389e271;hpb=25b99959b9e66d00681092977c23b5df32ead5f4;p=pharext%2Fpharext.org diff --git a/app/Controller/Github.php b/app/Controller/Github.php index 0c38bd7..164f320 100644 --- a/app/Controller/Github.php +++ b/app/Controller/Github.php @@ -8,7 +8,7 @@ use app\Session; use app\Web; use http\QueryString; -use http\Url; +use http\Header; abstract class Github implements Controller { @@ -35,7 +35,16 @@ abstract class Github implements Controller "location" => "github", "title" => "Github" ]); - $this->app->getView()->registerFunction("check", [$this, "checkRepoHook"]); + $this->app->getView()->registerFunction("check", [$github, "checkRepoHook"]); + + if (($header = $this->app->getRequest()->getHeader("Cache-Control", Header::class))) { + $params = $header->getParams(); + if (!empty($params["no-cache"])) { + $this->github->setMaxAge(0); + } elseif (!empty($params["max-age"])) { + $this->github->setMaxAge($params["max-age"]["value"]); + } + } } protected function checkToken() { @@ -48,36 +57,4 @@ abstract class Github implements Controller ])); return false; } - - /** - * Check if the pharext webhook is set for the repo and return its id - * @param object $repo - * @return int hook id - */ - function checkRepoHook($repo) { - if ($repo->hooks) { - foreach ($repo->hooks as $hook) { - if ($hook->name === "web" && $hook->config->url === $this->github->getConfig()->hook->url) { - return $hook; - } - } - } - return null; - } - - function createLinkGenerator($links) { - return function($which) use($links) { - if (!isset($links[$which])) { - if ($which !== "next" || !isset($links["last"])) { - return null; - } else { - $which = "last"; - } - } - $url = new Url($links[$which], null, 0); - $qry = new QueryString($url->query); - return $qry->getInt("page", 1); - }; - } - }