forked from mirror/pixelfed
commit
668cae7c83
2 changed files with 18 additions and 5 deletions
|
@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Http;
|
|||
use App\Profile;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
|
||||
class ActivityPubFetchService
|
||||
{
|
||||
|
@ -19,9 +20,18 @@ class ActivityPubFetchService
|
|||
$headers['Accept'] = 'application/activity+json, application/json';
|
||||
$headers['User-Agent'] = '(Pixelfed/'.config('pixelfed.version').'; +'.config('app.url').')';
|
||||
|
||||
return Http::withHeaders($headers)
|
||||
->timeout(30)
|
||||
->get($url)
|
||||
->body();
|
||||
try {
|
||||
$res = Http::withHeaders($headers)
|
||||
->timeout(10)
|
||||
->get($url);
|
||||
} catch (ConnectionException $e) {
|
||||
return;
|
||||
} catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
if(!$res->ok()) {
|
||||
return;
|
||||
}
|
||||
return $res->body();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,10 +248,13 @@ class Helpers {
|
|||
|
||||
$hash = hash('sha256', $url);
|
||||
$key = "helpers:url:fetcher:sha256-{$hash}";
|
||||
$ttl = now()->addMinutes(5);
|
||||
$ttl = now()->addMinutes(15);
|
||||
|
||||
return Cache::remember($key, $ttl, function() use($url) {
|
||||
$res = ActivityPubFetchService::get($url);
|
||||
if(!$res || empty($res)) {
|
||||
return false;
|
||||
}
|
||||
$res = json_decode($res, true, 8);
|
||||
if(json_last_error() == JSON_ERROR_NONE) {
|
||||
return $res;
|
||||
|
|
Loading…
Reference in a new issue