Skip to content

Commit

Permalink
fix 404
Browse files Browse the repository at this point in the history
  • Loading branch information
killua-eu committed Jan 17, 2024
1 parent 43301ed commit a3640a0
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions glued/Controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Nyholm\Psr7\Factory\Psr17Factory;
use Ramsey\Uuid\Uuid;



class ServiceController extends AbstractController
{

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -713,20 +722,18 @@ 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']); }
if (isset($rr['meta'])) { $rr['meta'] = json_decode($rr['meta']); }
}
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);
}

Expand Down Expand Up @@ -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); }
}

Expand Down Expand Up @@ -919,7 +925,6 @@ function status() {
return $res;
}


/**
* Returns a health status response.
* @param Request $request
Expand Down

0 comments on commit a3640a0

Please sign in to comment.