Fixed crash when no albums are available

This commit is contained in:
2021-11-26 17:44:38 +01:00
parent c65bc123d3
commit 56127a16a0
3 changed files with 17 additions and 11 deletions

View File

@ -182,12 +182,13 @@ class PhotoPrism
public function getAlbumsByTokens(array $tokens, int $count = 1000, int $offset = 0): array
{
$this->logger->debug('getAlbumsByToken');
$albums = $this->getAlbums($count, 0);
$visibleAlbums = [];
foreach ($albums as $album) {
$token = $this->getAlbumToken($album);
$album->token = $token;
if (in_array($album->token, $tokens)) {
if ($token != null && in_array($album->token, $tokens)) {
$visibleAlbums[] = $album;
} else {
$this->logger->debug('Skipping album without access: ' . $album->title);
@ -198,7 +199,7 @@ class PhotoPrism
return $visibleAlbums;
}
public function getAlbumToken($album): string
public function getAlbumToken($album): ?string
{
$uid = is_string($album) ? $album : $album->uid;
$res = $this->makeRequest('GET', '/albums/' . $uid . '/links');
@ -207,6 +208,9 @@ class PhotoPrism
throw new NetworkException($response['error']);
}
$this->logger->debug('Token response: ' . $res);
if (!in_array('Token', $response)) {
return null;
}
return $response['Token'];
}