pixelfed/app/Services/ActivityPubFetchService.php

38 lines
793 B
PHP
Raw Normal View History

<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
use App\Profile;
use App\Util\ActivityPub\Helpers;
use App\Util\ActivityPub\HttpSignature;
2022-12-05 07:46:55 +00:00
use Illuminate\Http\Client\ConnectionException;
class ActivityPubFetchService
{
public static function get($url)
{
if(!Helpers::validateUrl($url)) {
return 0;
}
$headers = HttpSignature::instanceActorSign($url, false);
$headers['Accept'] = 'application/activity+json, application/json';
$headers['User-Agent'] = '(Pixelfed/'.config('pixelfed.version').'; +'.config('app.url').')';
2022-12-05 07:46:55 +00:00
try {
$res = Http::withHeaders($headers)
->timeout(10)
->get($url);
} catch (ConnectionException $e) {
return;
} catch (Exception $e) {
return;
}
if(!$res->ok()) {
return;
}
return $res->body();
}
}