refactor: simplify preview generation

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-29 18:44:52 -04:00
parent 59838af3db
commit 6af5704e5e
2 changed files with 9 additions and 8 deletions
+5 -4
View File
@@ -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);
}