1
0
Fork 0
mirror of synced 2024-07-01 20:50:49 +12:00

some fixes

This commit is contained in:
shimon 2022-08-15 16:55:11 +03:00
parent 67d12d3120
commit df0bdeb8a3
5 changed files with 21 additions and 5394 deletions

View file

@ -2811,6 +2811,13 @@ $collections = [
'lengths' => [],
'orders' => [],
],
[
'$id' => '_key_resource',
'type' => Database::INDEX_KEY,
'attributes' => ['resource'],
'lengths' => [],
'orders' => [],
],
],
],
'files' => [

View file

@ -59,6 +59,7 @@ App::get('/v1/avatars/credit-cards/:code')
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('cache.resource', 'avatar/credit-card')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
->label('sdk.method', 'getCreditCard')
@ -78,6 +79,7 @@ App::get('/v1/avatars/browsers/:code')
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('cache.resource', 'avatar/browser')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
->label('sdk.method', 'getBrowser')
@ -97,6 +99,7 @@ App::get('/v1/avatars/flags/:code')
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('cache.resource', 'avatar/flag')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
->label('sdk.method', 'getFlag')
@ -116,6 +119,7 @@ App::get('/v1/avatars/image')
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('cache.resource', 'avatar/image')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
->label('sdk.method', 'getImage')
@ -166,6 +170,7 @@ App::get('/v1/avatars/favicon')
->groups(['api', 'avatars'])
->label('cache', true)
->label('scope', 'avatars.read')
->label('cache.resource', 'avatar/favicon')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
->label('sdk.method', 'getFavicon')
@ -296,6 +301,7 @@ App::get('/v1/avatars/qr')
->desc('Get QR Code')
->groups(['api', 'avatars'])
->label('scope', 'avatars.read')
->label('cache.resource', 'avatar/qr')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
->label('sdk.method', 'getQR')
@ -337,6 +343,7 @@ App::get('/v1/avatars/initials')
->desc('Get User Initials')
->groups(['api', 'avatars'])
->label('scope', 'avatars.read')
->label('cache.resource', 'avatar/initials')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'avatars')
->label('sdk.method', 'getInitials')

View file

@ -9,10 +9,7 @@ use Appwrite\Utopia\Database\Validator\CustomId;
use Appwrite\OpenSSL\OpenSSL;
use Appwrite\Stats\Stats;
use Appwrite\Utopia\Response;
use phpDocumentor\Reflection\Project;
use Utopia\App;
use Utopia\Cache\Adapter\Filesystem;
use Utopia\Cache\Cache;
use Utopia\Config\Config;
use Utopia\Database\Database;
use Utopia\Database\Document;

View file

@ -130,22 +130,12 @@ App::init()
if ($useCache) {
$key = md5($request->getURI() . implode('*', $request->getParams()));
$cache = new Cache(new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()));
$cache = new Cache(
new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId())
);
$timestamp = 60 * 60 * 24 * 30;
$data = $cache->load($key, $timestamp);
if (!empty($data)) {
$cacheLog = Authorization::skip(fn() => $dbForProject->getDocument('cache', $key));
if ($cacheLog->isEmpty()) {
Authorization::skip(fn() => $dbForProject->createDocument('cache', new Document([
'$id' => $key,
'accessedAt' => \time(),
])));
} elseif (date('Y/m/d', time()) > date('Y/m/d', $cacheLog->getAttribute('accessedAt'))) {
$cacheLog->setAttribute('accessedAt', \time());
Authorization::skip(fn() => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
}
$data = json_decode($data, true);
$response
@ -379,10 +369,10 @@ App::shutdown()
&& $project->getId()
&& $mode !== APP_MODE_ADMIN // TODO: add check to make sure user is admin
&& !empty($route->getLabel('sdk.namespace', null))
) { // Don't calculate console usage on admin mode
) {
$usage
->setParam('networkRequestSize', $request->getSize() + $usage->getParam('storage'))
->setParam('networkResponseSize', $response->getSize())
->submit();
->setParam('networkRequestSize', $request->getSize() + $usage->getParam('storage'))
->setParam('networkResponseSize', $response->getSize())
->submit();
}
});

5374
composer.lock generated

File diff suppressed because it is too large Load diff