X-Git-Url: http://git.shiar.nl/sc2-widget/blobdiff_plain/b4c80b59335b9905191da1e9be35e82487ff36e7..60d357554684c38bfe547a601ce20013b1b5b693:/widget.php diff --git a/widget.php b/widget.php index 736a7b1..e222f22 100644 --- a/widget.php +++ b/widget.php @@ -18,14 +18,23 @@ function error($message, $status = 500) } $request = trim($_SERVER['PATH_INFO'], '/'); -$target = "$request.json"; -if (!file_exists($target)) { - if (!is_numeric($request)) { +$target = "data/$request.json"; +$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)) {