Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code to support API authentication from Photoprism #764

Merged
merged 4 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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