浏览代码

Add ActivityPub Actor Transformer

Daniel Supernault 7 年之前
父节点
当前提交
0f55fbacc4
共有 1 个文件被更改,包括 41 次插入0 次删除
  1. 41 0
      app/Transformer/ActivityPub/ProfileTransformer.php

+ 41 - 0
app/Transformer/ActivityPub/ProfileTransformer.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Transformer\ActivityPub;
+
+use App\Profile;
+use League\Fractal;
+
+class ProfileTransformer extends Fractal\TransformerAbstract
+{
+
+  public function transform(Profile $profile)
+  {
+      return [
+          '@context' => 'https://www.w3.org/ns/activitystreams',
+          'id' => $profile->permalink(),
+          'type' => 'Person',
+          'following' => $profile->permalink('/following'),
+          'followers' => $profile->permalink('/followers'),
+          'inbox' => $profile->permalink('/inbox'),
+          'outbox' => $profile->permalink('/outbox'),
+          'featured' => $profile->permalink('/collections/featured'),
+          'preferredUsername' => $profile->username,
+          'name'  => $profile->name,
+          'summary' => $profile->bio,
+          'url' => $profile->url(),
+          'manuallyApprovesFollowers' => $profile->is_private,
+          'follower_count' => $profile->followers()->count(),
+          'following_count' => $profile->following()->count(),
+          'publicKey' => [
+            'id' => $profile->permalink() . '#main-key',
+            'owner' => $profile->permalink(),
+            'publicKeyPem' => $profile->public_key
+          ],
+          'endpoints' => [
+            'sharedInbox' => config('routes.api.sharedInbox')
+          ],
+              
+      ];
+  }
+
+}