1
0
Fork 0
mirror of synced 2024-10-02 02:07:04 +13:00

Merge branch 'feat-storage-buckets' into feat-large-file

This commit is contained in:
Damodar Lohani 2021-10-17 12:59:09 +05:45
commit c1aa49747a
4 changed files with 34 additions and 18 deletions

View file

@ -287,8 +287,8 @@ App::post('/v1/storage/buckets')
'adapter' => $adapter,
'encryption' => $encryption,
'antiVirus' => $antiVirus,
'$read' => $read,
'$write' => $write,
'$read' => $read ?? [],
'$write' => $write ?? [],
'search' => implode(' ', [$bucketId, $name]),
]));
} catch (Duplicate $th) {
@ -321,30 +321,31 @@ App::get('/v1/storage/buckets')
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
->param('limit', 25, new Range(0, 100), 'Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request.', true)
->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true)
->param('after', '', new UID(), 'ID of the bucket used as the starting point for the query, excluding the bucket itself. Should be used for efficient pagination when working with large sets of data.', true)
->param('cursor', '', new UID(), 'ID of the bucket used as the starting point for the query, excluding the bucket itself. Should be used for efficient pagination when working with large sets of data.', true)
->param('cursorDirection', Database::CURSOR_AFTER, new WhiteList([Database::CURSOR_AFTER, Database::CURSOR_BEFORE]), 'Direction of the cursor.', true)
->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
->inject('response')
->inject('dbForInternal')
->inject('usage')
->action(function ($search, $limit, $offset, $after, $orderType, $response, $dbForInternal, $usage) {
->action(function ($search, $limit, $offset, $cursor, $cursorDirection, $orderType, $response, $dbForInternal, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
/** @var Appwrite\Stats\Stats $usage */
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, $search)] : [];
if (!empty($after)) {
$afterBucket = $dbForInternal->getDocument('buckets', $after);
if (!empty($cursor)) {
$cursorBucket = $dbForInternal->getDocument('buckets', $cursor);
if ($afterBucket->isEmpty()) {
throw new Exception("Bucket '{$after}' for the 'after' value not found.", 400);
if ($cursorBucket->isEmpty()) {
throw new Exception("Bucket '{$cursor}' for the 'cursor' value not found.", 400);
}
}
$usage->setParam('storage.buckets.read', 1);
$response->dynamic(new Document([
'buckets' => $dbForInternal->find('buckets', $queries, $limit, $offset, [], [$orderType], $afterBucket ?? null),
'buckets' => $dbForInternal->find('buckets', $queries, $limit, $offset, [], [$orderType], $cursorBucket ?? null, $cursorDirection),
'sum' => $dbForInternal->count('buckets', $queries, APP_LIMIT_COUNT),
]), Response::MODEL_BUCKET_LIST);
});
@ -777,7 +778,7 @@ App::get('/v1/storage/buckets/:bucketId/files')
->inject('response')
->inject('dbForInternal')
->inject('usage')
->action(function ($bucketId, $search, $limit, $offset, $after, $orderType, $response, $dbForInternal, $usage) {
->action(function ($bucketId, $search, $limit, $offset, $cursor, $cursorDirection, $orderType, $response, $dbForInternal, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
/** @var Appwrite\Stats\Stats $usage */
@ -794,11 +795,11 @@ App::get('/v1/storage/buckets/:bucketId/files')
$queries[] = [new Query('name', Query::TYPE_SEARCH, [$search])];
}
if (!empty($after)) {
$afterFile = $dbForInternal->getDocument('bucket_' . $bucketId, $after);
if (!empty($cursor)) {
$cursorFile = $dbForInternal->getDocument('bucket_' . $bucketId, $cursor);
if ($afterFile->isEmpty()) {
throw new Exception("File '{$after}' for the 'after' value not found.", 400);
if ($cursorFile->isEmpty()) {
throw new Exception("File '{$cursor}' for the 'cursor' value not found.", 400);
}
}
@ -814,7 +815,7 @@ App::get('/v1/storage/buckets/:bucketId/files')
;
$response->dynamic(new Document([
'files' => $dbForInternal->find('bucket_' . $bucketId, $queries, $limit, $offset, [], [$orderType], $afterFile ?? null),
'files' => $dbForInternal->find('bucket_' . $bucketId, $queries, $limit, $offset, [], [$orderType], $cursorFile ?? null, $cursorDirection),
'sum' => $dbForInternal->count('bucket_' . $bucketId, $queries, APP_LIMIT_COUNT),
]), Response::MODEL_FILE_LIST);
});

View file

@ -53,6 +53,7 @@ class StorageConsoleClientTest extends Scope
], $this->getHeaders()), [
'bucketId' => 'unique()',
'name' => 'Test Bucket',
'permission' => 'file'
]);
$this->assertEquals(201, $bucket['headers']['status-code']);
$bucketId = $bucket['body']['$id'];

View file

@ -19,7 +19,21 @@ class StorageCustomClientTest extends Scope
/**
* Test for SUCCESS
*/
$file = $this->client->call(Client::METHOD_POST, '/storage/files', array_merge([
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], $this->getHeaders()), [
'bucketId' => 'unique()',
'name' => 'Test Bucket',
'permission' => 'file',
'read' => ['role:all'],
'write' => ['role:all'],
]);
$this->assertEquals(201, $bucket['headers']['status-code']);
$this->assertNotEmpty($bucket['body']['$id']);
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/'. $bucket['body']['$id'] . '/files', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [

View file

@ -92,7 +92,7 @@ class StorageCustomServerTest extends Scope
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'after' => $response['body']['buckets'][0]['$id']
'cursor' => $response['body']['buckets'][0]['$id']
]);
$this->assertEquals(200, $response['headers']['status-code']);