foto: api directory modification headers
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 4 May 2021 17:01:33 +0000 (19:01 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 8 May 2021 17:56:50 +0000 (19:56 +0200)
Report presence and date to reduce dashboard bandwidth,
with minimal cache-control to avoid dynamic caching.

foto/index.php

index 1ebb53986bc08c3046e94ca32a1b5b60d137ef64..45c49c90458fa05bd050b2ba38f707f8d8f01f08 100644 (file)
@@ -11,6 +11,13 @@ $Page->title = ($nav ? implode(' ', $nav) . ': ' : '') . $title;
 
 if ($_SERVER['HTTP_ACCEPT'] === 'application/json') {
        header('Access-Control-Allow-Origin: *');
+       header('Cache-Control: max-age=10');
+       if (file_exists($rootdir)) {
+               header('Last-Modified: '.gmdate(DATE_RFC7231, filemtime($rootdir)));
+       }
+       else {
+               http_response_code(404);
+       }
        $imgs = [];
        foreach (glob("$rootdir/*.jpg") as $path) {
                $target = preg_replace('{^(\.\./)*}', '', readlink($path));