]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add offset parameter to messages endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Fri, 23 Dec 2022 10:13:25 +0000 (11:13 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Mon, 9 Jan 2023 12:34:42 +0000 (13:34 +0100)
gui/baculum/protected/API/Pages/API/Messages.php
gui/baculum/protected/API/openapi_baculum.json

index 704fd15ebfaab170d3dde37d15b9afc153ca9f02..176245f5b91f4d5d3b84d0863609d7f5dbbad2a4 100644 (file)
@@ -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;
index 23869f955aa95e231c636b5e79bec04e006e9c44..275a9eca1655d6533775b40f00c1f1a50dbfbc18 100644 (file)
                                                }
                                        }
                                },
-                               "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": {