Skip to content

Commit

Permalink
fixup! feat(dav): introduce paginate with custom headers
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
  • Loading branch information
Altahrim committed Nov 15, 2024
1 parent e35b1ab commit 1d741cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions apps/dav/lib/Paginate/PaginateCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
/**
* @param string $uri
* @param \Iterator $items
* @return array{'token': int, 'count': int}
* @return array{'token': string, 'count': int}
*/
public function store(string $uri, \Iterator $items): array {
$token = $this->random->generate(32);
Expand All @@ -45,7 +45,7 @@ public function store(string $uri, \Iterator $items): array {

$count = 0;
foreach ($items as $item) {
$value = json_encode($item);
$value = serialize($item);
$query->setParameter('index', $count, IQueryBuilder::PARAM_INT);
$query->setParameter('value', $value);
$query->executeStatement();
Expand Down Expand Up @@ -73,7 +73,7 @@ public function get(string $url, string $token, int $offset, int $count) {

$result = $query->executeQuery();
return array_map(function (string $entry) {
return json_decode($entry, true);
return unserialize($entry);
}, $result->fetchAll(\PDO::FETCH_COLUMN));
}

Expand Down
11 changes: 6 additions & 5 deletions apps/dav/lib/Paginate/PaginatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use Sabre\HTTP\ResponseInterface;

class PaginatePlugin extends ServerPlugin {
public const PAGINATE_HEADER = 'x-nc-paginate';
public const PAGINATE_TOTAL_HEADER = 'x-nc-paginate-total';
public const PAGINATE_TOKEN_HEADER = 'x-nc-paginate-token';
public const PAGINATE_OFFSET_HEADER = 'x-nc-paginate-offset';
public const PAGINATE_COUNT_HEADER = 'x-nc-paginate-count';
public const PAGINATE_HEADER = 'X-NC-Paginate';
public const PAGINATE_TOTAL_HEADER = 'X-NC-Paginate-Total';
public const PAGINATE_TOKEN_HEADER = 'X-NC-Paginate-Token';
public const PAGINATE_OFFSET_HEADER = 'X-NC-Paginate-Offset';
public const PAGINATE_COUNT_HEADER = 'X-NC-Paginate-Count';

/** @var Server */
private $server;
Expand Down Expand Up @@ -86,6 +86,7 @@ public function onMethod(RequestInterface $request, ResponseInterface $response)

$data = $this->server->generateMultiStatus($items, $minimal);
$response->setBody($data);

return false;
}
}
Expand Down

0 comments on commit 1d741cb

Please sign in to comment.