From e0c43cd6e50d762ea564faf17a9aa4a21ca72ffb Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 31 Dec 2020 14:35:32 +0100 Subject: [PATCH] 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. --- foto/index.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 -- 2.30.0