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);
|
||||
}
|
||||
|
||||
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',
|
||||
]);
|
||||
|
||||
+5
-4
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user