1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00

Merge branch 'feat-265-realtime' of https://github.com/appwrite/appwrite into feat-265-realtime-usage

This commit is contained in:
Torsten Dittmann 2021-08-18 12:52:25 +02:00
commit 30025885f3
4 changed files with 34 additions and 15 deletions

View file

@ -33,7 +33,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
/** @var Utopia\Locale\Locale $locale */
/** @var bool $mode */
/** @var array $clients */
$domain = $request->getHostname();
$domains = Config::getParam('domains', []);
if (!array_key_exists($domain, $domains)) {
@ -98,7 +98,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
$refDomain = (!empty($protocol) ? $protocol : $request->getProtocol()).'://'.((\in_array($origin, $clients))
? $origin : 'localhost').(!empty($port) ? ':'.$port : '');
$refDomain = (!$route->getLabel('origin', false)) // This route is publicly accessible
? $refDomain
: (!empty($protocol) ? $protocol : $request->getProtocol()).'://'.$origin.(!empty($port) ? ':'.$port : '');
@ -119,7 +119,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
Config::setParam('domainVerification',
($selfDomain->getRegisterable() === $endDomain->getRegisterable()) &&
$endDomain->getRegisterable() !== '');
Config::setParam('cookieDomain', (
$request->getHostname() === 'localhost' ||
$request->getHostname() === 'localhost:'.$request->getPort() ||
@ -189,7 +189,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
&& empty($request->getHeader('x-appwrite-key', ''))) {
throw new Exception($originValidator->getDescription(), 403);
}
/*
* ACL Check
*/
@ -223,7 +223,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
if (!empty($authKey)) { // API Key authentication
// Check if given key match project API keys
$key = $project->search('secret', $authKey, $project->getAttribute('keys', []));
/*
* Try app auth when we have project key and no user
* Mock user to app and grant API key scopes in addition to default app scopes
@ -245,8 +245,8 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
}
}
foreach (Auth::getRoles($user) as $role) {
Authorization::setRole($role);
foreach (Auth::getRoles($user) as $authRole) {
Authorization::setRole($authRole);
}
// TDOO Check if user is root
@ -255,7 +255,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS !== $project->getCollection()) { // Check if permission is denied because project is missing
throw new Exception('Project not found', 404);
}
throw new Exception($user->getAttribute('email', 'User').' (role: '.\strtolower($roles[$role]['label']).') missing scope ('.$scope.')', 401);
}
@ -302,12 +302,12 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project) {
if (php_sapi_name() === 'cli') {
Console::error('[Error] Timestamp: '.date('c', time()));
if($route) {
Console::error('[Error] Method: '.$route->getMethod());
Console::error('[Error] URL: '.$route->getURL());
}
Console::error('[Error] Type: '.get_class($error));
Console::error('[Error] Message: '.$error->getMessage());
Console::error('[Error] File: '.$error->getFile());

View file

@ -169,10 +169,10 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
$attempts = 0;
$start = time();
/**
* Sending current connections to project channels on the console project every 5 seconds.
*/
Timer::tick(5000, function () use ($server, $register, $realtime) {
/**
* Sending current connections to project channels on the console project every 5 seconds.
*/
if ($realtime->hasSubscriber('console', 'role:member', 'project')) {
$db = $register->get('dbPool')->get();
$cache = $register->get('redisPool')->get();
@ -215,6 +215,25 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
]
];
$server->send($realtime->getSubscribers($event), json_encode($event['data']));
}
/**
* Sending test message for SDK E2E tests every 5 seconds.
*/
if ($realtime->hasSubscriber('console', 'role:guest', 'tests')) {
$payload = ['response' => 'WS:/v1/realtime:passed'];
$event = [
'project' => 'console',
'roles' => ['role:guest'],
'data' => [
'event' => 'test.event',
'channels' => ['tests'],
'timestamp' => time(),
'payload' => $payload
]
];
$server->send($realtime->getSubscribers($event), json_encode($event['data']));
}
});

View file

@ -45,7 +45,7 @@ use Appwrite\Utopia\Response\Model\Mock; // Keep last
use stdClass;
/**
* @method Response public function setStatusCode(int $code = 200)
* @method Response setStatusCode(int $code = 200)
*/
class Response extends SwooleResponse
{

View file

@ -632,7 +632,7 @@ trait RealtimeBase
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'name' => 'Test',
'runtime' => 'php-7.4',
'runtime' => 'php-8.0',
'execute' => ['*'],
'timeout' => 10,
]);