Skip to content

Commit 32004e6

Browse files
authored
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
1 parent 8255133 commit 32004e6

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

PhotoPrism/PhotoPrism.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,29 @@ public function __construct()
1414
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
1515
}
1616

17+
public function getRequestAttrs()
18+
{
19+
$attrs["headers"] = ["X-Session-ID" => $this->config->session];
20+
return $attrs;
21+
}
22+
1723
public function test()
1824
{
19-
$test = parent::appTest($this->url("api/v1/config"));
25+
$attrs = $this->getRequestAttrs();
26+
$test = parent::appTest($this->url("api/v1/config"), $attrs);
2027
echo $test->status;
2128
}
2229

2330
public function livestats()
2431
{
2532
$status = "inactive";
26-
$res = parent::execute($this->url("api/v1/config"));
33+
$attrs = $this->getRequestAttrs();
34+
$res = parent::execute($this->url("api/v1/config"), $attrs);
2735
$details = json_decode($res->getBody(), true);
28-
2936
$data = [];
3037

3138
if ($details) {
39+
$status = "active";
3240
$data["photos"] = number_format($details["count"]["photos"]) ?? 0;
3341
$data["videos"] = number_format($details["count"]["videos"]) ?? 0;
3442
}

PhotoPrism/config.blade.php

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<div class="input">
44
<label>{{ strtoupper(__('app.url')) }}</label>
55
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
6+
</div>
7+
<div class="input">
8+
<label title="">Session ID (<a href="https://docs.photoprism.app/developer-guide/api/#with-authentication" target="_blank">help?</a>)</label>
9+
{!! Form::text('config[session]', isset($item) ? $item->getconfig()->session : null, ['placeholder' => __('Session ID'), 'data-config' => 'session', 'class' => 'form-control config-item']) !!}
610
</div>
711
<div class="input">
812
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>

0 commit comments

Comments
 (0)