Initial commit
This commit is contained in:
62
src/Entities/Album.php
Normal file
62
src/Entities/Album.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Phlaym\PhotoprismApi\Entities;
|
||||
|
||||
use Phlaym\PhotoprismApi\API\LoggerFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/** A PhotoPrism Album */
|
||||
class Album
|
||||
{
|
||||
/** @var string $uid Unique Id of the album */
|
||||
public string $uid = '';
|
||||
|
||||
/** @var string $slug URL slug of the album */
|
||||
public string $slug = '';
|
||||
|
||||
/** @var string $title Title of the album */
|
||||
public string $title = '';
|
||||
|
||||
/** @var string|null $token Secret token of the album. Needs to be set by the API */
|
||||
public ?string $token = null;
|
||||
|
||||
/** @var int $photoCount Number of photos in Album */
|
||||
public int $photoCount = 0;
|
||||
|
||||
/** @var LoggerInterface $logger Logger object */
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* Creates a new album from the api response
|
||||
*
|
||||
* @param array $response Photoprism API response containing an album object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
array $response
|
||||
) {
|
||||
$this->uid = $response['UID'];
|
||||
$this->slug = $response['Slug'];
|
||||
$this->title = $response['Title'];
|
||||
if (isset($response['PhotoCount'])) {
|
||||
$this->photoCount = $response['PhotoCount'];
|
||||
}
|
||||
$this->logger = LoggerFactory::create('Phlaym\PhotoprismApi.Album');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL path for this album.
|
||||
* Starts with a leading /
|
||||
* Returns null if the album's token is not set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUrlPath(): ?string
|
||||
{
|
||||
if (empty($this->token)) {
|
||||
return null;
|
||||
}
|
||||
return "/s/{$this->token}/{$this->slug}";
|
||||
}
|
||||
}
|
77
src/Entities/Photo.php
Normal file
77
src/Entities/Photo.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Phlaym\PhotoprismApi\Entities;
|
||||
|
||||
use Phlaym\PhotoprismApi\API\LoggerFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/** A PhotoPrism Photo */
|
||||
class Photo
|
||||
{
|
||||
/** @var string $thumbnail_token Token for fetching the thumbnail*/
|
||||
public string $thumbnail_token = '';
|
||||
|
||||
/** @var string $uid Unique Id of the photo */
|
||||
public string $uid = '';
|
||||
|
||||
/** @var string $id Id of the photo */
|
||||
public int $id = 0;
|
||||
|
||||
/** @var string $type Type of the photo (image, video, etc) */
|
||||
public string $type = '';
|
||||
|
||||
public string $fileUID;
|
||||
public string $fileRoot;
|
||||
public string $fileName;
|
||||
public string $hash;
|
||||
public int $width;
|
||||
public int $height;
|
||||
|
||||
public array $files;
|
||||
|
||||
/** @var LoggerInterface $logger Logger object */
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* Creates a new photo from the api response
|
||||
*
|
||||
* @param array $response Photoprism API response containing a photo object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
array $response
|
||||
) {
|
||||
$this->uid = $response['UID'];
|
||||
$this->id = intval($response['ID']);
|
||||
$this->type = $response['Type'];
|
||||
$this->fileUID = $response['FileUID'];
|
||||
$this->fileRoot = $response['FileRoot'];
|
||||
$this->fileName = $response['FileName'];
|
||||
$this->hash = $response['Hash'];
|
||||
$this->width = intval($response['Width']);
|
||||
$this->height = intval($response['Height']);
|
||||
$this->logger = LoggerFactory::create('Phlaym\PhotoprismApi.Photo');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the thumbnail URL path for this image.
|
||||
* Starts with a leading /
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getThumbnailUrl(string $size = 'tile_500'): string
|
||||
{
|
||||
return "/t/{$this->hash}/{$this->thumbnail_token}/{$size}";
|
||||
}
|
||||
/**
|
||||
* Gets the thumbnail URL path for this image.
|
||||
* Starts with a leading /
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmbedUrl(string $size = 'fit_1920'): string
|
||||
{
|
||||
return "/api/v1/t/{$this->hash}/{$this->thumbnail_token}/{$size}";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user