From 32004e65024c77a7cf261c466b651f941fd5b77f Mon Sep 17 00:00:00 2001 From: svanhoutte <22617546+svanhoutte@users.noreply.github.com> Date: Sat, 17 Aug 2024 06:55:55 -0400 Subject: [PATCH] Update code to support API authentication from Photoprism (#764) * Update PhotoPrism.php to support authentication * Update config.blade.php for API authentication * Update PhotoPrism.php to pass phpcbf test * Fixed visibility and camel caps --- PhotoPrism/PhotoPrism.php | 14 +++++++++++--- PhotoPrism/config.blade.php | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/PhotoPrism/PhotoPrism.php b/PhotoPrism/PhotoPrism.php index 69645451bc..9144f0f6cb 100644 --- a/PhotoPrism/PhotoPrism.php +++ b/PhotoPrism/PhotoPrism.php @@ -14,21 +14,29 @@ public function __construct() //$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set } + public function getRequestAttrs() + { + $attrs["headers"] = ["X-Session-ID" => $this->config->session]; + return $attrs; + } + public function test() { - $test = parent::appTest($this->url("api/v1/config")); + $attrs = $this->getRequestAttrs(); + $test = parent::appTest($this->url("api/v1/config"), $attrs); echo $test->status; } public function livestats() { $status = "inactive"; - $res = parent::execute($this->url("api/v1/config")); + $attrs = $this->getRequestAttrs(); + $res = parent::execute($this->url("api/v1/config"), $attrs); $details = json_decode($res->getBody(), true); - $data = []; if ($details) { + $status = "active"; $data["photos"] = number_format($details["count"]["photos"]) ?? 0; $data["videos"] = number_format($details["count"]["videos"]) ?? 0; } diff --git a/PhotoPrism/config.blade.php b/PhotoPrism/config.blade.php index ce273e941c..1a8424d693 100644 --- a/PhotoPrism/config.blade.php +++ b/PhotoPrism/config.blade.php @@ -3,6 +3,10 @@