feat: blobs fetch
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -162,6 +162,7 @@ class DefaultController extends ControllerAbstract {
|
||||
'entity.copy' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
|
||||
'entity.submit' => $this->entitySubmit($tenantId, $userId, $data),
|
||||
'entity.download' => $this->entityDownload($tenantId, $userId, $data),
|
||||
'entity.blobs' => $this->entityBlobs($tenantId, $userId, $data),
|
||||
|
||||
default => throw new InvalidArgumentException(self::ERR_INVALID_OPERATION . $operation)
|
||||
};
|
||||
@@ -895,5 +896,43 @@ class DefaultController extends ControllerAbstract {
|
||||
'Cache-Control' => 'no-store',
|
||||
]);
|
||||
}
|
||||
|
||||
private function entityBlobs(string $tenantId, string $userId, array $data): mixed {
|
||||
if (!isset($data['target'])) {
|
||||
throw new InvalidArgumentException(self::ERR_MISSING_TARGET);
|
||||
}
|
||||
if (!is_string($data['target'])) {
|
||||
throw new InvalidArgumentException(self::ERR_INVALID_IDENTIFIER);
|
||||
}
|
||||
if (!isset($data['parts']) || !is_array($data['parts']) || $data['parts'] === []) {
|
||||
throw new InvalidArgumentException('At least one part selector is required');
|
||||
}
|
||||
|
||||
$target = ResourceIdentifier::fromString($data['target']);
|
||||
|
||||
$results = [];
|
||||
foreach ($data['parts'] as $part) {
|
||||
if (!is_array($part)) {
|
||||
throw new InvalidArgumentException('Invalid part selector');
|
||||
}
|
||||
|
||||
$resource = $this->mailManager->entityDownload($tenantId, $userId, $target, $part);
|
||||
|
||||
$bytes = '';
|
||||
foreach ($resource->stream() as $chunk) {
|
||||
$bytes .= $chunk;
|
||||
}
|
||||
|
||||
$results[] = [
|
||||
'source' => $data['target'],
|
||||
'part' => $part,
|
||||
'mime' => $resource->mimeType(),
|
||||
'filename' => $resource->filename(),
|
||||
'bytes' => base64_encode($bytes),
|
||||
];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user