From: Mischa POSLAWSKY Date: Thu, 31 Dec 2020 13:35:32 +0000 (+0100) Subject: foto: json client requests serve directory api X-Git-Tag: v5.3~20 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/e0c43cd6e50d762ea564faf17a9aa4a21ca72ffb foto: json client requests serve directory api Requested album links as js array (in subarrays to allow future metadata addition) for use by dashboard page. --- diff --git a/foto/index.php b/foto/index.php index e7f1bab..8ba7db1 100644 --- a/foto/index.php +++ b/foto/index.php @@ -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