2020-04-27 05:43:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
2021-09-20 06:21:16 +00:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2020-04-27 05:43:54 +00:00
|
|
|
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;
|
2023-04-20 00:57:40 +00:00
|
|
|
use Illuminate\Http\Client\RequestException;
|
2020-04-27 05:43:54 +00:00
|
|
|
|
|
|
|
class ActivityPubFetchService
|
|
|
|
{
|
2023-08-01 09:16:08 +00:00
|
|
|
public static function get($url, $validateUrl = true)
|
2020-04-27 05:43:54 +00:00
|
|
|
{
|
2023-08-01 09:16:08 +00:00
|
|
|
if($validateUrl === true) {
|
|
|
|
if(!Helpers::validateUrl($url)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2021-01-26 04:44:07 +00:00
|
|
|
|
2023-04-20 01:04:41 +00:00
|
|
|
$baseHeaders = [
|
2023-04-20 01:09:55 +00:00
|
|
|
'Accept' => 'application/activity+json, application/ld+json',
|
2023-04-20 01:04:41 +00:00
|
|
|
];
|
|
|
|
|
2023-06-26 05:02:02 +00:00
|
|
|
$headers = HttpSignature::instanceActorSign($url, false, $baseHeaders, 'get');
|
2023-04-20 01:09:55 +00:00
|
|
|
$headers['Accept'] = 'application/activity+json, application/ld+json';
|
2023-06-26 05:02:02 +00:00
|
|
|
$headers['User-Agent'] = 'PixelFedBot/1.0.0 (Pixelfed/'.config('pixelfed.version').'; +'.config('app.url').')';
|
2021-01-17 19:51:07 +00:00
|
|
|
|
2022-12-05 07:46:55 +00:00
|
|
|
try {
|
|
|
|
$res = Http::withHeaders($headers)
|
2023-04-20 00:57:40 +00:00
|
|
|
->timeout(30)
|
|
|
|
->connectTimeout(5)
|
|
|
|
->retry(3, 500)
|
2022-12-05 07:46:55 +00:00
|
|
|
->get($url);
|
2023-04-20 00:57:40 +00:00
|
|
|
} catch (RequestException $e) {
|
|
|
|
return;
|
2022-12-05 07:46:55 +00:00
|
|
|
} catch (ConnectionException $e) {
|
|
|
|
return;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!$res->ok()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $res->body();
|
2020-04-27 05:43:54 +00:00
|
|
|
}
|
2021-09-20 06:21:16 +00:00
|
|
|
}
|