From a3640a061d3fc529d3c1727e389a28ec05695cac Mon Sep 17 00:00:00 2001 From: Pavel Stratil Date: Wed, 17 Jan 2024 14:41:15 +0000 Subject: [PATCH] fix 404 --- glued/Controllers/ServiceController.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/glued/Controllers/ServiceController.php b/glued/Controllers/ServiceController.php index b66eb94..edf0422 100644 --- a/glued/Controllers/ServiceController.php +++ b/glued/Controllers/ServiceController.php @@ -11,6 +11,8 @@ use Nyholm\Psr7\Factory\Psr17Factory; use Ramsey\Uuid\Uuid; + + class ServiceController extends AbstractController { @@ -675,6 +677,13 @@ public function objects_c1(Request $request, Response $response, array $args = [ } public function objects_r1(Request $request, Response $response, array $args = []): Response { + $data = [ + 'timestamp' => microtime(), + 'status' => 'Objects R1 OK', + 'service' => basename(__ROOT__), + 'data' => [] + ]; + if (!array_key_exists('bucket', $args)) { throw new Exception('Bucket not found.', 400); } $wm = ''; $link = false; @@ -713,7 +722,10 @@ public function objects_r1(Request $request, Response $response, array $args = [ $handle = $this->mysqli->execute_query($q, $pa); $r = $handle->fetch_all(MYSQLI_ASSOC); - if ($handle->num_rows == 0) { throw new \Exception('Not found.', 404); } + if ($handle->num_rows == 0) { + if ($this->get_buckets($args['bucket']) == []) { throw new \Exception('Bucket not found.', 404); } + return $response->withJson($data); + } foreach ($r as &$rr) { if (isset($rr['refs'])) { $rr['refs'] = json_decode($rr['refs']); } if (isset($rr['backrefs'])) { $rr['backrefs'] = json_decode($rr['backrefs']); } @@ -721,12 +733,7 @@ public function objects_r1(Request $request, Response $response, array $args = [ } if ($wm !== '') { $r = $r[0]; } if ($link) { $r['link'] = $link; } - $data = [ - 'timestamp' => microtime(), - 'status' => 'Objects R1 OK', - 'service' => basename(__ROOT__), - 'data' => $r - ]; + $data['data'] = $r; return $response->withJson($data); } @@ -883,8 +890,7 @@ public function links_r1(Request $request, Response $response, array $args = []) ->withHeader('Content-Length', filesize($file)); $fileStream = fopen($file, 'rb'); $stream = (new Psr17Factory())->createStreamFromResource($fileStream); - $response = $response->withBody($stream); - return $response; + return $response->withBody($stream); } else { $data['status'] = 'Not found'; return $response->withJson($data)->withStatus(404); } } @@ -919,7 +925,6 @@ function status() { return $res; } - /** * Returns a health status response. * @param Request $request