This commit is contained in:
shimon
2022-07-24 10:05:24 +03:00
parent 02907f12f1
commit 64050337cf
8 changed files with 22 additions and 24 deletions
+1 -3
View File
@@ -10,6 +10,4 @@
debug/
app/sdks
dev/yasd_init.php
test/tmp/
tests/resources/disk-a/video-srt.srt
tests/resources/disk-a/video-srt.mp4
+1 -3
View File
@@ -2783,11 +2783,9 @@ $collections = [
],
'indexes' => [
[
'$id' => '_key_accessed',
'$id' => '_key_accessedAt',
'type' => Database::INDEX_KEY,
'attributes' => ['accessedAt'],
'lengths' => [],
'orders' => [],
],
],
],
+9 -4
View File
@@ -55,7 +55,8 @@ $avatarCallback = function (string $type, string $code, int $width, int $height,
App::get('/v1/avatars/credit-cards/:code')
->desc('Get Credit Card Icon')
->groups(['api', 'avatars', 'cache'])
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
@@ -73,7 +74,8 @@ App::get('/v1/avatars/credit-cards/:code')
App::get('/v1/avatars/browsers/:code')
->desc('Get Browser Icon')
->groups(['api', 'avatars', 'cache'])
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
@@ -91,7 +93,8 @@ App::get('/v1/avatars/browsers/:code')
App::get('/v1/avatars/flags/:code')
->desc('Get Country Flag')
->groups(['api', 'avatars', 'cache'])
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
@@ -110,6 +113,7 @@ App::get('/v1/avatars/flags/:code')
App::get('/v1/avatars/image')
->desc('Get Image from URL')
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
@@ -156,7 +160,8 @@ App::get('/v1/avatars/image')
App::get('/v1/avatars/favicon')
->desc('Get Favicon')
->groups(['api', 'avatars', 'cache'])
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
+2 -2
View File
@@ -800,8 +800,8 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId')
App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
->alias('/v1/storage/files/:fileId/preview', ['bucketId' => 'default'])
->desc('Get File Preview')
->groups(['api', 'storage', 'cache'])
->label('useCache', true)
->groups(['api', 'storage'])
->label('cache', true)
->label('scope', 'files.read')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'storage')
-1
View File
@@ -612,7 +612,6 @@ App::get('/.well-known/acme-challenge')
});
include_once __DIR__ . '/shared/api.php';
include_once __DIR__ . '/shared/cache.php';
include_once __DIR__ . '/shared/web.php';
foreach (Config::getParam('services', []) as $service) {
+7 -4
View File
@@ -47,7 +47,6 @@ App::init(function (App $utopia, Request $request, Response $response, Document
}
$closestLimit = null;
$roles = Authorization::getRoles();
$isPrivilegedUser = Auth::isPrivilegedUser($roles);
$isAppUser = Auth::isAppUser($roles);
@@ -116,7 +115,7 @@ App::init(function (App $utopia, Request $request, Response $response, Document
$deletes->setProject($project);
$database->setProject($project);
$useCache = $route->getLabel('useCache', false);
$useCache = $route->getLabel('cache', false);
if ($useCache) {
$key = md5($request->getURI() . $request->getServer('query_string'));
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()));
@@ -133,7 +132,11 @@ App::init(function (App $utopia, Request $request, Response $response, Document
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
}
$data = json_decode($data, true);
$response->file(base64_decode($data['payload']), $data['content-type'], $data['date'], 'hit');
$response->setContentType($data['content-type'])
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache
->addHeader('Expires', $data['date'])
->addHeader('X-Appwrite-Cache', 'hit')
->file(base64_decode($data['payload']));
}
}
}, ['utopia', 'request', 'response', 'project', 'user', 'events', 'audits', 'mails', 'usage', 'deletes', 'database', 'dbForProject', 'mode'], 'api');
@@ -261,7 +264,7 @@ App::shutdown(function (App $utopia, Request $request, Response $response, Docum
$route = $utopia->match($request);
$useCache = $route->getLabel('useCache', false);
$useCache = $route->getLabel('cache', false);
if ($useCache) {
$key = md5($request->getURI() . $request->getServer('query_string'));
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()));
-2
View File
@@ -695,8 +695,6 @@ App::setResource('layout', function ($locale) {
return $layout;
}, ['locale']);
App::setResource('cacheKey', fn () => '');
App::setResource('cachePath', fn () => '');
App::setResource('locale', fn() => new Locale(App::getEnv('_APP_LOCALE', 'en')));
// Queues
+2 -5
View File
@@ -381,7 +381,7 @@ class Response extends SwooleResponse
*
* return array
*/
public function output(Document $document, string $model): string | array
public function output(Document $document, string $model): array
{
$data = $document;
$model = $this->getModel($model);
@@ -453,10 +453,7 @@ class Response extends SwooleResponse
'payload' => $data
];
$this->setContentType($contentType)
->addHeader('Expires', $date)
->addHeader('X-Appwrite-Cache', $state)
->send($data);
$this->send($data);
}
/**