*/ public function version(): array { return $this->json('version'); } /** * @return array */ public function check(?string $currentSha): array { return $this->json('check', $currentSha ? ['current_sha' => $currentSha] : []); } /** * @return array */ public function license(): array { return $this->json('license'); } public function changelog(): string { $response = $this->send(fn () => $this->http->request((int) config('updater.timeouts.json')) ->accept('text/markdown') ->get($this->url('changelog'), ['format' => 'raw'])); return $response->body(); } /** * ZIP in eine Datei streamen – nicht in den Speicher. * * @return array{sha: string|null, sha256: string|null} */ public function downloadZip(string $sha, string $target): array { $response = $this->send(fn () => $this->http->request((int) config('updater.timeouts.zip')) ->accept('application/zip') ->sink($target) ->get($this->url('zip'), ['ref' => $sha]), sinkedTo: $target); return [ 'sha' => $response->header('X-Commit-Sha') ?: null, 'sha256' => $response->header('X-Content-Sha256') ?: null, ]; } /** * @param array $query * @return array */ private function json(string $path, array $query = []): array { $response = $this->send(fn () => $this->http->request((int) config('updater.timeouts.json')) ->get($this->url($path), $query)); $data = $response->json(); if (! is_array($data)) { throw new ServerError('invalid_response', $response->status(), 'Antwort ist kein JSON.'); } return $data; } /** * @param callable(): Response $callback */ private function send(callable $callback, ?string $sinkedTo = null): Response { $response = VendorHttp::guard($callback); if (! $response->successful()) { // Bei Downloads steht die Fehlerantwort in der Zieldatei. $body = $sinkedTo && is_file($sinkedTo) ? (string) file_get_contents($sinkedTo) : null; throw VendorHttp::errorFrom($response, $body); } return $response; } private function url(string $path): string { return rtrim($this->baseUrl, '/').'/'.$path; } }