response changes
This commit is contained in:
parent
966765dac7
commit
d09bf306ce
|
@ -47,8 +47,6 @@ $avatarCallback = function (string $type, string $code, int $width, int $height,
|
|||
$output = (empty($output)) ? $type : $output;
|
||||
$data = $image->output($output, $quality);
|
||||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 30)) . ' GMT')
|
||||
->addHeader('X-Appwrite-Cache', 'miss')
|
||||
->setContentType('image/png')
|
||||
->file($data, 'image/png');
|
||||
|
||||
|
@ -155,8 +153,6 @@ App::get('/v1/avatars/image')
|
|||
$data = $image->output($output, $quality);
|
||||
|
||||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 30)) . ' GMT')
|
||||
->addHeader('X-Appwrite-Cache', 'miss')
|
||||
->setContentType('image/png')
|
||||
->file($data, 'image/png');
|
||||
|
||||
|
@ -268,9 +264,10 @@ App::get('/v1/avatars/favicon')
|
|||
if (empty($data) || (\mb_substr($data, 0, 5) === '<html') || \mb_substr($data, 0, 5) === '<!doc') {
|
||||
throw new Exception('Favicon not found', 404, Exception::AVATAR_ICON_NOT_FOUND);
|
||||
}
|
||||
$response->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 30)) . ' GMT')
|
||||
->addHeader('X-Appwrite-Cache', 'miss')
|
||||
->file($data, 'image/png');
|
||||
$response
|
||||
->setContentType('image/x-icon')
|
||||
->file($data, 'image/x-icon')
|
||||
;
|
||||
}
|
||||
|
||||
$fetch = @\file_get_contents($outputHref, false);
|
||||
|
@ -285,8 +282,6 @@ App::get('/v1/avatars/favicon')
|
|||
$data = $image->output($output, $quality);
|
||||
|
||||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 30)) . ' GMT')
|
||||
->addHeader('X-Appwrite-Cache', 'miss')
|
||||
->setContentType('image/png')
|
||||
->file($data, 'image/png');
|
||||
|
||||
|
@ -329,8 +324,7 @@ App::get('/v1/avatars/qr')
|
|||
$image->crop((int) $size, (int) $size);
|
||||
|
||||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 30)) . ' GMT') // 30 days cache
|
||||
->addHeader('X-Appwrite-Cache', 'miss')
|
||||
->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));
|
||||
});
|
||||
|
|
|
@ -959,8 +959,6 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
|
|||
$contentType = (\array_key_exists($output, $outputs)) ? $outputs[$output] : $outputs['jpg'];
|
||||
|
||||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 30)) . ' GMT')
|
||||
->addHeader('X-Appwrite-Cache', 'miss')
|
||||
->setContentType($contentType)
|
||||
->file($data, $contentType);
|
||||
|
||||
|
|
|
@ -117,9 +117,10 @@ App::init(function (App $utopia, Request $request, Response $response, Document
|
|||
|
||||
$useCache = $route->getLabel('cache', false);
|
||||
if ($useCache) {
|
||||
$key = md5($request->getURI() . $request->getServer('query_string'));
|
||||
$key = md5($request->getURI() . implode('*', $request->getParams()));
|
||||
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()));
|
||||
$data = $cache->load($key, 60 * 60 * 24 * 30 * 1);
|
||||
$timestamp = 60 * 60 * 24 * 30;
|
||||
$data = $cache->load($key, $timestamp);
|
||||
if (!empty($data)) {
|
||||
$cacheLog = Authorization::skip(fn () => $dbForProject->getDocument('cache', $key));
|
||||
if ($cacheLog->isEmpty()) {
|
||||
|
@ -133,12 +134,12 @@ App::init(function (App $utopia, Request $request, Response $response, Document
|
|||
}
|
||||
|
||||
$data = json_decode($data, true);
|
||||
|
||||
$expire = \date('D, d M Y H:i:s', \time() + $timestamp) . ' GMT';
|
||||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 30)) . ' GMT')
|
||||
->addHeader('Expires', $expire)
|
||||
->addHeader('X-Appwrite-Cache', 'hit')
|
||||
->setContentType($data['content-type'])
|
||||
->file(base64_decode($data['payload']), $data['content-type'], $data['date']);
|
||||
->file(base64_decode($data['payload']), $data['content-type']);
|
||||
}
|
||||
}
|
||||
}, ['utopia', 'request', 'response', 'project', 'user', 'events', 'audits', 'mails', 'usage', 'deletes', 'database', 'dbForProject', 'mode'], 'api');
|
||||
|
@ -268,9 +269,10 @@ App::shutdown(function (App $utopia, Request $request, Response $response, Docum
|
|||
|
||||
$useCache = $route->getLabel('cache', false);
|
||||
if ($useCache) {
|
||||
$key = md5($request->getURI() . $request->getServer('query_string'));
|
||||
$key = md5($request->getURI() . implode('*', $request->getParams()));
|
||||
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()));
|
||||
$data = $response->getPayload();
|
||||
$timestamp = 60 * 60 * 24 * 30;
|
||||
if (!empty($data)) {
|
||||
$cacheLog = $dbForProject->getDocument('cache', $key);
|
||||
if ($cacheLog->isEmpty()) {
|
||||
|
@ -282,9 +284,14 @@ App::shutdown(function (App $utopia, Request $request, Response $response, Docum
|
|||
$cacheLog->setAttribute('accessedAt', time());
|
||||
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
|
||||
}
|
||||
if (!empty($data['payload'])) {
|
||||
$data['payload'] = base64_encode($data['payload']);
|
||||
$cache->save($key, json_encode($data));
|
||||
}
|
||||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $timestamp) . ' GMT')
|
||||
->addHeader('X-Appwrite-Cache', 'miss');
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
|
@ -460,7 +460,6 @@ class Response extends SwooleResponse
|
|||
'content-type' => $contentType,
|
||||
'payload' => $data
|
||||
];
|
||||
|
||||
$this->send($data);
|
||||
}
|
||||
|
||||
|
@ -491,7 +490,7 @@ class Response extends SwooleResponse
|
|||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPayload(): string | array
|
||||
public function getPayload(): array
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue