Use BamBuddy's trailing-slash printers endpoint and tolerate /api/v1 in the saved URL
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 12s
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 12s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
b11538944f
commit
6b3f529a33
@@ -51,34 +51,24 @@ class Bambuddy
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $query */
|
||||
private function get(string $path, array $query = []): array
|
||||
private function get(string $path, array $query = [], int $timeout = 8): array
|
||||
{
|
||||
if (! $this->configured()) {
|
||||
throw new RuntimeException('BamBuddy API key is not configured.');
|
||||
}
|
||||
$base = preg_replace('#/api(/v1)?$#', '', rtrim(trim($this->url()), '/'));
|
||||
|
||||
return Http::withHeaders(['X-API-Key' => $this->settings->for('bambuddy')['api_key']])
|
||||
->acceptJson()->connectTimeout(3)->timeout(8)
|
||||
->get(rtrim($this->url(), '/').'/api/v1/'.ltrim($path, '/'), $query)->throw()->json() ?? [];
|
||||
return Http::withHeaders(['X-API-Key' => trim((string) $this->settings->for('bambuddy')['api_key'])])
|
||||
->acceptJson()->connectTimeout(3)->timeout($timeout)
|
||||
->get($base.'/api/v1/'.ltrim($path, '/'), $query)->throw()->json() ?? [];
|
||||
}
|
||||
|
||||
private function fetchPrinters(): array
|
||||
{
|
||||
$url = rtrim($this->url(), '/').'/api/v1/printers';
|
||||
$apiKey = $this->settings->for('bambuddy')['api_key'];
|
||||
|
||||
$printers = Http::withHeaders(['X-API-Key' => $apiKey])
|
||||
->acceptJson()->connectTimeout(3)->timeout(8)->get($url)->throw()->json() ?? [];
|
||||
|
||||
return collect($printers)->filter(fn ($printer) => is_array($printer) && isset($printer['id']))
|
||||
->take(20)->map(function (array $printer) use ($apiKey): array {
|
||||
return collect($this->get('printers/'))->filter(fn ($printer) => is_array($printer) && isset($printer['id']))
|
||||
->take(20)->map(function (array $printer): array {
|
||||
try {
|
||||
$status = Http::withHeaders(['X-API-Key' => $apiKey])
|
||||
->acceptJson()->connectTimeout(3)->timeout(5)
|
||||
->get(rtrim($this->url(), '/').'/api/v1/printers/'.(int) $printer['id'].'/status')
|
||||
->throw()->json() ?? [];
|
||||
|
||||
return $printer + ['live' => $status];
|
||||
return $printer + ['live' => $this->get('printers/'.(int) $printer['id'].'/status', timeout: 5)];
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user