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

Re-implement ProvidesOriginalUriInterface #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions Classes/AssetSource/CantoAssetProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@
use Neos\Flow\Annotations as Flow;
use Neos\Media\Domain\Model\AssetSource\AssetProxy\AssetProxyInterface;
use Neos\Media\Domain\Model\AssetSource\AssetProxy\HasRemoteOriginalInterface;
use Neos\Media\Domain\Model\AssetSource\AssetProxy\ProvidesOriginalUriInterface;
use Neos\Media\Domain\Model\AssetSource\AssetProxy\SupportsIptcMetadataInterface;
use Neos\Media\Domain\Model\AssetSource\AssetSourceInterface;
use Neos\Media\Domain\Model\ImportedAsset;
use Neos\Media\Domain\Repository\ImportedAssetRepository;
use Neos\Media\Domain\Service\ThumbnailService;
use Neos\Media\Exception\ThumbnailServiceException;
use Neos\Utility\MediaTypes;
use Psr\Http\Message\UriInterface;
use stdClass;

/**
*
*/
final class CantoAssetProxy implements AssetProxyInterface, HasRemoteOriginalInterface, SupportsIptcMetadataInterface
final class CantoAssetProxy implements AssetProxyInterface, HasRemoteOriginalInterface, ProvidesOriginalUriInterface, SupportsIptcMetadataInterface
{
/**
* @var CantoAssetSource
Expand Down Expand Up @@ -75,14 +78,14 @@ final class CantoAssetProxy implements AssetProxyInterface, HasRemoteOriginalInt
private $iptcProperties = [];

/**
* @var UriInterface
* @var string
*/
private $thumbnailUri;
private $previewUri;

/**
* @var UriInterface
* @var string
*/
private $previewUri;
private $originalUri;

/**
* @var int
Expand All @@ -105,6 +108,12 @@ final class CantoAssetProxy implements AssetProxyInterface, HasRemoteOriginalInt
*/
protected $importedAssetRepository;

/**
* @FLow\Inject
* @var ThumbnailService
*/
protected $thumbnailService;

/**
* @param stdClass $jsonObject
* @param CantoAssetSource $assetSource
Expand Down Expand Up @@ -132,8 +141,8 @@ public static function fromJsonObject(stdClass $jsonObject, CantoAssetSource $as
$assetProxy->widthInPixels = $jsonObject->width ? (int)$jsonObject->width : null;
$assetProxy->heightInPixels = $jsonObject->height ? (int)$jsonObject->height : null;

$assetProxy->thumbnailUri = new Uri($jsonObject->url->directUrlPreview);
$assetProxy->previewUri = new Uri($jsonObject->url->directUrlPreview);
$assetProxy->originalUri = $jsonObject->url->directUrlOriginal;
$assetProxy->previewUri = $jsonObject->url->directUrlPreview;

return $assetProxy;
}
Expand Down Expand Up @@ -238,18 +247,30 @@ public function getHeightInPixels(): ?int

/**
* @return UriInterface
* @throws ThumbnailServiceException
*/
public function getThumbnailUri(): ?UriInterface
{
return $this->thumbnailUri;
$thumbnailConfiguration = $this->thumbnailService->getThumbnailConfigurationForPreset('Neos.Media.Browser:Thumbnail');
return new Uri(sprintf(
'%s/%d',
preg_replace('|/[0-9]+$|', '', $this->previewUri),
max($thumbnailConfiguration->getMaximumWidth(), $thumbnailConfiguration->getMaximumHeight())
));
}

/**
* @return UriInterface
* @throws ThumbnailServiceException
*/
public function getPreviewUri(): ?UriInterface
{
return $this->previewUri;
$previewConfiguration = $this->thumbnailService->getThumbnailConfigurationForPreset('Neos.Media.Browser:Preview');
return new Uri(sprintf(
'%s/%d',
preg_replace('|/[0-9]+$|', '', $this->previewUri),
max($previewConfiguration->getMaximumWidth(), $previewConfiguration->getMaximumHeight())
));
}

/**
Expand All @@ -260,7 +281,15 @@ public function getPreviewUri(): ?UriInterface
*/
public function getImportStream()
{
return fopen((string)$this->assetSource->getCantoClient()->directUri($this->identifier), 'rb');
return fopen($this->originalUri, 'rb');
}

/**
* @return UriInterface
*/
public function getOriginalUri(): UriInterface
{
return new Uri($this->originalUri);
}

/**
Expand Down