feat(storage): add after pagination
This commit is contained in:
parent
ca9dafddae
commit
8e6c415d01
1 changed files with 11 additions and 2 deletions
|
@ -168,17 +168,26 @@ App::get('/v1/storage/files')
|
||||||
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
|
->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('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('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 file used to return files listed after. Should be used for efficient pagination working with many files.', true)
|
||||||
->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
|
->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('dbForInternal')
|
->inject('dbForInternal')
|
||||||
->action(function ($search, $limit, $offset, $orderType, $response, $dbForInternal) {
|
->action(function ($search, $limit, $offset, $after, $orderType, $response, $dbForInternal) {
|
||||||
/** @var Appwrite\Utopia\Response $response */
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
/** @var Utopia\Database\Database $dbForInternal */
|
/** @var Utopia\Database\Database $dbForInternal */
|
||||||
|
|
||||||
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, $search)] : [];
|
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, $search)] : [];
|
||||||
|
|
||||||
|
if (!empty($after)) {
|
||||||
|
$afterFile = $dbForInternal->getDocument('files', $after);
|
||||||
|
|
||||||
|
if ($afterFile->isEmpty()) {
|
||||||
|
throw new Exception('File for after not found', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$response->dynamic(new Document([
|
$response->dynamic(new Document([
|
||||||
'files' => $dbForInternal->find('files', $queries, $limit, $offset, ['_id'], [$orderType]),
|
'files' => $dbForInternal->find('files', $queries, $limit, $offset, [], [$orderType], $afterFile ?? null),
|
||||||
'sum' => $dbForInternal->count('files', $queries, APP_LIMIT_COUNT),
|
'sum' => $dbForInternal->count('files', $queries, APP_LIMIT_COUNT),
|
||||||
]), Response::MODEL_FILE_LIST);
|
]), Response::MODEL_FILE_LIST);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue