refresh outdated profile requests
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 22 May 2019 17:21:59 +0000 (19:21 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 22 May 2019 22:05:10 +0000 (00:05 +0200)
Attempt to recreate files after an hour.

widget.php

index 736a7b1305b04eb8ee3f11bc4a409d44c572ca3f..ddf9cb854aa8df3f823df1a03c9a1dee7d465d2e 100644 (file)
@@ -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 <q>$request</q>", 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)) {