diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 4d5efdaedb..d6dfe9ccf1 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -1299,6 +1299,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/view') $size = $deviceForFiles->getFileSize($path); if ($size > APP_STORAGE_READ_BUFFER) { for ($i = 0; $i < ceil($size / MAX_OUTPUT_CHUNK_SIZE); $i++) { + $response->chunk( $deviceForFiles->read( $path, diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index d212de57ea..8871d13710 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -473,7 +473,9 @@ App::init() ); $timestamp = 60 * 60 * 24 * 30; $data = $cache->load($key, $timestamp); + if (!empty($data) && !$cacheLog->isEmpty()) { + $parts = explode('/', $cacheLog->getAttribute('resourceType')); $type = $parts[0] ?? null; @@ -718,7 +720,7 @@ App::shutdown() if ($useCache) { $resource = $resourceType = null; $data = $response->getPayload(); - + var_dump($response->getHeaders()); if (!empty($data['payload'])) { $pattern = $route->getLabel('cache.resource', null); @@ -735,6 +737,7 @@ App::shutdown() if(!empty($request->getRangeStart())) $keyParams .= '*'.$request->getRangeStart(); if(!empty($request->getRangeEnd())) $keyParams .= '*'.$request->getRangeEnd(); $keyParams .= '*'. APP_CACHE_BUSTER; + $key = md5($keyParams); $signature = md5($data['payload']); $cacheLog = Authorization::skip(fn () => $dbForProject->getDocument('cache', $key)); diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 6cc2639f51..4b5fdd30ce 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -694,6 +694,48 @@ class Response extends SwooleResponse $this->send($body); } + /** + * Output response + * + * Generate HTTP response output including the response header (+cookies) and body and prints them. + * + * @param string $body + * @param bool $end + * + * @return void + */ + public function bla(string $body = '', bool $end = false): void + { + if ($this->sent) { + return; + } + + if ($end) { + $this->sent = true; + } + + + + $this->addHeader('X-Debug-Speed', (string) (microtime(true) - $this->startTime)); + + $this + ->appendCookies() + ->appendHeaders(); + + $this->payload = [ + 'payload' => $body + ]; + + if (!$this->disablePayload) { + $this->write($body); + if ($end) { + $this->disablePayload(); + $this->end(); + } + } else { + $this->end(); + } + } /** * YAML *