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']; }); } public static function getDiscover() { return Cache::remember(self::DISCOVER_CACHE_KEY, now()->addHours(6), function () { try { $res = Http::withOptions(['allow_redirects' => false]) ->withHeaders([ 'X-Pixelfed-Api' => 1, ])->timeout(5) ->connectTimeout(5) ->retry(2, 500) ->get('https://beagle.pixelfed.net/api/v1/discover'); } catch (RequestException $e) { return; } catch (ConnectionException $e) { return; } catch (Exception $e) { return; } if (! $res->ok()) { return; } $json = $res->json(); if (! isset($json['statuses']) || ! count($json['statuses'])) { return []; } return $json['statuses']; }); } public static function getDiscoverPosts() { $posts = collect(self::getDiscover()) ->filter(function ($post) { $bannedInstances = InstanceService::getBannedDomains(); $domain = parse_url($post['id'], PHP_URL_HOST); return ! in_array($domain, $bannedInstances); }) ->map(function ($post) { $domain = parse_url($post['id'], PHP_URL_HOST); if ($domain === config_cache('pixelfed.domain.app')) { $parts = explode('/', $post['id']); $id = array_last($parts); return StatusService::get($id); } return Helpers::statusFetch($post['id']); }) ->values() ->toArray(); return $posts; } }