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 <[email protected]>
  • Loading branch information
Altahrim committed Nov 15, 2024
1 parent e35b1ab commit 08fffbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 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
13 changes: 7 additions & 6 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 @@ -60,7 +60,7 @@ public function onMultiStatus(&$fileProperties): void {
$fileProperties = $copyIterator->getFirstItems();
$this->server->httpResponse->addHeader(self::PAGINATE_HEADER, 'true');
$this->server->httpResponse->addHeader(self::PAGINATE_TOKEN_HEADER, $token);
$this->server->httpResponse->addHeader(self::PAGINATE_TOTAL_HEADER, $count);
$this->server->httpResponse->addHeader(self::PAGINATE_TOTAL_HEADER, (string)$count);
}
}

Expand All @@ -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 08fffbc

Please sign in to comment.