Daniel Supernault 10 mesi fa
parent
commit
1210bf7502
1 ha cambiato i file con 22 aggiunte e 22 eliminazioni
  1. 22 22
      app/Services/NodeinfoService.php

+ 22 - 22
app/Services/NodeinfoService.php

@@ -2,32 +2,31 @@
 
 namespace App\Services;
 
-use Illuminate\Support\Str;
-use Illuminate\Support\Facades\Http;
-use Illuminate\Http\Client\RequestException;
 use Illuminate\Http\Client\ConnectionException;
+use Illuminate\Http\Client\RequestException;
+use Illuminate\Support\Facades\Http;
 
 class NodeinfoService
 {
     public static function get($domain)
     {
-    	$version = config('pixelfed.version');
-		$appUrl = config('app.url');
-		$headers = [
-			'Accept'     => 'application/json',
-			'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
-		];
+        $version = config('pixelfed.version');
+        $appUrl = config('app.url');
+        $headers = [
+            'Accept' => 'application/json',
+            'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
+        ];
 
-        $url = 'https://' . $domain;
-        $wk = $url . '/.well-known/nodeinfo';
+        $url = 'https://'.$domain;
+        $wk = $url.'/.well-known/nodeinfo';
 
         try {
             $res = Http::withOptions([
                 'allow_redirects' => false,
             ])
-            ->withHeaders($headers)
-            ->timeout(5)
-            ->get($wk);
+                ->withHeaders($headers)
+                ->timeout(5)
+                ->get($wk);
         } catch (RequestException $e) {
             return false;
         } catch (ConnectionException $e) {
@@ -36,18 +35,18 @@ class NodeinfoService
             return false;
         }
 
-        if(!$res) {
+        if (! $res) {
             return false;
         }
 
         $json = $res->json();
 
-        if( !isset($json['links'])) {
+        if (! isset($json['links'])) {
             return false;
         }
 
-        if(is_array($json['links'])) {
-            if(isset($json['links']['href'])) {
+        if (is_array($json['links'])) {
+            if (isset($json['links']['href'])) {
                 $href = $json['links']['href'];
             } else {
                 $href = $json['links'][0]['href'];
@@ -59,7 +58,7 @@ class NodeinfoService
         $domain = parse_url($url, PHP_URL_HOST);
         $hrefDomain = parse_url($href, PHP_URL_HOST);
 
-        if($domain !== $hrefDomain) {
+        if ($domain !== $hrefDomain) {
             return false;
         }
 
@@ -67,9 +66,9 @@ class NodeinfoService
             $res = Http::withOptions([
                 'allow_redirects' => false,
             ])
-            ->withHeaders($headers)
-            ->timeout(5)
-            ->get($href);
+                ->withHeaders($headers)
+                ->timeout(5)
+                ->get($href);
         } catch (RequestException $e) {
             return false;
         } catch (ConnectionException $e) {
@@ -77,6 +76,7 @@ class NodeinfoService
         } catch (\Exception $e) {
             return false;
         }
+
         return $res->json();
     }
 }