diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index d1bcf1e3f7..ff01b8efe3 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -49,7 +49,7 @@ $avatarCallback = function (string $type, string $code, int $width, int $height, $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') ->setContentType('image/png') - ->send($data) + ->file($data) ; unset($image); }; @@ -156,7 +156,7 @@ App::get('/v1/avatars/image') $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') ->setContentType('image/png') - ->send($data) + ->file($data) ; unset($image); }); @@ -287,7 +287,7 @@ App::get('/v1/avatars/favicon') $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') ->setContentType('image/png') - ->send($data) + ->file($data) ; unset($image); }); @@ -329,7 +329,7 @@ App::get('/v1/avatars/qr') $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache ->setContentType('image/png') - ->send($image->output('png', 9)) + ->file($image->output('png', 9)) ; }); @@ -411,6 +411,6 @@ App::get('/v1/avatars/initials') $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache ->setContentType('image/png') - ->send($image->getImageBlob()) + ->file($image->getImageBlob()) ; }); diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index cbae4a4530..100028365b 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -960,7 +960,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') ->setContentType($contentType) - ->send($data) + ->file($data) ; unset($image); }); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index f16c244472..61a5d54c23 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -307,7 +307,7 @@ App::shutdown() $useCache = $route->getLabel('cache', false); if ($useCache) { $data = $response->getPayload(); - if (!empty($data)) { + if (!empty($data['payload'])) { $key = md5($request->getURI() . implode('*', $request->getParams())); $cacheLog = $dbForProject->getDocument('cache', $key); if ($cacheLog->isEmpty()) { @@ -319,11 +319,14 @@ App::shutdown() $cacheLog->setAttribute('accessedAt', \time()); Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog)); } - if (!empty($data['payload'])) { - $data['payload'] = base64_encode($data['payload']); - $cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId())); - $cache->save($key, json_encode($data)); - } + + $data = [ + 'content-type' => $response->getContentType(), + 'payload' => base64_encode($data['payload']), + ] ; + + $cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId())); + $cache->save($key, json_encode($data)); } } diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index afcb2288a1..391278d01b 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -449,7 +449,6 @@ class Response extends SwooleResponse return $this->payload; } - /** * Output response * @@ -459,17 +458,15 @@ class Response extends SwooleResponse * * @return void */ - public function send(string $body = ''): void + public function file(string $body = ''): void { $this->payload = [ - 'content-type' => $this->getContentType(), - 'payload' => $body + 'payload' => $body ]; - parent::send($body); + $this->send($body); } - /** * YAML * @@ -501,7 +498,6 @@ class Response extends SwooleResponse return $this->payload; } - /** * Function to set a response filter *