From 08fffbc650ff83e01663c68bc056ad9329d01bfb Mon Sep 17 00:00:00 2001 From: Benjamin Gaussorgues Date: Fri, 15 Nov 2024 09:40:56 +0100 Subject: [PATCH] fixup! feat(dav): introduce paginate with custom headers Signed-off-by: Benjamin Gaussorgues --- apps/dav/lib/Paginate/PaginateCache.php | 6 +++--- apps/dav/lib/Paginate/PaginatePlugin.php | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/dav/lib/Paginate/PaginateCache.php b/apps/dav/lib/Paginate/PaginateCache.php index 0e5abca287329..981502ec9daa2 100644 --- a/apps/dav/lib/Paginate/PaginateCache.php +++ b/apps/dav/lib/Paginate/PaginateCache.php @@ -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); @@ -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(); @@ -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)); } diff --git a/apps/dav/lib/Paginate/PaginatePlugin.php b/apps/dav/lib/Paginate/PaginatePlugin.php index 3531dff79b979..06d012584a816 100644 --- a/apps/dav/lib/Paginate/PaginatePlugin.php +++ b/apps/dav/lib/Paginate/PaginatePlugin.php @@ -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; @@ -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); } } @@ -86,6 +86,7 @@ public function onMethod(RequestInterface $request, ResponseInterface $response) $data = $this->server->generateMultiStatus($items, $minimal); $response->setBody($data); + return false; } }