From f17ca9d904e2b194c50c3a5ed4682a0f35622300 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 19 Apr 2023 18:57:40 -0600 Subject: [PATCH] Update HttpSignature --- app/Http/Controllers/AccountController.php | 12 ++++++++++-- app/Services/ActivityPubFetchService.php | 10 +++++++--- app/Util/ActivityPub/HttpSignature.php | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 3ed1cd40a..a0e53a799 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -282,14 +282,22 @@ class AccountController extends Controller $filterable['id'] = $profile->id; $filterable['type'] = $class; - Follower::whereProfileId($profile->id)->whereFollowingId($pid)->delete(); + $followed = Follower::whereProfileId($profile->id)->whereFollowingId($pid)->first(); + if($followed) { + $followed->delete(); + $selfProfile = $request->user()->profile; + $selfProfile->followers_count = Follower::whereFollowingId($pid)->count(); + $selfProfile->save(); + AccountService::del($selfProfile->id); + } + Notification::whereProfileId($pid) ->whereActorId($profile->id) ->get() ->map(function($n) use($pid) { NotificationService::del($pid, $n['id']); $n->forceDelete(); - }); + }); break; } diff --git a/app/Services/ActivityPubFetchService.php b/app/Services/ActivityPubFetchService.php index 5c0d48c7f..518e958f1 100644 --- a/app/Services/ActivityPubFetchService.php +++ b/app/Services/ActivityPubFetchService.php @@ -7,6 +7,7 @@ use App\Profile; use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\HttpSignature; use Illuminate\Http\Client\ConnectionException; +use Illuminate\Http\Client\RequestException; class ActivityPubFetchService { @@ -17,13 +18,16 @@ class ActivityPubFetchService } $headers = HttpSignature::instanceActorSign($url, false); - $headers['Accept'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'; - $headers['User-Agent'] = '(Pixelfed/'.config('pixelfed.version').'; +'.config('app.url').')'; + $headers['Accept'] = 'application/activity+json'; try { $res = Http::withHeaders($headers) - ->timeout(10) + ->timeout(30) + ->connectTimeout(5) + ->retry(3, 500) ->get($url); + } catch (RequestException $e) { + return; } catch (ConnectionException $e) { return; } catch (Exception $e) { diff --git a/app/Util/ActivityPub/HttpSignature.php b/app/Util/ActivityPub/HttpSignature.php index 8c8dad99f..835c855c1 100644 --- a/app/Util/ActivityPub/HttpSignature.php +++ b/app/Util/ActivityPub/HttpSignature.php @@ -130,8 +130,8 @@ class HttpSignature { $headers = [ '(request-target)' => 'post '.parse_url($url, PHP_URL_PATH), - 'Date' => $date->format('D, d M Y H:i:s \G\M\T'), 'Host' => parse_url($url, PHP_URL_HOST), + 'Date' => $date->format('D, d M Y H:i:s \G\M\T'), ]; if($digest) {