diff --git a/lib/Controllers/DefaultController.php b/lib/Controllers/DefaultController.php index 5ce2476..3e5e010 100644 --- a/lib/Controllers/DefaultController.php +++ b/lib/Controllers/DefaultController.php @@ -995,10 +995,10 @@ class DefaultController extends ControllerAbstract { ], Response::HTTP_NOT_FOUND); } - return new StreamedResponse($preview->result->resource->stream(), Response::HTTP_OK, [ - 'Content-Type' => $preview->result->resource->mimeType(), - 'Content-Length' => (string) $preview->blob->size, - 'ETag' => '"' . trim($preview->blob->etag, '"') . '"', + return new StreamedResponse($preview->resource->stream(), Response::HTTP_OK, [ + 'Content-Type' => $preview->resource->mimeType(), + 'Content-Length' => (string) $preview->size, + 'ETag' => '"' . trim($preview->etag, '"') . '"', 'Cache-Control' => 'private, max-age=3600', 'X-Content-Type-Options' => 'nosniff', ]); diff --git a/lib/Manager.php b/lib/Manager.php index c236808..634e736 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace KTXM\MailManager; use InvalidArgumentException; -use KTXC\Preview\CachedPreview; +use KTXC\Preview\Preview; use KTXC\Preview\PreviewManager; use KTXC\Resource\ProviderManager; use KTXF\Preview\PreviewSource; @@ -1359,7 +1359,7 @@ class Manager { /** * 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; $size = $part['size'] ?? null; 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'); } + $attachmentIdentity = hash('sha256', json_encode($selector, JSON_THROW_ON_ERROR)); + return $this->previewManager->fetch($tenantId, new PreviewSource( sourceType: 'mail-attachment', - identity: (string) $targetEntity, + identity: (string) $targetEntity . ':' . $attachmentIdentity, // Attachments are immutable once delivered, so there is no revision to track; // existence and access are enforced by entityDownload() (via serviceFetch) below, // which only runs on a cache miss. @@ -1390,7 +1392,6 @@ class Manager { $targetEntity, $selector, ), - selector: hash('sha256', json_encode($selector, JSON_THROW_ON_ERROR)), ), $variant); }