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

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Hickmeister
2026-10-11 20:16:14 +01:00
co-authored by Claude Sonnet 5.5
parent b11538944f
commit 6b3f529a33
4 changed files with 11 additions and 21 deletions
+8 -18
View File
@@ -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);
+1 -1
View File
@@ -24,7 +24,7 @@ class BambuddyPageTest extends TestCase
['id' => 1, 'tray_color' => null, 'tray_type' => null, 'remain' => 0, 'exists' => false],
]]],
]),
'https://3d.example.test/api/v1/printers' => Http::response([['id' => 1, 'name' => 'Printy Boii 2', 'model' => 'X1C']]),
'https://3d.example.test/api/v1/printers/' => Http::response([['id' => 1, 'name' => 'Printy Boii 2', 'model' => 'X1C']]),
'https://3d.example.test/api/v1/queue/' => Http::response([
['id' => 5, 'status' => 'pending', 'position' => 1, 'archive_name' => 'Queued_Bracket', 'completed_at' => null],
['id' => 4, 'status' => 'completed', 'position' => 0, 'archive_name' => 'Old_Job', 'completed_at' => '2026-10-01T10:00:00'],
+1 -1
View File
@@ -34,7 +34,7 @@ class DashboardAccessTest extends TestCase
['receipt_id' => 77, 'name' => 'Buyer One', 'create_timestamp' => now()->timestamp],
]]),
'https://api.etsy.com/v3/application/shops/42/listings*' => Http::response(['count' => 12, 'results' => []]),
'https://3d.example.test/api/v1/printers' => Http::response([['id' => 1, 'name' => 'X1 Carbon']]),
'https://3d.example.test/api/v1/printers/' => Http::response([['id' => 1, 'name' => 'X1 Carbon']]),
'https://3d.example.test/api/v1/printers/1/status' => Http::response(['connected' => true, 'state' => 'RUNNING', 'progress' => 45]),
'https://auth.example.test/token' => Http::response(['access_token' => 'shipping-token']),
'https://shipping.example.test/api/me/orders/detail' => Http::response(['Orders' => [
+1 -1
View File
@@ -55,7 +55,7 @@ class IntegrationsTest extends TestCase
{
Http::preventStrayRequests();
Http::fake([
'https://3d.example.test/api/v1/printers' => Http::response([['id' => 1, 'name' => 'X1 Carbon', 'status' => 'printing']]),
'https://3d.example.test/api/v1/printers/' => Http::response([['id' => 1, 'name' => 'X1 Carbon', 'status' => 'printing']]),
'https://3d.example.test/api/v1/printers/1/status' => Http::response(['connected' => true, 'state' => 'RUNNING', 'progress' => 45, 'temperatures' => ['nozzle' => 220, 'bed' => 60]]),
]);
config()->set('services.bambuddy', ['url' => 'https://3d.example.test', 'api_key' => 'read-key']);