From: Mischa POSLAWSKY Date: Wed, 22 May 2019 17:21:59 +0000 (+0200) Subject: refresh outdated profile requests X-Git-Tag: v0.4~4 X-Git-Url: http://git.shiar.nl/sc2-widget/commitdiff_plain/aa690a9c0c95e3121b747d77aa836fcd92654fb2 refresh outdated profile requests Attempt to recreate files after an hour. --- diff --git a/widget.php b/widget.php index 736a7b1..ddf9cb8 100644 --- a/widget.php +++ b/widget.php @@ -19,13 +19,22 @@ function error($message, $status = 500) $request = trim($_SERVER['PATH_INFO'], '/'); $target = "$request.json"; -if (!file_exists($target)) { - if (!is_numeric($request)) { +$last = file_exists($target) ? filemtime($target) : 0; + +if ($last < time() - 3600) { + $recipe = NULL; + if (is_numeric($request)) { + $recipe = $request; + } + elseif (!$last) { error("Unknown profile request $request", 400); } - system("./getsc2clan $request | sponge $target", $exitcode); - if ($exitcode) { - error("No results for profile id $request from Blizzard", 503); + + if ($recipe) { + system("./getsc2clan $recipe | sponge $target", $exitcode); + if ($exitcode and !$last) { + error("No results for profile $request from Blizzard", 503); + } } } if (!filesize($target)) {