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

Photoprism #496

Closed
ISeeTWizard opened this issue Apr 20, 2022 · 25 comments
Closed

Photoprism #496

ISeeTWizard opened this issue Apr 20, 2022 · 25 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@ISeeTWizard
Copy link

Hi - I just have an issue with the livestats on the Photoprism tile.
In fact I need an authentification for the api (I tried to access too over the browser) but there is no such option that I could configure.

Isn't that supported yet?

Thanks

@runbmp
Copy link

runbmp commented May 6, 2022

You can try using https://user:[email protected]

@ISeeTWizard
Copy link
Author

Unfortunately that doesn't work :/
but thanks for the idea

@simensen
Copy link

I'm curious about this as well! I just tried to use the Photoprism tile and haven't been able to figure out how to "authenticate".

@simensen
Copy link

It looks like the v1 API uses X-Session-ID and I'm not sure how we could possibly use this with Heimdall, currently. :-/

https://docs.photoprism.app/developer-guide/ui/rest-api/

@iwinstar
Copy link

I figure out how to solve this problem. You need to change two files under Heimdall deploy path /config/www/SupportedApps/PhotoPrism/ and then re-add PhotoPrism.

config.blade.php

<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
<div class="items">
    <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>
    </div>
</div>

PhotoPrism.php

<?php namespace App\SupportedApps\PhotoPrism;

class PhotoPrism extends \App\SupportedApps implements \App\EnhancedApps
{
	public $config;

	//protected $login_first = true; // Uncomment if api requests need to be authed first
	//protected $method = 'POST';  // Uncomment if requests to the API should be set by POST

	function __construct()
	{
		//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
	}

	function get_request_attrs()
    {
		$attrs["headers"] = ["X-Session-ID" => $this->config->session];
        return $attrs;
    }

	public function test()
	{
        $attrs = $this->get_request_attrs();
		$test = parent::appTest($this->url("api/v1/config"), $attrs);
		echo $test->status;
	}

	public function livestats()
	{
		$status = "inactive";
		$attrs = $this->get_request_attrs();
		$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;
		}

		return parent::getLiveStats($status, $data);
	}

	public function url($endpoint)
	{
		$api_url = parent::normaliseurl($this->config->url) . $endpoint;
		return $api_url;
	}
}

@byrongamatos
Copy link

Thank you @iwinstar your solution worked great.

@EarlJr53
Copy link

@byrongamatos what did you put into the URL and Session ID fields when adding PhotoPrism into Heimdall?

@byrongamatos
Copy link

byrongamatos commented Dec 21, 2022

@byrongamatos what did you put into the URL and Session ID fields when adding PhotoPrism into Heimdall?

@EarlJr53 Open a new tab and login to photo prism. Then open the developer tools of your browser, and under local storage for photoprism you will find a session token. I copied and used this token

@EarlJr53
Copy link

Thank you so much! I got it!

@byrongamatos what did you put into the URL and Session ID fields when adding PhotoPrism into Heimdall?

Open a new tab and login to photo prism. Then open the developer tools of your browser, and under local storage for photoprism you will find a session token. I copied and used this token

@ISeeTWizard
Copy link
Author

ISeeTWizard commented Dec 21, 2022

I changed the files too and had to restart my docker heimdall instance
Unfortunately for me it seems not to work :/
At least I don't get any errors - just a message that the communication with the api was successfull
But it writes 0 photos and 0 videos which of course isn't correct

The session_id I took with dev tools (F12 browser - Application tab - Search for Local Storage - Than your URL - than you can find the session_id)

I can even enter what I want as session ID
The communication is always successfull

@iwinstar
Copy link

iwinstar commented Dec 21, 2022

I think the session_id you provided maybe expired, you can check it with Postman.

Screenshot 2022-12-22 at 03 14 15

I changed the files too and had to restart my docker heimdall instance Unfortunately for me it seems not to work :/ At least I don't get any errors - just a message that the communication with the api was successfull But it writes 0 photos and 0 videos which of course isn't correct

The session_id I took with dev tools (F12 browser - Application tab - Search for Local Storage - Than your URL - than you can find the session_id)

I can even enter what I want as session ID The communication is always successfull

@ISeeTWizard
Copy link
Author

No
seems to be something else :/
Maybe due to the reverse proxy - Need to check further

@ISeeTWizard
Copy link
Author

Hmm OK
not reverse proxy - even with direct connection it doesn't work
I wrote photoprism to see why I just get 0 within the counts

@ISeeTWizard
Copy link
Author

At least the connection is working
Thanks for that :)

Why the API just returns 0 for everything must be an error somewhere on the photoprism side...
We will see - I will let you know if I figure out if someone else has this issue too

@heisenberg2980
Copy link

Could anyone open a PR to apply the solution from @iwinstar to Heimdall code? It would be great if everyone using Heimdall could get this fix without having to find this issue and manually update those files

@mvdkleijn
Copy link
Collaborator

Hi there! Running through the backlog of issues and PRs... A couple of observations / comments:

  1. The Photoprism REST API is marked as internal, i.e. generally not meant for external use;
  2. Indeed, the only way to authenticate appears to be copying the X-Session-ID header value;
  3. Their documentation mentions unauthenticated access, but doesn't further specify in what cases that can be used, if any.
  4. There is a Go client and a quick look through the code suggests that they use username & password to POST to api/v1/session and then retrieve an X-Session-ID or something equivalent. YMMV.
  5. Though I won't be working on code for this, I'm happy to look over any PRs that are submitted against current master.

Let me know if anyone plans to work on this.

@mvdkleijn mvdkleijn added help wanted Extra attention is needed question Further information is requested labels Jan 25, 2024
@LinuxServer-CI
Copy link

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

5 similar comments
@LinuxServer-CI
Copy link

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

@LinuxServer-CI
Copy link

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

@LinuxServer-CI
Copy link

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

@LinuxServer-CI
Copy link

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

@LinuxServer-CI
Copy link

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

@svanhoutte
Copy link
Contributor

@mvdkleijn photoprism now supports app password. https://docs.photoprism.app/developer-guide/api/auth/
It is easy to create a password for heimdall and use it with the code made by @iwinstar just need to put it in the session id field . I create a PR for it #764

@LinuxServer-CI
Copy link

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

@mvdkleijn
Copy link
Collaborator

Fixed by #764

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
Development

No branches or pull requests

10 participants