瀏覽代碼

Update HttpSignature

Daniel Supernault 2 年之前
父節點
當前提交
f17ca9d904

+ 10 - 2
app/Http/Controllers/AccountController.php

@@ -282,14 +282,22 @@ class AccountController extends Controller
 			$filterable['id'] = $profile->id;
 			$filterable['id'] = $profile->id;
 			$filterable['type'] = $class;
 			$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)
 			Notification::whereProfileId($pid)
 				->whereActorId($profile->id)
 				->whereActorId($profile->id)
 				->get()
 				->get()
 				->map(function($n) use($pid) {
 				->map(function($n) use($pid) {
 					NotificationService::del($pid, $n['id']);
 					NotificationService::del($pid, $n['id']);
 					$n->forceDelete();
 					$n->forceDelete();
-				});
+			});
 			break;
 			break;
 		}
 		}
 
 

+ 7 - 3
app/Services/ActivityPubFetchService.php

@@ -7,6 +7,7 @@ use App\Profile;
 use App\Util\ActivityPub\Helpers;
 use App\Util\ActivityPub\Helpers;
 use App\Util\ActivityPub\HttpSignature;
 use App\Util\ActivityPub\HttpSignature;
 use Illuminate\Http\Client\ConnectionException;
 use Illuminate\Http\Client\ConnectionException;
+use Illuminate\Http\Client\RequestException;
 
 
 class ActivityPubFetchService
 class ActivityPubFetchService
 {
 {
@@ -17,13 +18,16 @@ class ActivityPubFetchService
 		}
 		}
 
 
 		$headers = HttpSignature::instanceActorSign($url, false);
 		$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 {
 		try {
 			$res = Http::withHeaders($headers)
 			$res = Http::withHeaders($headers)
-				->timeout(10)
+				->timeout(30)
+				->connectTimeout(5)
+				->retry(3, 500)
 				->get($url);
 				->get($url);
+		} catch (RequestException $e) {
+			return;
 		} catch (ConnectionException $e) {
 		} catch (ConnectionException $e) {
 			return;
 			return;
 		} catch (Exception $e) {
 		} catch (Exception $e) {

+ 1 - 1
app/Util/ActivityPub/HttpSignature.php

@@ -130,8 +130,8 @@ class HttpSignature {
 
 
     $headers = [
     $headers = [
       '(request-target)' => 'post '.parse_url($url, PHP_URL_PATH),
       '(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),
       'Host' => parse_url($url, PHP_URL_HOST),
+      'Date' => $date->format('D, d M Y H:i:s \G\M\T'),
     ];
     ];
 
 
     if($digest) {
     if($digest) {