refactor: simplify preview generation
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -995,10 +995,10 @@ class DefaultController extends ControllerAbstract {
|
|||||||
], Response::HTTP_NOT_FOUND);
|
], Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new StreamedResponse($preview->result->resource->stream(), Response::HTTP_OK, [
|
return new StreamedResponse($preview->resource->stream(), Response::HTTP_OK, [
|
||||||
'Content-Type' => $preview->result->resource->mimeType(),
|
'Content-Type' => $preview->resource->mimeType(),
|
||||||
'Content-Length' => (string) $preview->blob->size,
|
'Content-Length' => (string) $preview->size,
|
||||||
'ETag' => '"' . trim($preview->blob->etag, '"') . '"',
|
'ETag' => '"' . trim($preview->etag, '"') . '"',
|
||||||
'Cache-Control' => 'private, max-age=3600',
|
'Cache-Control' => 'private, max-age=3600',
|
||||||
'X-Content-Type-Options' => 'nosniff',
|
'X-Content-Type-Options' => 'nosniff',
|
||||||
]);
|
]);
|
||||||
|
|||||||
+5
-4
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace KTXM\MailManager;
|
namespace KTXM\MailManager;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use KTXC\Preview\CachedPreview;
|
use KTXC\Preview\Preview;
|
||||||
use KTXC\Preview\PreviewManager;
|
use KTXC\Preview\PreviewManager;
|
||||||
use KTXC\Resource\ProviderManager;
|
use KTXC\Resource\ProviderManager;
|
||||||
use KTXF\Preview\PreviewSource;
|
use KTXF\Preview\PreviewSource;
|
||||||
@@ -1359,7 +1359,7 @@ class Manager {
|
|||||||
/**
|
/**
|
||||||
* Resolve an authorized attachment and lazily generate or retrieve its preview.
|
* Resolve an authorized attachment and lazily generate or retrieve its preview.
|
||||||
*/
|
*/
|
||||||
public function entityPreview(string $tenantId, string $userId, EntityIdentifier $targetEntity, array $part, string $variant = 'popover'): ?CachedPreview {
|
public function entityPreview(string $tenantId, string $userId, EntityIdentifier $targetEntity, array $part, string $variant = 'popover'): ?Preview {
|
||||||
$mimeType = $part['type'] ?? null;
|
$mimeType = $part['type'] ?? null;
|
||||||
$size = $part['size'] ?? null;
|
$size = $part['size'] ?? null;
|
||||||
if (!is_string($mimeType) || ($size !== null && !is_int($size))) {
|
if (!is_string($mimeType) || ($size !== null && !is_int($size))) {
|
||||||
@@ -1375,9 +1375,11 @@ class Manager {
|
|||||||
throw new InvalidArgumentException('Attachment preview requires a blob, part, or content identifier');
|
throw new InvalidArgumentException('Attachment preview requires a blob, part, or content identifier');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$attachmentIdentity = hash('sha256', json_encode($selector, JSON_THROW_ON_ERROR));
|
||||||
|
|
||||||
return $this->previewManager->fetch($tenantId, new PreviewSource(
|
return $this->previewManager->fetch($tenantId, new PreviewSource(
|
||||||
sourceType: 'mail-attachment',
|
sourceType: 'mail-attachment',
|
||||||
identity: (string) $targetEntity,
|
identity: (string) $targetEntity . ':' . $attachmentIdentity,
|
||||||
// Attachments are immutable once delivered, so there is no revision to track;
|
// Attachments are immutable once delivered, so there is no revision to track;
|
||||||
// existence and access are enforced by entityDownload() (via serviceFetch) below,
|
// existence and access are enforced by entityDownload() (via serviceFetch) below,
|
||||||
// which only runs on a cache miss.
|
// which only runs on a cache miss.
|
||||||
@@ -1390,7 +1392,6 @@ class Manager {
|
|||||||
$targetEntity,
|
$targetEntity,
|
||||||
$selector,
|
$selector,
|
||||||
),
|
),
|
||||||
selector: hash('sha256', json_encode($selector, JSON_THROW_ON_ERROR)),
|
|
||||||
), $variant);
|
), $variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user