Initial commit
This commit is contained in:
69
photos.php
Normal file
69
photos.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
/* require autoloading to manage namespaces */
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use Phlaym\PhotoprismApi\API\PhotoPrism;
|
||||
$config = include __DIR__ . '/config.php';
|
||||
|
||||
function goodbye($message)
|
||||
{
|
||||
die(json_encode(['error' => ['message' => $message]]));
|
||||
}
|
||||
|
||||
if (!isset($_GET['album'])) {
|
||||
goodbye('Kein Album angegeben!');
|
||||
}
|
||||
|
||||
if (!isset($config['host'])) {
|
||||
$config['host'] = 'https://photos.phlaym.net';
|
||||
}
|
||||
$album_token = $_GET['album'];
|
||||
$offset = $_GET['offset'] ?? 0;
|
||||
|
||||
$api = new PhotoPrism($config);
|
||||
try {
|
||||
$api->login();
|
||||
} catch (\Exception $e) {
|
||||
goodbye('Login bei Photoprism fehlgeschlagen');
|
||||
}
|
||||
$album = null;
|
||||
try {
|
||||
if (isset($_SESSION[$album_token])) {
|
||||
$album = $api->getAlbumById($_SESSION[$album_token], $album_token);
|
||||
if (is_null($album)) {
|
||||
goodbye('Fotoalbum konnte nicht gefunden werden');
|
||||
}
|
||||
$album->photoCount = $_SESSION[$album_token . '_count'];
|
||||
} else {
|
||||
$album = $api->getAlbumByToken($album_token);
|
||||
if (is_null($album)) {
|
||||
goodbye('Fotoalbum konnte nicht gefunden werden');
|
||||
}
|
||||
$_SESSION[$album_token] = $album->uid;
|
||||
$_SESSION[$album_token . '_count'] = $album->photoCount;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
goodbye('Login bei Photoprism fehlgeschlagen');
|
||||
}
|
||||
|
||||
$photo = null;
|
||||
try {
|
||||
$photos = $api->getAlbumPhotos($album, 1, $offset % $album->photoCount);
|
||||
if (is_null($photos) || empty($photos)) {
|
||||
goodbye('Fotos konnten nicht gefunden werden');
|
||||
}
|
||||
$photo = $photos[0];
|
||||
} catch (\Exception $e) {
|
||||
goodbye('Laden des nächstes Fotos fehlgeschlagen');
|
||||
}
|
||||
echo json_encode(
|
||||
[
|
||||
'src' => $config['host'] . $photo->getEmbedUrl('fit_1920'),
|
||||
'count' => $album->photoCount,
|
||||
'album' => $album->title
|
||||
]
|
||||
);
|
Reference in New Issue
Block a user