Add BamBuddy AMS, queue, history and stats to the print farm page
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Hickmeister
2026-10-11 20:14:29 +01:00
co-authored by Claude Sonnet 5.5
parent f7e3c8fe16
commit b11538944f
6 changed files with 135 additions and 3 deletions
+33
View File
@@ -29,6 +29,39 @@ class Bambuddy
return $this->cache->remember('bambuddy.printers.'.md5($this->url()), 45, fn (): array => $this->fetchPrinters());
}
/** @return array<int, array<string, mixed>> Jobs still waiting or running in the BamBuddy queue. */
public function queue(): array
{
return $this->cache->remember('bambuddy.queue.'.md5($this->url()), 45, fn (): array => collect($this->get('queue/'))
->filter(fn ($item): bool => is_array($item) && empty($item['completed_at']) && in_array($item['status'] ?? 'pending', ['pending', 'printing', 'queued', 'waiting'], true))
->sortBy('position')->values()->all());
}
/** @return array<int, array<string, mixed>> */
public function recentPrints(int $limit = 10): array
{
return $this->cache->remember('bambuddy.archives.'.md5($this->url()).'.'.$limit, 120, fn (): array => collect($this->get('archives/', ['limit' => $limit]))
->filter(fn ($archive): bool => is_array($archive))->values()->all());
}
/** @return array<string, mixed> */
public function stats(): array
{
return $this->cache->remember('bambuddy.stats.'.md5($this->url()), 300, fn (): array => $this->get('archives/stats'));
}
/** @param array<string, mixed> $query */
private function get(string $path, array $query = []): array
{
if (! $this->configured()) {
throw new RuntimeException('BamBuddy API key is not configured.');
}
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() ?? [];
}
private function fetchPrinters(): array
{
$url = rtrim($this->url(), '/').'/api/v1/printers';