From aa690a9c0c95e3121b747d77aa836fcd92654fb2 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 22 May 2019 19:21:59 +0200 Subject: [PATCH] refresh outdated profile requests Attempt to recreate files after an hour. --- widget.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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)) { -- 2.30.0