Skip to content

Commit

Permalink
Update code to support API authentication from Photoprism (#764)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
svanhoutte committed Aug 17, 2024
1 parent 8255133 commit 32004e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions PhotoPrism/PhotoPrism.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions PhotoPrism/config.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<div class="input">
<label>{{ strtoupper(__('app.url')) }}</label>
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
</div>
<div class="input">
<label title="">Session ID (<a href="https://docs.photoprism.app/developer-guide/api/#with-authentication" target="_blank">help?</a>)</label>
{!! Form::text('config[session]', isset($item) ? $item->getconfig()->session : null, ['placeholder' => __('Session ID'), 'data-config' => 'session', 'class' => 'form-control config-item']) !!}
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
Expand Down

0 comments on commit 32004e6

Please sign in to comment.