From a9e54aa5401a572fdd2cf74eb2e00beaf58d81b7 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 5 Apr 2024 22:02:51 -0600 Subject: [PATCH] Add BeagleService --- app/Services/Internal/BeagleService.php | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/Services/Internal/BeagleService.php diff --git a/app/Services/Internal/BeagleService.php b/app/Services/Internal/BeagleService.php new file mode 100644 index 000000000..60a4f78e4 --- /dev/null +++ b/app/Services/Internal/BeagleService.php @@ -0,0 +1,44 @@ +addDays(7), function() { + try { + $res = Http::withOptions(['allow_redirects' => false]) + ->timeout(5) + ->connectTimeout(5) + ->retry(2, 500) + ->get('https://beagle.pixelfed.net/api/v1/common/suggestions/rules'); + } catch (RequestException $e) { + return; + } catch (ConnectionException $e) { + return; + } catch (Exception $e) { + return; + } + + if(!$res->ok()) { + return; + } + + $json = $res->json(); + + if(!isset($json['rule_suggestions']) || !count($json['rule_suggestions'])) { + return []; + } + return $json['rule_suggestions']; + }); + } + +}