Skip to content

Commit 70e85fc

Browse files
authored
feat: use AssetService to stream response by URI (#212)
1 parent ca7164f commit 70e85fc

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

src/Controller/RequestController.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,39 +79,10 @@ public function serveProtectedAssetPathAction(Request $request, int $id, string
7979

8080
private function servePath(string $path, Request $request): Response
8181
{
82-
// @todo: replace this with Asset\Service::getStreamedResponseByUri() in P11
82+
$response = Model\Asset\Service::getStreamedResponseByUri($path);
8383

84-
$storage = $this->storage->get('thumbnail');
85-
$storagePath = urldecode($path);
86-
87-
if ($storage->fileExists($storagePath)) {
88-
$stream = $storage->readStream($storagePath);
89-
90-
return new StreamedResponse(function () use ($stream) {
91-
fpassthru($stream);
92-
}, Response::HTTP_OK, [
93-
'Content-Type' => $storage->mimeType($storagePath),
94-
'Content-Length' => $storage->fileSize($storagePath),
95-
]);
96-
}
97-
98-
$regExpression = sprintf(
99-
'/(%s)(%s)-thumb__(%s)__(%s)\/(%s)/',
100-
'.*',
101-
'video|image',
102-
'\d+',
103-
'[a-zA-Z0-9_\-]+',
104-
'.*'
105-
);
106-
107-
if (preg_match($regExpression, $path, $matches)) {
108-
return $this->forward('Pimcore\Bundle\CoreBundle\Controller\PublicServicesController::thumbnailAction', [
109-
'prefix' => ltrim($matches[1], '/'),
110-
'type' => $matches[2],
111-
'assetId' => $matches[3],
112-
'thumbnailName' => $matches[4],
113-
'filename' => $matches[5],
114-
]);
84+
if ($response instanceof StreamedResponse) {
85+
return $response;
11586
}
11687

11788
// no thumbnail path found, check if the original file has been requested

0 commit comments

Comments
 (0)