From 26b5b42b866ed7fb584d47fb0c7047c18f15aa66 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 28 Dec 2022 19:42:42 -0700 Subject: [PATCH] Update WebfingerService --- app/Services/WebfingerService.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/Services/WebfingerService.php b/app/Services/WebfingerService.php index 78a0008b..385bff02 100644 --- a/app/Services/WebfingerService.php +++ b/app/Services/WebfingerService.php @@ -28,13 +28,17 @@ class WebfingerService return []; } - $res = Http::retry(3, 100) - ->acceptJson() - ->withHeaders([ - 'User-Agent' => '(Pixelfed/' . config('pixelfed.version') . '; +' . config('app.url') . ')' - ]) - ->timeout(20) - ->get($url); + try { + $res = Http::retry(3, 100) + ->acceptJson() + ->withHeaders([ + 'User-Agent' => '(Pixelfed/' . config('pixelfed.version') . '; +' . config('app.url') . ')' + ]) + ->timeout(20) + ->get($url); + } catch (\Illuminate\Http\Client\ConnectionException $e) { + return []; + } if(!$res->successful()) { return []; @@ -48,11 +52,9 @@ class WebfingerService $link = collect($webfinger['links']) ->filter(function($link) { return $link && - isset($link['rel']) && - isset($link['type']) && - isset($link['href']) && - $link['rel'] == 'self' && - $link['type'] == 'application/activity+json' || $link['type'] == 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'; + isset($link['rel'], $link['type'], $link['href']) && + $link['rel'] === 'self' && + in_array($link['type'], ['application/activity+json','application/ld+json; profile="https://www.w3.org/ns/activitystreams"']); }) ->pluck('href') ->first();