From c665a3b15c2d260cafa20ec97c51400c05ab794d Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Fri, 23 Dec 2022 11:13:25 +0100 Subject: [PATCH] baculum: Add offset parameter to messages endpoint --- .../protected/API/Pages/API/Messages.php | 7 ++++- .../protected/API/openapi_baculum.json | 30 +++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/gui/baculum/protected/API/Pages/API/Messages.php b/gui/baculum/protected/API/Pages/API/Messages.php index 704fd15eb..176245f5b 100644 --- a/gui/baculum/protected/API/Pages/API/Messages.php +++ b/gui/baculum/protected/API/Pages/API/Messages.php @@ -35,12 +35,17 @@ class Messages extends BaculumAPIServer { public function get() { $misc = $this->getModule('misc'); $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; + $offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0; $cmd = ['messages']; $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, null, true); $output = $result->output; if ($result->exitcode == 0) { - $output = $limit > 0 ? array_slice($output, -$limit) : $output; + if ($limit > 0 && $offset <= 0) { + $output = array_slice($output, -$limit); + } elseif ($limit > 0 && $offset > 0) { + $output = array_slice($output, -$offset, $limit); + } } $this->output = $output; $this->error = $result->exitcode > 0 ? GenericError::ERROR_WRONG_EXITCODE : GenericError::ERROR_NO_ERRORS; diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 23869f955..275a9eca1 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -5558,16 +5558,28 @@ } } }, - "parameters": [{ - "name": "limit", - "in": "query", - "description": "Set messages log Limit.", - "required": false, - "default": 0, - "schema": { - "type": "integer" + "parameters": [ + { + "name": "limit", + "in": "query", + "description": "Set messages log Limit. It is applyed from the end, not from the beginning. Ex. for msg1, msg2, msg3, msg4 and limit=2 it displays msg3 and msg4.", + "required": false, + "default": 0, + "schema": { + "type": "integer" + } + }, + { + "name": "offset", + "in": "query", + "description": "Messages' offset must be used together with limit. It is applyed from the end, not from the beginning. Ex. for msg1, msg2, msg3, msg4 and offset=3 limit=2 it displays msg2 and msg3.", + "required": false, + "default": 0, + "schema": { + "type": "integer" + } } - }] + ] } }, "/api/v2/directors/{director_name}/status": { -- 2.47.3