diff --git a/app/Services/ActivityPubDeliveryService.php b/app/Services/ActivityPubDeliveryService.php new file mode 100644 index 000000000..1e1b5851d --- /dev/null +++ b/app/Services/ActivityPubDeliveryService.php @@ -0,0 +1,61 @@ +sender = $profile; + return $this; + } + + public function to(string $url) + { + $this->to = $url; + return $this; + } + + public function payload($payload) + { + $this->payload = $payload; + return $this; + } + + public function send() + { + return $this->queueDelivery(); + } + + protected function queueDelivery() + { + abort_if(!$this->sender || !$this->to || !$this->payload, 400); + abort_if(!Helpers::validateUrl($this->to), 400); + abort_if($this->sender->domain != null || $this->sender->status != null, 400); + + $body = $this->payload; + $payload = json_encode($body); + $headers = HttpSignature::sign($this->sender, $this->to, $body); + + $ch = curl_init($this->to); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); + curl_setopt($ch, CURLOPT_HEADER, true); + curl_exec($ch); + } + +} \ No newline at end of file