foto: json client requests serve directory api
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 31 Dec 2020 13:35:32 +0000 (14:35 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 27 Apr 2021 16:39:27 +0000 (18:39 +0200)
Requested album links as js array (in subarrays to allow future metadata
addition) for use by dashboard page.

foto/index.php

index e7f1bab54132b0766eba3ecb8a4e54849676b03c..8ba7db1768b977d9f75c2eb36dc6852776526f2f 100644 (file)
@@ -6,7 +6,17 @@ $nav[0] = "Foto's"; # override of root 'foto'
 $title = array_pop($nav);
 $Page->title = ($nav ? implode(' ', $nav) . ': ' : '') . $title;
 
-if ($Page->api) {
+if ($_SERVER['HTTP_ACCEPT'] === 'application/json') {
+       header('Access-Control-Allow-Origin: *');
+       $imgs = [];
+       foreach (glob("$rootdir/*.jpg") as $path) {
+               $target = preg_replace('{^(\.\./)*}', '', readlink($path));
+               $imgs[] = ["/$target"];
+       }
+       print json_encode($imgs);
+       exit;
+}
+elseif ($Page->api) {
        $img = "$rootdir/index.jpg";
        if (file_exists($img)) {
                # cover image of current album