Merge branch 'swoole-and-functions' of github.com:appwrite/appwrite into feat-add-webhook-events-to-the-users-service

This commit is contained in:
Eldad Fux
2020-09-10 23:55:29 +03:00
120 changed files with 21668 additions and 23341 deletions
+108 -87
View File
@@ -2,7 +2,6 @@
use Utopia\App;
use Utopia\Exception;
use Utopia\Response;
use Utopia\Validator\ArrayList;
use Utopia\Validator\Boolean;
use Utopia\Validator\Text;
@@ -19,6 +18,7 @@ use Appwrite\Database\Validator\UID;
use Appwrite\OpenSSL\OpenSSL;
use Appwrite\Network\Validator\CNAME;
use Appwrite\Network\Validator\Domain as DomainValidator;
use Appwrite\Utopia\Response;
use Cron\CronExpression;
App::post('/v1/projects')
@@ -39,7 +39,7 @@ App::post('/v1/projects')
->param('legalAddress', '', function () { return new Text(256); }, 'Project legal Address. Max length: 256 chars.', true)
->param('legalTaxId', '', function () { return new Text(256); }, 'Project legal Tax ID. Max length: 256 chars.', true)
->action(function ($name, $teamId, $description, $logo, $url, $legalName, $legalCountry, $legalState, $legalCity, $legalAddress, $legalTaxId, $response, $consoleDB, $projectDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
/** @var Appwrite\Database\Database $projectDB */
@@ -97,7 +97,7 @@ App::get('/v1/projects')
->param('offset', 0, function () { return new Range(0, 2000); }, 'Results offset. The default value is 0. Use this param to manage pagination.', true)
->param('orderType', 'ASC', function () { return new WhiteList(['ASC', 'DESC'], true); }, 'Order result by ASC or DESC order.', true)
->action(function ($search, $limit, $offset, $orderType, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$results = $consoleDB->getCollection([
@@ -133,7 +133,7 @@ App::get('/v1/projects/:projectId')
->label('sdk.method', 'get')
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
->action(function ($projectId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -161,9 +161,9 @@ App::get('/v1/projects/:projectId/usage')
->label('sdk.namespace', 'projects')
->label('sdk.method', 'getUsage')
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
->param('range', 'last30', function () { return new WhiteList(['daily', 'monthly', 'last30', 'last90'], true); }, 'Date range.', true)
->param('range', '30d', function () { return new WhiteList(['24h', '7d', '30d', '90d']); }, 'Date range.', true)
->action(function ($projectId, $range, $response, $consoleDB, $projectDB, $register) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
/** @var Appwrite\Database\Database $projectDB */
/** @var Utopia\Registry\Registry $register */
@@ -175,37 +175,33 @@ App::get('/v1/projects/:projectId/usage')
}
$period = [
'daily' => [
'start' => DateTime::createFromFormat('U', \strtotime('today')),
'end' => DateTime::createFromFormat('U', \strtotime('tomorrow')),
'group' => '1m',
'24h' => [
'start' => DateTime::createFromFormat('U', \strtotime('-24 hours')),
'end' => DateTime::createFromFormat('U', \strtotime('+1 hour')),
'group' => '30m',
],
'monthly' => [
'start' => DateTime::createFromFormat('U', \strtotime('midnight first day of this month')),
'end' => DateTime::createFromFormat('U', \strtotime('midnight last day of this month')),
'7d' => [
'start' => DateTime::createFromFormat('U', \strtotime('-7 days')),
'end' => DateTime::createFromFormat('U', \strtotime('now')),
'group' => '1d',
],
'last30' => [
'30d' => [
'start' => DateTime::createFromFormat('U', \strtotime('-30 days')),
'end' => DateTime::createFromFormat('U', \strtotime('tomorrow')),
'end' => DateTime::createFromFormat('U', \strtotime('now')),
'group' => '1d',
],
'last90' => [
'90d' => [
'start' => DateTime::createFromFormat('U', \strtotime('-90 days')),
'end' => DateTime::createFromFormat('U', \strtotime('today')),
'end' => DateTime::createFromFormat('U', \strtotime('now')),
'group' => '1d',
],
// 'yearly' => [
// 'start' => DateTime::createFromFormat('U', strtotime('midnight first day of january')),
// 'end' => DateTime::createFromFormat('U', strtotime('midnight last day of december')),
// 'group' => '4w',
// ],
];
$client = $register->get('influxdb');
$requests = [];
$network = [];
$functions = [];
if ($client) {
$start = $period[$range]['start']->format(DateTime::RFC3339);
@@ -233,6 +229,17 @@ App::get('/v1/projects/:projectId/usage')
'date' => \strtotime($point['time']),
];
}
// Functions
$result = $database->query('SELECT sum(value) AS "value" FROM "appwrite_usage_executions_all" WHERE time > \''.$start.'\' AND time < \''.$end.'\' AND "metric_type"=\'counter\' AND "project"=\''.$project->getId().'\' GROUP BY time('.$period[$range]['group'].') FILL(null)');
$points = $result->getPoints();
foreach ($points as $point) {
$functions[] = [
'value' => (!empty($point['value'])) ? $point['value'] : 0,
'date' => \strtotime($point['time']),
];
}
}
// Users
@@ -277,6 +284,7 @@ App::get('/v1/projects/:projectId/usage')
$tasksTotal = \count($project->getAttribute('tasks', []));
$response->json([
'range' => $range,
'requests' => [
'data' => $requests,
'total' => \array_sum(\array_map(function ($item) {
@@ -289,6 +297,12 @@ App::get('/v1/projects/:projectId/usage')
return $item['value'];
}, $network)),
],
'functions' => [
'data' => $functions,
'total' => \array_sum(\array_map(function ($item) {
return $item['value'];
}, $functions)),
],
'collections' => [
'data' => $collections,
'total' => $collectionsTotal,
@@ -318,7 +332,7 @@ App::get('/v1/projects/:projectId/usage')
) +
$projectDB->getCount(
[
'attribute' => 'codeSize',
'attribute' => 'size',
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_TAGS,
],
@@ -346,7 +360,7 @@ App::patch('/v1/projects/:projectId')
->param('legalAddress', '', function () { return new Text(256); }, 'Project legal address. Max length: 256 chars.', true)
->param('legalTaxId', '', function () { return new Text(256); }, 'Project legal tax ID. Max length: 256 chars.', true)
->action(function ($projectId, $name, $description, $logo, $url, $legalName, $legalCountry, $legalState, $legalCity, $legalAddress, $legalTaxId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -386,7 +400,7 @@ App::patch('/v1/projects/:projectId/oauth2')
->param('appId', '', function () { return new Text(256); }, 'Provider app ID. Max length: 256 chars.', true)
->param('secret', '', function () { return new text(512); }, 'Provider secret key. Max length: 512 chars.', true)
->action(function ($projectId, $provider, $appId, $secret, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -427,7 +441,7 @@ App::delete('/v1/projects/:projectId')
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
->param('password', '', function () { return new UID(); }, 'Your user password for confirmation. Must be between 6 to 32 chars.')
->action(function ($projectId, $password, $response, $user, $consoleDB, $deletes) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Document $user */
/** @var Appwrite\Database\Database $consoleDB */
/** @var Appwrite\Event\Event $deletes */
@@ -481,7 +495,7 @@ App::post('/v1/projects/:projectId/webhooks')
->param('httpUser', '', function () { return new Text(256); }, 'Webhook HTTP user. Max length: 256 chars.', true)
->param('httpPass', '', function () { return new Text(256); }, 'Webhook HTTP password. Max length: 256 chars.', true)
->action(function ($projectId, $name, $events, $url, $security, $httpUser, $httpPass, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -528,10 +542,8 @@ App::post('/v1/projects/:projectId/webhooks')
throw new Exception('Failed saving project to DB', 500);
}
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->json($webhook->getArrayCopy())
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($webhook, Response::MODEL_WEBHOOK);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/webhooks')
@@ -542,7 +554,7 @@ App::get('/v1/projects/:projectId/webhooks')
->label('sdk.method', 'listWebhooks')
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
->action(function ($projectId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -565,7 +577,10 @@ App::get('/v1/projects/:projectId/webhooks')
$webhook->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
}
$response->json($webhooks);
$response->dynamic(new Document([
'sum' => count($webhooks),
'webhooks' => $webhooks
]), Response::MODEL_WEBHOOK_LIST);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/webhooks/:webhookId')
@@ -577,7 +592,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('webhookId', null, function () { return new UID(); }, 'Webhook unique ID.')
->action(function ($projectId, $webhookId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -599,7 +614,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId')
$webhook->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
}
$response->json($webhook->getArrayCopy());
$response->dynamic($webhook, Response::MODEL_WEBHOOK);
}, ['response', 'consoleDB']);
App::put('/v1/projects/:projectId/webhooks/:webhookId')
@@ -617,7 +632,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId')
->param('httpUser', '', function () { return new Text(256); }, 'Webhook HTTP user. Max length: 256 chars.', true)
->param('httpPass', '', function () { return new Text(256); }, 'Webhook HTTP password. Max length: 256 chars.', true)
->action(function ($projectId, $webhookId, $name, $events, $url, $security, $httpUser, $httpPass, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -657,7 +672,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId')
throw new Exception('Failed saving webhook to DB', 500);
}
$response->json($webhook->getArrayCopy());
$response->dynamic($webhook, Response::MODEL_WEBHOOK);
}, ['response', 'consoleDB']);
App::delete('/v1/projects/:projectId/webhooks/:webhookId')
@@ -669,7 +684,7 @@ App::delete('/v1/projects/:projectId/webhooks/:webhookId')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('webhookId', null, function () { return new UID(); }, 'Webhook unique ID.')
->action(function ($projectId, $webhookId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -703,7 +718,7 @@ App::post('/v1/projects/:projectId/keys')
->param('name', null, function () { return new Text(128); }, 'Key name. Max length: 128 chars.')
->param('scopes', null, function () { return new ArrayList(new WhiteList(Config::getParam('scopes'), true)); }, 'Key scopes list.')
->action(function ($projectId, $name, $scopes, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -735,10 +750,8 @@ App::post('/v1/projects/:projectId/keys')
throw new Exception('Failed saving project to DB', 500);
}
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->json($key->getArrayCopy())
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($key, Response::MODEL_KEY);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/keys')
@@ -749,7 +762,7 @@ App::get('/v1/projects/:projectId/keys')
->label('sdk.method', 'listKeys')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->action(function ($projectId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -758,7 +771,12 @@ App::get('/v1/projects/:projectId/keys')
throw new Exception('Project not found', 404);
}
$response->json($project->getAttribute('keys', [])); //FIXME make sure array objects return correctly
$keys = $project->getAttribute('keys', []);
$response->dynamic(new Document([
'sum' => count($keys),
'keys' => $keys
]), Response::MODEL_KEY_LIST);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/keys/:keyId')
@@ -782,7 +800,7 @@ App::get('/v1/projects/:projectId/keys/:keyId')
throw new Exception('Key not found', 404);
}
$response->json($key->getArrayCopy());
$response->dynamic($key, Response::MODEL_KEY);
}, ['response', 'consoleDB']);
App::put('/v1/projects/:projectId/keys/:keyId')
@@ -796,7 +814,7 @@ App::put('/v1/projects/:projectId/keys/:keyId')
->param('name', null, function () { return new Text(128); }, 'Key name. Max length: 128 chars.')
->param('scopes', null, function () { return new ArrayList(new WhiteList(Config::getParam('scopes'), true)); }, 'Key scopes list')
->action(function ($projectId, $keyId, $name, $scopes, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -820,7 +838,7 @@ App::put('/v1/projects/:projectId/keys/:keyId')
throw new Exception('Failed saving key to DB', 500);
}
$response->json($key->getArrayCopy());
$response->dynamic($key, Response::MODEL_KEY);
}, ['response', 'consoleDB']);
App::delete('/v1/projects/:projectId/keys/:keyId')
@@ -832,7 +850,7 @@ App::delete('/v1/projects/:projectId/keys/:keyId')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('keyId', null, function () { return new UID(); }, 'Key unique ID.')
->action(function ($projectId, $keyId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -873,7 +891,7 @@ App::post('/v1/projects/:projectId/tasks')
->param('httpUser', '', function () { return new Text(256); }, 'Task HTTP user. Max length: 256 chars.', true)
->param('httpPass', '', function () { return new Text(256); }, 'Task HTTP password. Max length: 256 chars.', true)
->action(function ($projectId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -935,10 +953,8 @@ App::post('/v1/projects/:projectId/tasks')
ResqueScheduler::enqueueAt($next, 'v1-tasks', 'TasksV1', $task->getArrayCopy());
}
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->json($task->getArrayCopy())
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($task, Response::MODEL_TASK);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/tasks')
@@ -949,7 +965,7 @@ App::get('/v1/projects/:projectId/tasks')
->label('sdk.method', 'listTasks')
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
->action(function ($projectId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -972,7 +988,10 @@ App::get('/v1/projects/:projectId/tasks')
$task->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
}
$response->json($tasks);
$response->dynamic(new Document([
'sum' => count($tasks),
'tasks' => $tasks
]), Response::MODEL_TASK_LIST);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/tasks/:taskId')
@@ -984,7 +1003,7 @@ App::get('/v1/projects/:projectId/tasks/:taskId')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('taskId', null, function () { return new UID(); }, 'Task unique ID.')
->action(function ($projectId, $taskId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1006,7 +1025,7 @@ App::get('/v1/projects/:projectId/tasks/:taskId')
$task->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
}
$response->json($task->getArrayCopy());
$response->dynamic($task, Response::MODEL_TASK);
}, ['response', 'consoleDB']);
App::put('/v1/projects/:projectId/tasks/:taskId')
@@ -1027,7 +1046,7 @@ App::put('/v1/projects/:projectId/tasks/:taskId')
->param('httpUser', '', function () { return new Text(256); }, 'Task HTTP user. Max length: 256 chars.', true)
->param('httpPass', '', function () { return new Text(256); }, 'Task HTTP password. Max length: 256 chars.', true)
->action(function ($projectId, $taskId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1079,7 +1098,7 @@ App::put('/v1/projects/:projectId/tasks/:taskId')
ResqueScheduler::enqueueAt($next, 'v1-tasks', 'TasksV1', $task->getArrayCopy());
}
$response->json($task->getArrayCopy());
$response->dynamic($task, Response::MODEL_TASK);
}, ['response', 'consoleDB']);
App::delete('/v1/projects/:projectId/tasks/:taskId')
@@ -1091,7 +1110,7 @@ App::delete('/v1/projects/:projectId/tasks/:taskId')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('taskId', null, function () { return new UID(); }, 'Task unique ID.')
->action(function ($projectId, $taskId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1128,7 +1147,7 @@ App::post('/v1/projects/:projectId/platforms')
->param('store', '', function () { return new Text(256); }, 'App store or Google Play store ID. Max length: 256 chars.', true)
->param('hostname', '', function () { return new Text(256); }, 'Platform client hostname. Max length: 256 chars.', true)
->action(function ($projectId, $type, $name, $key, $store, $hostname, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1164,10 +1183,8 @@ App::post('/v1/projects/:projectId/platforms')
throw new Exception('Failed saving project to DB', 500);
}
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->json($platform->getArrayCopy())
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($platform, Response::MODEL_PLATFORM);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/platforms')
@@ -1178,7 +1195,7 @@ App::get('/v1/projects/:projectId/platforms')
->label('sdk.method', 'listPlatforms')
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
->action(function ($projectId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1189,7 +1206,10 @@ App::get('/v1/projects/:projectId/platforms')
$platforms = $project->getAttribute('platforms', []);
$response->json($platforms);
$response->dynamic(new Document([
'sum' => count($platforms),
'platforms' => $platforms
]), Response::MODEL_PLATFORM_LIST);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/platforms/:platformId')
@@ -1201,7 +1221,7 @@ App::get('/v1/projects/:projectId/platforms/:platformId')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('platformId', null, function () { return new UID(); }, 'Platform unique ID.')
->action(function ($projectId, $platformId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1216,7 +1236,7 @@ App::get('/v1/projects/:projectId/platforms/:platformId')
throw new Exception('Platform not found', 404);
}
$response->json($platform->getArrayCopy());
$response->dynamic($platform, Response::MODEL_PLATFORM);
}, ['response', 'consoleDB']);
App::put('/v1/projects/:projectId/platforms/:platformId')
@@ -1232,7 +1252,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId')
->param('store', '', function () { return new Text(256); }, 'App store or Google Play store ID. Max length: 256 chars.', true)
->param('hostname', '', function () { return new Text(256); }, 'Platform client URL. Max length: 256 chars.', true)
->action(function ($projectId, $platformId, $name, $key, $store, $hostname, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1259,7 +1279,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId')
throw new Exception('Failed saving platform to DB', 500);
}
$response->json($platform->getArrayCopy());
$response->dynamic($platform, Response::MODEL_PLATFORM);
}, ['response', 'consoleDB']);
App::delete('/v1/projects/:projectId/platforms/:platformId')
@@ -1271,7 +1291,7 @@ App::delete('/v1/projects/:projectId/platforms/:platformId')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('platformId', null, function () { return new UID(); }, 'Platform unique ID.')
->action(function ($projectId, $platformId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1304,7 +1324,7 @@ App::post('/v1/projects/:projectId/domains')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('domain', null, function () { return new DomainValidator(); }, 'Domain name.')
->action(function ($projectId, $domain, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1353,10 +1373,8 @@ App::post('/v1/projects/:projectId/domains')
throw new Exception('Failed saving project to DB', 500);
}
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->json($domain->getArrayCopy())
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($domain, Response::MODEL_DOMAIN);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/domains')
@@ -1367,7 +1385,7 @@ App::get('/v1/projects/:projectId/domains')
->label('sdk.method', 'listDomains')
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
->action(function ($projectId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1377,8 +1395,11 @@ App::get('/v1/projects/:projectId/domains')
}
$domains = $project->getAttribute('domains', []);
$response->json($domains);
$response->dynamic(new Document([
'sum' => count($domains),
'domains' => $domains
]), Response::MODEL_DOMAIN_LIST);
}, ['response', 'consoleDB']);
App::get('/v1/projects/:projectId/domains/:domainId')
@@ -1390,7 +1411,7 @@ App::get('/v1/projects/:projectId/domains/:domainId')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('domainId', null, function () { return new UID(); }, 'Domain unique ID.')
->action(function ($projectId, $domainId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1405,7 +1426,7 @@ App::get('/v1/projects/:projectId/domains/:domainId')
throw new Exception('Domain not found', 404);
}
$response->json($domain->getArrayCopy());
$response->dynamic($domain, Response::MODEL_DOMAIN);
}, ['response', 'consoleDB']);
App::patch('/v1/projects/:projectId/domains/:domainId/verification')
@@ -1417,7 +1438,7 @@ App::patch('/v1/projects/:projectId/domains/:domainId/verification')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('domainId', null, function () { return new UID(); }, 'Domain unique ID.')
->action(function ($projectId, $domainId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);
@@ -1439,7 +1460,7 @@ App::patch('/v1/projects/:projectId/domains/:domainId/verification')
}
if ($domain->getAttribute('verification') === true) {
return $response->json($domain->getArrayCopy());
return $response->dynamic($domain, Response::MODEL_DOMAIN);
}
// Verify Domain with DNS records
@@ -1463,7 +1484,7 @@ App::patch('/v1/projects/:projectId/domains/:domainId/verification')
'domain' => $domain->getAttribute('domain'),
]);
$response->json($domain->getArrayCopy());
$response->dynamic($domain, Response::MODEL_DOMAIN);
}, ['response', 'consoleDB']);
App::delete('/v1/projects/:projectId/domains/:domainId')
@@ -1475,7 +1496,7 @@ App::delete('/v1/projects/:projectId/domains/:domainId')
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
->param('domainId', null, function () { return new UID(); }, 'Domain unique ID.')
->action(function ($projectId, $domainId, $response, $consoleDB) {
/** @var Utopia\Response $response */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $consoleDB */
$project = $consoleDB->getDocument($projectId);