Update AP Helpers

This commit is contained in:
Daniel Supernault 2020-02-01 11:42:24 -07:00
parent 764ab76e90
commit 823bcbc69a
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -23,6 +23,7 @@ use App\Jobs\ImageOptimizePipeline\{ImageOptimize,ImageThumbnail};
use App\Jobs\StatusPipeline\NewStatusPipeline; use App\Jobs\StatusPipeline\NewStatusPipeline;
use App\Util\ActivityPub\HttpSignature; use App\Util\ActivityPub\HttpSignature;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Services\ActivityPubDeliveryService;
class Helpers { class Helpers {
@ -435,35 +436,22 @@ class Helpers {
return self::profileFirstOrNew($url); return self::profileFirstOrNew($url);
} }
public static function sendSignedObject($senderProfile, $url, $body) public static function sendSignedObject($profile, $url, $body)
{ {
abort_if(!self::validateUrl($url), 400); ActivityPubDeliveryService::queue()
->from($profile)
$payload = json_encode($body); ->to($url)
$headers = HttpSignature::sign($senderProfile, $url, $body); ->payload($body)
->send();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
return;
} }
public static function apSignedPostRequest($senderProfile, $url, $body) public static function apSignedPostRequest($profile, $url, $body)
{ {
abort_if(!self::validateUrl($url), 400); ActivityPubDeliveryService::queue()
->from($profile)
->to($url)
->payload($body)
->send();
$payload = json_encode($body);
$headers = HttpSignature::sign($senderProfile, $url, $body);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
return;
} }
} }