Fixed crash when no albums are available
This commit is contained in:
parent
c65bc123d3
commit
56127a16a0
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
**/*/logs
|
||||
upload.php
|
||||
config.php
|
||||
.nova
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/composer,macos
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=composer,macos
|
||||
@ -42,4 +43,4 @@ Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/composer,macos
|
||||
# End of https://www.toptal.com/developers/gitignore/api/composer,macos
|
||||
|
17
index.php
17
index.php
@ -36,7 +36,7 @@ use PhotoPrismUpload\API\PhotoPrism;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body></body>
|
||||
<body>
|
||||
<?php
|
||||
|
||||
$config = require(__DIR__ . '/config.php');
|
||||
@ -45,22 +45,22 @@ $albums = [];
|
||||
try {
|
||||
$api->login();
|
||||
} catch (\Exception $e) {
|
||||
die('Fehler: ' . $e->getMessage());
|
||||
die('Fehler: ' . $e->getMessage().'</body></html>');
|
||||
}
|
||||
|
||||
if (!isset($_POST['submit'])) {
|
||||
if (!isset($_GET['token'])) {
|
||||
die('Sorry, kein Zugriff');
|
||||
die('Sorry, kein Zugriff</body></html>');
|
||||
}
|
||||
$token = $_GET['token'];
|
||||
$tokens = explode(',', $token);
|
||||
try {
|
||||
$albums = $api->getAlbumsByTokens($tokens);
|
||||
} catch (\Exception $e) {
|
||||
die('Fehler: ' . $e->getMessage());
|
||||
die('Fehler: ' . $e->getMessage().'</body></html>');
|
||||
}
|
||||
if (empty($albums) && (empty($config['noAlbumToken']) || !in_array($config['noAlbumToken'], $tokens))) {
|
||||
die('Falscher Token');
|
||||
die('Falscher Token</body></html>');
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
@ -118,12 +118,13 @@ if (!isset($_POST['submit'])) {
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
die();
|
||||
die('</body></html>');
|
||||
}
|
||||
try {
|
||||
$api->uploadPhotos($_POST['album']);
|
||||
} catch (\Exception $e) {
|
||||
die('Fehler: ' . $e->getMessage());
|
||||
die('Fehler: ' . $e->getMessage().'</body></html>');
|
||||
}
|
||||
?>
|
||||
Erfolg! <a href=".">Zurück</a>
|
||||
Erfolg! <a href=".">Zurück</a>
|
||||
</body></html>
|
@ -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'];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user